diff graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java @ 17314:3b6759c384a9

Introduce emitLoadConstant in LIRGeneratorTool.
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 02 Oct 2014 10:48:17 +0200
parents c6a1215d025b
children 2915eff532d4
line wrap: on
line diff
--- 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);