changeset 6491:e61ef9ba27a8

refactored lowering of DirectCompareAndSwap node into HotSpotLIRGenerator
author Doug Simon <doug.simon@oracle.com>
date Tue, 02 Oct 2012 18:25:17 +0200
parents 9892bfd8a48f
children dc409418cc2c
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DirectCompareAndSwapNode.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/HotSpotLIRGenerator.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/HotSpotAMD64Backend.java
diffstat 3 files changed, 46 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DirectCompareAndSwapNode.java	Tue Oct 02 17:31:03 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DirectCompareAndSwapNode.java	Tue Oct 02 18:25:17 2012 +0200
@@ -22,18 +22,13 @@
  */
 package com.oracle.graal.hotspot.nodes;
 
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.compiler.target.*;
-import com.oracle.graal.lir.*;
-import com.oracle.graal.lir.amd64.AMD64Move.CompareAndSwapOp;
+import com.oracle.graal.hotspot.target.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.java.*;
 import com.oracle.graal.snippets.*;
-import com.oracle.max.asm.*;
-import com.oracle.max.asm.target.amd64.*;
 
 /**
  * A special purpose store node that differs from {@link CompareAndSwapNode} in that
@@ -58,29 +53,23 @@
 
     @Override
     public void generate(LIRGenerator gen) {
-        Kind kind = newValue.kind();
-        assert kind == expectedValue.kind();
+        ((HotSpotLIRGenerator) gen).visitDirectCompareAndSwap(this);
+    }
 
-        Value expected = gen.loadNonConst(gen.operand(expectedValue));
-        Variable newVal = gen.load(gen.operand(newValue));
+    public ValueNode object() {
+        return object;
+    }
 
-        int disp = 0;
-        Address address;
-        Value index = gen.operand(this.offset);
-        if (ValueUtil.isConstant(index) && NumUtil.isInt(ValueUtil.asConstant(index).asLong() + disp)) {
-            disp += (int) ValueUtil.asConstant(index).asLong();
-            address = new Address(kind, gen.load(gen.operand(this.object)), disp);
-        } else {
-            address = new Address(kind, gen.load(gen.operand(this.object)), gen.load(index), Address.Scale.Times1, disp);
-        }
+    public ValueNode offset() {
+        return offset;
+    }
 
-        RegisterValue rax = AMD64.rax.asValue(kind);
-        gen.emitMove(expected, rax);
-        gen.append(new CompareAndSwapOp(rax, address, rax, newVal));
+    public ValueNode expectedValue() {
+        return expectedValue;
+    }
 
-        Variable result = gen.newVariable(kind());
-        gen.emitMove(rax, result);
-        gen.setResult(this, result);
+    public ValueNode newValue() {
+        return newValue;
     }
 
     /**
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/HotSpotLIRGenerator.java	Tue Oct 02 17:31:03 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/HotSpotLIRGenerator.java	Tue Oct 02 18:25:17 2012 +0200
@@ -24,6 +24,7 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.gen.*;
+import com.oracle.graal.hotspot.nodes.*;
 import com.oracle.graal.nodes.spi.*;
 
 /**
@@ -39,4 +40,6 @@
      * @param address the target address of the call
      */
     void emitTailcall(Value[] args, Value address);
+
+    void visitDirectCompareAndSwap(DirectCompareAndSwapNode x);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/HotSpotAMD64Backend.java	Tue Oct 02 17:31:03 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/HotSpotAMD64Backend.java	Tue Oct 02 18:25:17 2012 +0200
@@ -44,6 +44,7 @@
 import com.oracle.graal.hotspot.target.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.amd64.*;
+import com.oracle.graal.lir.amd64.AMD64Move.*;
 import com.oracle.graal.lir.asm.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.java.*;
@@ -158,6 +159,34 @@
             setResult(x, exception);
         }
 
+        @SuppressWarnings("hiding")
+        @Override
+        public void visitDirectCompareAndSwap(DirectCompareAndSwapNode x) {
+            Kind kind = x.newValue().kind();
+            assert kind == x.expectedValue().kind();
+
+            Value expected = loadNonConst(operand(x.expectedValue()));
+            Variable newVal = load(operand(x.newValue()));
+
+            int disp = 0;
+            Address address;
+            Value index = operand(x.offset());
+            if (ValueUtil.isConstant(index) && NumUtil.isInt(ValueUtil.asConstant(index).asLong() + disp)) {
+                disp += (int) ValueUtil.asConstant(index).asLong();
+                address = new Address(kind, load(operand(x.object())), disp);
+            } else {
+                address = new Address(kind, load(operand(x.object())), load(index), Address.Scale.Times1, disp);
+            }
+
+            RegisterValue rax = AMD64.rax.asValue(kind);
+            emitMove(expected, rax);
+            append(new CompareAndSwapOp(rax, address, rax, newVal));
+
+            Variable result = newVariable(x.kind());
+            emitMove(rax, result);
+            setResult(x, result);
+        }
+
         @Override
         public void emitTailcall(Value[] args, Value address) {
             append(new AMD64TailcallOp(args, address));