changeset 17285:3a834111a632

Make [Instruction]ValueProcedure and [Instruction]ValueConsumer a FunctionalInterface.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 25 Sep 2014 17:04:52 +0200
parents d21962ea9617
children afafc0aad977
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionStateProcedure.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueConsumer.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedureBase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueConsumer.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePositionProcedure.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueProcedure.java
diffstat 13 files changed, 159 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Thu Sep 25 17:04:52 2014 +0200
@@ -2208,7 +2208,7 @@
         }
     }
 
-    class CheckConsumer extends ValueConsumer {
+    class CheckConsumer implements ValueConsumer {
 
         boolean ok;
         Interval curInterval;
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Thu Sep 25 17:04:52 2014 +0200
@@ -224,7 +224,7 @@
         return kernel;
     }
 
-    static final class RegisterAnalysis extends ValueConsumer {
+    static final class RegisterAnalysis implements ValueConsumer {
         private final SortedSet<Integer> signed32 = new TreeSet<>();
         private final SortedSet<Integer> signed64 = new TreeSet<>();
 
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionStateProcedure.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionStateProcedure.java	Thu Sep 25 17:04:52 2014 +0200
@@ -26,4 +26,4 @@
 public interface InstructionStateProcedure {
 
     void doState(LIRInstruction instruction, LIRFrameState state);
-}
\ No newline at end of file
+}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueConsumer.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueConsumer.java	Thu Sep 25 17:04:52 2014 +0200
@@ -31,7 +31,8 @@
 /**
  * Non-modifying version of {@link InstructionValueProcedure}.
  */
-public abstract class InstructionValueConsumer extends InstructionValueProcedureBase {
+@FunctionalInterface
+public interface InstructionValueConsumer {
 
     /**
      * Iterator method to be overwritten.
@@ -41,12 +42,5 @@
      * @param mode The operand mode for the value.
      * @param flags A set of flags for the value.
      */
-    public abstract void visitValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags);
-
-    @Override
-    public final Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
-        assert !(value instanceof CompositeValue) : String.format("Must not visit CompositeValues! Instruction: %s Value: %s", instruction, value);
-        visitValue(instruction, value, mode, flags);
-        return value;
-    }
-}
\ No newline at end of file
+    void visitValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags);
+}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java	Thu Sep 25 17:04:52 2014 +0200
@@ -30,10 +30,11 @@
 
 /**
  * Iterator for iterating over a list of values. Subclasses must overwrite one of the doValue
- * methods. Clients should not use this class directly but call
+ * methods. Clients should not use this interface directly but call
  * {@link InstructionValueProcedureBase#processValue} instead.
  */
-public abstract class InstructionValueProcedure extends InstructionValueProcedureBase {
+@FunctionalInterface
+public interface InstructionValueProcedure {
 
     /**
      * Iterator method to be overwritten.
@@ -44,11 +45,5 @@
      * @param flags A set of flags for the value.
      * @return The new value to replace the value that was passed in.
      */
-    public abstract Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags);
-
-    @Override
-    public final Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
-        assert !(value instanceof CompositeValue) : String.format("Must not visit CompositeValues! Instruction: %s Value: %s", instruction, value);
-        return doValue(instruction, value, mode, flags);
-    }
-}
\ No newline at end of file
+    Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags);
+}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedureBase.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedureBase.java	Thu Sep 25 17:04:52 2014 +0200
@@ -34,7 +34,9 @@
  * {@link InstructionValueConsumer} instead.
  *
  * @see InstructionValueProcedure
+ * @see ValueProcedure
  * @see InstructionValueConsumer
+ * @see ValueConsumer
  */
 public abstract class InstructionValueProcedureBase {
 
@@ -49,4 +51,62 @@
      * @return The new value to replace the value that was passed in.
      */
     abstract public Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags);
-}
\ No newline at end of file
+
+    /**
+     * Wraps an {@link InstructionValueProcedure} into an {@link InstructionValueProcedureBase}.
+     */
+    public static InstructionValueProcedureBase wrap(InstructionValueProcedure proc) {
+        return new InstructionValueProcedureBase() {
+
+            @Override
+            public Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+                return proc.doValue(instruction, value, mode, flags);
+            }
+        };
+
+    }
+
+    /**
+     * Wraps a {@link ValueProcedure} into an {@link InstructionValueProcedureBase}.
+     */
+    public static InstructionValueProcedureBase wrap(ValueProcedure proc) {
+        return new InstructionValueProcedureBase() {
+
+            @Override
+            public Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+                return proc.doValue(value, mode, flags);
+            }
+        };
+
+    }
+
+    /**
+     * Wraps an {@link InstructionValueConsumer} into an {@link InstructionValueProcedureBase}.
+     */
+    public static InstructionValueProcedureBase wrap(InstructionValueConsumer proc) {
+        return new InstructionValueProcedureBase() {
+
+            @Override
+            public Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+                proc.visitValue(instruction, value, mode, flags);
+                return value;
+            }
+        };
+
+    }
+
+    /**
+     * Wraps a {@link ValueConsumer} into an {@link InstructionValueProcedureBase}.
+     */
+    public static InstructionValueProcedureBase wrap(ValueConsumer proc) {
+        return new InstructionValueProcedureBase() {
+
+            @Override
+            public Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+                proc.visitValue(value, mode, flags);
+                return value;
+            }
+        };
+
+    }
+}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java	Thu Sep 25 17:04:52 2014 +0200
@@ -62,7 +62,11 @@
      *
      * @param proc The procedure called for variables.
      */
-    public void forEachState(LIRInstruction inst, InstructionValueProcedureBase proc) {
+    public void forEachState(LIRInstruction inst, InstructionValueProcedure proc) {
+        forEachState(inst, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    void forEachState(LIRInstruction inst, InstructionValueProcedureBase proc) {
         for (BytecodeFrame cur = topFrame; cur != null; cur = cur.caller()) {
             processValues(inst, cur.values, proc);
         }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java	Thu Sep 25 17:04:52 2014 +0200
@@ -236,49 +236,91 @@
 
     // InstructionValueProcedures
     public final void forEachInput(InstructionValueProcedure proc) {
-        instructionClass.forEachUse(this, proc);
+        instructionClass.forEachUse(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     public final void forEachAlive(InstructionValueProcedure proc) {
-        instructionClass.forEachAlive(this, proc);
+        instructionClass.forEachAlive(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     public final void forEachTemp(InstructionValueProcedure proc) {
-        instructionClass.forEachTemp(this, proc);
+        instructionClass.forEachTemp(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     public final void forEachOutput(InstructionValueProcedure proc) {
-        instructionClass.forEachDef(this, proc);
+        instructionClass.forEachDef(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void forEachState(InstructionValueProcedure proc) {
+        instructionClass.forEachState(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    // ValueProcedures
+    public final void forEachInput(ValueProcedure proc) {
+        instructionClass.forEachUse(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void forEachAlive(ValueProcedure proc) {
+        instructionClass.forEachAlive(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void forEachTemp(ValueProcedure proc) {
+        instructionClass.forEachTemp(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void forEachOutput(ValueProcedure proc) {
+        instructionClass.forEachDef(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void forEachState(ValueProcedure proc) {
+        instructionClass.forEachState(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     // States
-    public final void forEachState(InstructionValueProcedure proc) {
-        instructionClass.forEachState(this, proc);
-    }
-
     public final void forEachState(InstructionStateProcedure proc) {
         instructionClass.forEachState(this, proc);
     }
 
-    // Consumers
+    // InstructionValueConsumers
     public final void visitEachInput(InstructionValueConsumer proc) {
-        instructionClass.forEachUse(this, proc);
+        instructionClass.forEachUse(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     public final void visitEachAlive(InstructionValueConsumer proc) {
-        instructionClass.forEachAlive(this, proc);
+        instructionClass.forEachAlive(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     public final void visitEachTemp(InstructionValueConsumer proc) {
-        instructionClass.forEachTemp(this, proc);
+        instructionClass.forEachTemp(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     public final void visitEachOutput(InstructionValueConsumer proc) {
-        instructionClass.forEachDef(this, proc);
+        instructionClass.forEachDef(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     public final void visitEachState(InstructionValueConsumer proc) {
-        instructionClass.forEachState(this, proc);
+        instructionClass.forEachState(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    // ValueConsumers
+    public final void visitEachInput(ValueConsumer proc) {
+        instructionClass.forEachUse(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void visitEachAlive(ValueConsumer proc) {
+        instructionClass.forEachAlive(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void visitEachTemp(ValueConsumer proc) {
+        instructionClass.forEachTemp(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void visitEachOutput(ValueConsumer proc) {
+        instructionClass.forEachDef(this, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    public final void visitEachState(ValueConsumer proc) {
+        instructionClass.forEachState(this, InstructionValueProcedureBase.wrap(proc));
     }
 
     /**
@@ -297,7 +339,20 @@
      * @return The non-null value returned by the procedure, or null.
      */
     public Value forEachRegisterHint(Value value, OperandMode mode, InstructionValueProcedure proc) {
-        return instructionClass.forEachRegisterHint(this, mode, proc);
+        return instructionClass.forEachRegisterHint(this, mode, InstructionValueProcedureBase.wrap(proc));
+    }
+
+    /**
+     * @see #forEachRegisterHint(Value, OperandMode, InstructionValueProcedure)
+     * @param value The value the hints are needed for.
+     * @param mode The operand mode of the value.
+     * @param proc The procedure invoked for all the hints. If the procedure returns a non-null
+     *            value, the iteration is stopped and the value is returned by this method, i.e.,
+     *            clients can stop the iteration once a suitable hint has been found.
+     * @return The non-null value returned by the procedure, or null.
+     */
+    public Value forEachRegisterHint(Value value, OperandMode mode, ValueProcedure proc) {
+        return instructionClass.forEachRegisterHint(this, mode, InstructionValueProcedureBase.wrap(proc));
     }
 
     protected void verify() {
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java	Thu Sep 25 17:04:52 2014 +0200
@@ -268,7 +268,7 @@
         }
     }
 
-    final Value forEachRegisterHint(LIRInstruction obj, OperandMode mode, InstructionValueProcedure proc) {
+    final Value forEachRegisterHint(LIRInstruction obj, OperandMode mode, InstructionValueProcedureBase proc) {
         Values hints;
         if (mode == OperandMode.USE) {
             hints = defs;
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java	Thu Sep 25 17:04:52 2014 +0200
@@ -362,7 +362,7 @@
             /*
              * Value procedure for the instruction's output and temp values
              */
-            class OutputValueConsumer extends ValueConsumer {
+            class OutputValueConsumer implements ValueConsumer {
 
                 int opValueNum;
 
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueConsumer.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueConsumer.java	Thu Sep 25 17:04:52 2014 +0200
@@ -31,7 +31,8 @@
 /**
  * Non-modifying version of {@link ValueProcedure}.
  */
-public abstract class ValueConsumer extends InstructionValueConsumer {
+@FunctionalInterface
+public interface ValueConsumer {
 
     /**
      * Iterator method to be overwritten.
@@ -40,10 +41,6 @@
      * @param mode The operand mode for the value.
      * @param flags A set of flags for the value.
      */
-    public abstract void visitValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags);
+    void visitValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags);
 
-    @Override
-    public void visitValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
-        visitValue(value, mode, flags);
-    }
-}
\ No newline at end of file
+}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePositionProcedure.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePositionProcedure.java	Thu Sep 25 17:04:52 2014 +0200
@@ -36,4 +36,4 @@
      * @param position The position of the value that is iterated.
      */
     void doValue(LIRInstruction instruction, ValuePosition position);
-}
\ No newline at end of file
+}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueProcedure.java	Thu Sep 25 14:51:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueProcedure.java	Thu Sep 25 17:04:52 2014 +0200
@@ -31,7 +31,8 @@
 /**
  * Similar to {@link InstructionValueProcedure} but without an {@link LIRInstruction} parameter.
  */
-public abstract class ValueProcedure extends InstructionValueProcedure {
+@FunctionalInterface
+public interface ValueProcedure {
 
     /**
      * Iterator method to be overwritten.
@@ -41,10 +42,5 @@
      * @param flags A set of flags for the value.
      * @return The new value to replace the value that was passed in.
      */
-    public abstract Value doValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags);
-
-    @Override
-    public final Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
-        return doValue(value, mode, flags);
-    }
-}
\ No newline at end of file
+    Value doValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags);
+}