changeset 22650:61026507bfa6

Use correct LIRKind for constants in phis.
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 17 Sep 2015 14:29:34 +0200
parents 467f38f99aea
children 00ee7def5b54
files graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java
diffstat 5 files changed, 31 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Thu Sep 17 11:08:55 2015 +0200
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Thu Sep 17 14:29:34 2015 +0200
@@ -345,7 +345,7 @@
     @Override
     public Variable emitLoad(LIRKind kind, Value address, LIRFrameState state) {
         AMD64AddressValue loadAddress = asAddressValue(address);
-        Variable result = newVariable(toStackKind(kind));
+        Variable result = newVariable(toRegisterKind(kind));
         switch ((JavaKind) kind.getPlatformKind()) {
             case Boolean:
                 append(new AMD64Unary.MemoryOp(MOVZXB, DWORD, result, loadAddress, state));
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java	Thu Sep 17 11:08:55 2015 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java	Thu Sep 17 14:29:34 2015 +0200
@@ -280,17 +280,14 @@
         ArrayList<LIRKind> values = new ArrayList<>(phi.valueCount());
         for (int i = 0; i < phi.valueCount(); i++) {
             ValueNode node = phi.valueAt(i);
-            if (node instanceof ConstantNode) {
-                values.add(gen.getLIRKind(node.stamp()));
+            Value value = getOperand(node);
+            if (value != null) {
+                values.add(value.getLIRKind());
             } else {
-                Value value = getOperand(node);
-                if (value != null) {
-                    values.add(value.getLIRKind());
-                } else {
-                    assert isPhiInputFromBackedge(phi, i) : String.format("Input %s to phi node %s is not yet available although it is not coming from a loop back edge", node, phi);
-                    // non-java constant -> get Kind from stamp.
-                    values.add(getLIRGeneratorTool().getLIRKind(node.stamp()));
-                }
+                assert isPhiInputFromBackedge(phi, i) : String.format("Input %s to phi node %s is not yet available although it is not coming from a loop back edge", node, phi);
+                // non-java constant -> get LIRKind from stamp.
+                LIRKind kind = gen.getLIRKind(node.stamp());
+                values.add(gen.toRegisterKind(kind));
             }
         }
         LIRKind derivedKind = LIRKind.merge(values);
@@ -298,10 +295,10 @@
         return derivedKind;
     }
 
-    private static boolean verifyPHIKind(LIRKind derivedKind, LIRKind phiKind) {
-        assert derivedKind.getPlatformKind() != JavaKind.Object || !derivedKind.isUnknownReference();
-        PlatformKind phiPlatformKind = phiKind.getPlatformKind();
-        assert derivedKind.equals(phiKind) || derivedKind.getPlatformKind().equals(phiPlatformKind instanceof JavaKind ? ((JavaKind) phiPlatformKind).getStackKind() : phiPlatformKind);
+    private boolean verifyPHIKind(LIRKind derivedKind, LIRKind phiKind) {
+        PlatformKind derivedPlatformKind = derivedKind.getPlatformKind();
+        PlatformKind phiPlatformKind = gen.toRegisterKind(phiKind).getPlatformKind();
+        assert derivedPlatformKind.equals(phiPlatformKind) : "kinds don't match: " + derivedPlatformKind + " vs " + phiPlatformKind;
         return true;
     }
 
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java	Thu Sep 17 11:08:55 2015 +0200
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java	Thu Sep 17 14:29:34 2015 +0200
@@ -277,7 +277,7 @@
     @Override
     public Variable emitLoad(LIRKind kind, Value address, LIRFrameState state) {
         SPARCAddressValue loadAddress = asAddressValue(address);
-        Variable result = newVariable(toStackKind(kind));
+        Variable result = newVariable(toRegisterKind(kind));
         append(new LoadOp(kind.getPlatformKind(), result, loadAddress, state));
         return result;
     }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java	Thu Sep 17 11:08:55 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java	Thu Sep 17 14:29:34 2015 +0200
@@ -86,15 +86,6 @@
         // @formatter:on
     }
 
-    protected static LIRKind toStackKind(LIRKind kind) {
-        if (kind.getPlatformKind() instanceof JavaKind) {
-            JavaKind stackKind = ((JavaKind) kind.getPlatformKind()).getStackKind();
-            return kind.changeType(stackKind);
-        } else {
-            return kind;
-        }
-    }
-
     private final LIRKindTool lirKindTool;
 
     private final CodeGenProviders providers;
@@ -160,7 +151,7 @@
     @Override
     public Value emitConstant(LIRKind kind, Constant constant) {
         if (constant instanceof JavaConstant && canInlineConstant((JavaConstant) constant)) {
-            return new ConstantValue(kind, constant);
+            return new ConstantValue(toRegisterKind(kind), constant);
         } else {
             return emitLoadConstant(kind, constant);
         }
@@ -440,6 +431,15 @@
         }
     }
 
+    public LIRKind toRegisterKind(LIRKind kind) {
+        JavaKind stackKind = ((JavaKind) kind.getPlatformKind()).getStackKind();
+        if (stackKind != kind.getPlatformKind()) {
+            return kind.changeType(stackKind);
+        } else {
+            return kind;
+        }
+    }
+
     public AbstractBlockBase<?> getCurrentBlock() {
         return currentBlock;
     }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Thu Sep 17 11:08:55 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Thu Sep 17 14:29:34 2015 +0200
@@ -98,6 +98,14 @@
 
     Value emitJavaConstant(JavaConstant constant);
 
+    /**
+     * Some backends need to convert sub-word kinds to a larger kind in {@link #emitLoad} and
+     * {@link #emitLoadConstant} because sub-word registers can't be accessed. This method converts
+     * the {@link LIRKind} of a memory location or constant to the {@link LIRKind} that will be used
+     * when it is loaded into a register.
+     */
+    LIRKind toRegisterKind(LIRKind kind);
+
     AllocatableValue emitLoadConstant(LIRKind kind, Constant constant);
 
     Variable emitLoad(LIRKind kind, Value address, LIRFrameState state);