changeset 17314:3b6759c384a9

Introduce emitLoadConstant in LIRGeneratorTool.
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 02 Oct 2014 10:48:17 +0200
parents d6e4c9031ff6
children 979bf76f0fe3
files graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.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 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java
diffstat 11 files changed, 64 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java	Thu Oct 02 10:48:17 2014 +0200
@@ -595,10 +595,7 @@
 
     @Override
     protected Value appendConstant(Constant constant) {
-        if (gen.canInlineConstant(constant)) {
-            return constant;
-        }
-        return gen.emitMove(constant);
+        return gen.emitLoadConstant(constant);
     }
 
     @Override
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -93,21 +93,6 @@
     }
 
     @Override
-    public boolean canStoreConstant(Constant c) {
-        // there is no immediate move of 64-bit constants on Intel
-        switch (c.getKind()) {
-            case Long:
-                return Util.isInt(c.asLong()) && !getCodeCache().needsDataPatch(c);
-            case Double:
-                return false;
-            case Object:
-                return c.isNull();
-            default:
-                return true;
-        }
-    }
-
-    @Override
     public boolean canInlineConstant(Constant c) {
         switch (c.getKind()) {
             case Long:
@@ -119,13 +104,6 @@
         }
     }
 
-    @Override
-    public Variable emitMove(Value input) {
-        Variable result = newVariable(input.getLIRKind());
-        emitMove(result, input);
-        return result;
-    }
-
     protected AMD64LIRInstruction createMove(AllocatableValue dst, Value src) {
         if (src instanceof AMD64AddressValue) {
             return new LeaOp(dst, (AMD64AddressValue) src);
--- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -62,12 +62,6 @@
     }
 
     @Override
-    public boolean canStoreConstant(Constant c) {
-        // Operand b must be in the .reg state space.
-        return false;
-    }
-
-    @Override
     public boolean canInlineConstant(Constant c) {
         switch (c.getKind()) {
             case Long:
@@ -79,13 +73,6 @@
         }
     }
 
-    @Override
-    public Variable emitMove(Value input) {
-        Variable result = newVariable(input.getLIRKind());
-        emitMove(result, input);
-        return result;
-    }
-
     protected HSAILLIRInstruction createMove(AllocatableValue dst, Value src) {
         if (src instanceof HSAILAddressValue) {
             return new LeaOp(dst, (HSAILAddressValue) src);
--- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -93,12 +93,6 @@
     }
 
     @Override
-    public boolean canStoreConstant(Constant c) {
-        // Operand b must be in the .reg state space.
-        return false;
-    }
-
-    @Override
     public boolean canInlineConstant(Constant c) {
         switch (c.getKind()) {
             case Long:
@@ -131,13 +125,6 @@
     }
 
     @Override
-    public Variable emitMove(Value input) {
-        Variable result = newVariable(input.getLIRKind());
-        emitMove(result, input);
-        return result;
-    }
-
-    @Override
     public void emitMove(AllocatableValue dst, Value src) {
         if (isRegister(src) || isStackSlot(dst)) {
             append(new MoveFromRegOp(dst, src));
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -83,18 +83,6 @@
     }
 
     @Override
-    public boolean canStoreConstant(Constant c) {
-        // SPARC can only store integer null constants (via g0)
-        switch (c.getKind()) {
-            case Float:
-            case Double:
-                return false;
-            default:
-                return c.isDefaultForKind();
-        }
-    }
-
-    @Override
     public boolean canInlineConstant(Constant c) {
         switch (c.getKind()) {
             case Int:
@@ -108,13 +96,6 @@
         }
     }
 
-    @Override
-    public Variable emitMove(Value input) {
-        Variable result = newVariable(input.getLIRKind());
-        emitMove(result, input);
-        return result;
-    }
-
     protected SPARCLIRInstruction createMove(AllocatableValue dst, Value src) {
         if (src instanceof SPARCAddressValue) {
             return new LoadAddressOp(dst, (SPARCAddressValue) src);
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -51,6 +51,7 @@
 import com.oracle.graal.lir.amd64.AMD64Move.MoveFromRegOp;
 import com.oracle.graal.lir.amd64.AMD64Move.StoreOp;
 import com.oracle.graal.lir.gen.*;
+import com.oracle.graal.phases.util.*;
 
 /**
  * LIR generator specialized for AMD64 HotSpot.
@@ -459,6 +460,28 @@
         return result;
     }
 
+    /**
+     * Checks whether the supplied constant can be used without loading it into a register for store
+     * operations, i.e., on the right hand side of a memory access.
+     *
+     * @param c The constant to check.
+     * @return True if the constant can be used directly, false if the constant needs to be in a
+     *         register.
+     */
+    protected boolean canStoreConstant(Constant c) {
+        // there is no immediate move of 64-bit constants on Intel
+        switch (c.getKind()) {
+            case Long:
+                return Util.isInt(c.asLong()) && !getCodeCache().needsDataPatch(c);
+            case Double:
+                return false;
+            case Object:
+                return c.isNull();
+            default:
+                return true;
+        }
+    }
+
     @Override
     public void emitStore(LIRKind kind, Value address, Value inputVal, LIRFrameState state) {
         AMD64AddressValue storeAddress = asAddressValue(address);
--- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -93,8 +93,7 @@
         return config.narrowKlassBase;
     }
 
-    @Override
-    public boolean canStoreConstant(Constant c) {
+    private static boolean canStoreConstant(Constant c) {
         return !(c instanceof HotSpotObjectConstant);
     }
 
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -191,6 +191,17 @@
         return result;
     }
 
+    private static boolean canStoreConstant(Constant c) {
+        // SPARC can only store integer null constants (via g0)
+        switch (c.getKind()) {
+            case Float:
+            case Double:
+                return false;
+            default:
+                return c.isDefaultForKind();
+        }
+    }
+
     @Override
     public void emitStore(LIRKind kind, Value address, Value inputVal, LIRFrameState state) {
         SPARCAddressValue storeAddress = asAddressValue(address);
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java	Thu Oct 02 10:48:17 2014 +0200
@@ -111,7 +111,20 @@
     }
 
     @Override
-    public abstract Variable emitMove(Value input);
+    public Variable emitMove(Value input) {
+        Variable result = newVariable(input.getLIRKind());
+        emitMove(result, input);
+        return result;
+    }
+
+    @Override
+    public Value emitLoadConstant(Constant constant) {
+        if (canInlineConstant(constant)) {
+            return constant;
+        } else {
+            return emitMove(constant);
+        }
+    }
 
     public AllocatableValue asAllocatable(Value value) {
         if (isAllocatableValue(value)) {
@@ -128,6 +141,16 @@
         return (Variable) value;
     }
 
+    /**
+     * Checks whether the supplied constant can be used without loading it into a register for most
+     * operations, i.e., for commonly used arithmetic, logical, and comparison operations.
+     *
+     * @param c The constant to check.
+     * @return True if the constant can be used directly, false if the constant needs to be in a
+     *         register.
+     */
+    protected abstract boolean canInlineConstant(Constant c);
+
     public Value loadNonConst(Value value) {
         if (isConstant(value) && !canInlineConstant((Constant) value)) {
             return emitMove(value);
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Thu Oct 02 10:48:17 2014 +0200
@@ -52,6 +52,8 @@
 
     void doBlockEnd(AbstractBlock<?> block);
 
+    Value emitLoadConstant(Constant constant);
+
     Value emitLoad(LIRKind kind, Value address, LIRFrameState state);
 
     void emitStore(LIRKind kind, Value address, Value input, LIRFrameState state);
@@ -84,26 +86,6 @@
 
     Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args);
 
-    /**
-     * Checks whether the supplied constant can be used without loading it into a register for most
-     * operations, i.e., for commonly used arithmetic, logical, and comparison operations.
-     *
-     * @param c The constant to check.
-     * @return True if the constant can be used directly, false if the constant needs to be in a
-     *         register.
-     */
-    boolean canInlineConstant(Constant c);
-
-    /**
-     * Checks whether the supplied constant can be used without loading it into a register for store
-     * operations, i.e., on the right hand side of a memory access.
-     *
-     * @param c The constant to check.
-     * @return True if the constant can be used directly, false if the constant needs to be in a
-     *         register.
-     */
-    boolean canStoreConstant(Constant c);
-
     RegisterAttributes attributes(Register register);
 
     /**
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java	Thu Oct 02 10:36:12 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java	Thu Oct 02 10:48:17 2014 +0200
@@ -91,10 +91,10 @@
 
     @Override
     public void generate(NodeLIRBuilderTool gen) {
-        if (gen.getLIRGeneratorTool().canInlineConstant(value) || onlyUsedInVirtualState()) {
+        if (onlyUsedInVirtualState()) {
             gen.setResult(this, value);
         } else {
-            gen.setResult(this, gen.getLIRGeneratorTool().emitMove(value));
+            gen.setResult(this, gen.getLIRGeneratorTool().emitLoadConstant(value));
         }
     }