changeset 16797:8cbbd7cb740f

Introduce InstructionValueProcedureBase.
author Josef Eisl <josef.eisl@jku.at>
date Tue, 12 Aug 2014 17:38:00 +0200
parents 0d47af538a92
children 07110b72e04a
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotLIRFrameState.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.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/LIRInstructionClass.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java
diffstat 8 files changed, 81 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotLIRFrameState.java	Tue Aug 12 16:18:07 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotLIRFrameState.java	Tue Aug 12 17:38:00 2014 +0200
@@ -38,11 +38,11 @@
     }
 
     @Override
-    protected Value processValue(LIRInstruction inst, InstructionValueProcedure proc, Value value) {
+    protected Value processValue(LIRInstruction inst, InstructionValueProcedureBase proc, Value value) {
         if (value instanceof HotSpotMonitorValue) {
             HotSpotMonitorValue monitor = (HotSpotMonitorValue) value;
             if (processed(monitor.getOwner())) {
-                monitor.setOwner(proc.doValue(inst, monitor.getOwner(), OperandMode.ALIVE, STATE_FLAGS));
+                monitor.setOwner(proc.processValue(inst, monitor.getOwner(), OperandMode.ALIVE, STATE_FLAGS));
             }
             return value;
         } else {
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java	Tue Aug 12 16:18:07 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java	Tue Aug 12 17:38:00 2014 +0200
@@ -54,7 +54,7 @@
         valueClass = CompositeValueClass.get(getClass());
     }
 
-    public final CompositeValue forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueProcedure proc) {
+    public final CompositeValue forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueProcedureBase proc) {
         return valueClass.forEachComponent(inst, this, mode, proc);
     }
 
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java	Tue Aug 12 16:18:07 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java	Tue Aug 12 17:38:00 2014 +0200
@@ -139,7 +139,7 @@
         return str.toString();
     }
 
-    public final CompositeValue forEachComponent(LIRInstruction inst, CompositeValue obj, OperandMode mode, InstructionValueProcedure proc) {
+    public final CompositeValue forEachComponent(LIRInstruction inst, CompositeValue obj, OperandMode mode, InstructionValueProcedureBase proc) {
         return forEachComponent(inst, obj, directComponentCount, componentOffsets, mode, componentFlags, proc);
     }
 
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java	Tue Aug 12 16:18:07 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java	Tue Aug 12 17:38:00 2014 +0200
@@ -30,9 +30,10 @@
 
 /**
  * Iterator for iterating over a list of values. Subclasses must overwrite one of the doValue
- * methods. Clients of the class must only call the doValue method that takes additional parameters.
+ * methods. Clients should not use this class directly but call
+ * {@link InstructionValueProcedureBase#processValue} instead.
  */
-public abstract class InstructionValueProcedure {
+public abstract class InstructionValueProcedure extends InstructionValueProcedureBase {
 
     /**
      * Iterator method to be overwritten. This version of the iterator does not take additional
@@ -56,7 +57,12 @@
      * @param flags A set of flags for the value.
      * @return The new value to replace the value that was passed in.
      */
-    public Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+    protected Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
         return doValue(instruction, value);
     }
+
+    @Override
+    public final Value processValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+        return doValue(instruction, value, mode, flags);
+    }
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedureBase.java	Tue Aug 12 17:38:00 2014 +0200
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.lir;
+
+import java.util.*;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.lir.LIRInstruction.*;
+
+/**
+ * Common base class for modifying and non-modifying {@link Value value} iterators.
+ *
+ * This type should not be sub-classed directly. Use {@link InstructionValueProcedureBase} or
+ * {@link InstructionValueConsumer} instead.
+ *
+ * @see InstructionValueProcedure
+ */
+public abstract class InstructionValueProcedureBase {
+
+    /**
+     * Iterator method to be overwritten. This version of the iterator gets additional parameters
+     * about the processed value.
+     *
+     * @param instruction The current instruction.
+     * @param value The value that is iterated.
+     * @param mode The operand mode for the value.
+     * @param flags A set of flags for the value.
+     * @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
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java	Tue Aug 12 16:18:07 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java	Tue Aug 12 17:38:00 2014 +0200
@@ -62,7 +62,7 @@
      *
      * @param proc The procedure called for variables.
      */
-    public void forEachState(LIRInstruction inst, InstructionValueProcedure proc) {
+    public void forEachState(LIRInstruction inst, InstructionValueProcedureBase proc) {
         for (BytecodeFrame cur = topFrame; cur != null; cur = cur.caller()) {
             processValues(inst, cur.values, proc);
         }
@@ -79,16 +79,16 @@
      */
     protected static final EnumSet<OperandFlag> STATE_FLAGS = EnumSet.of(OperandFlag.REG, OperandFlag.STACK);
 
-    protected void processValues(LIRInstruction inst, Value[] values, InstructionValueProcedure proc) {
+    protected void processValues(LIRInstruction inst, Value[] values, InstructionValueProcedureBase proc) {
         for (int i = 0; i < values.length; i++) {
             Value value = values[i];
             values[i] = processValue(inst, proc, value);
         }
     }
 
-    protected Value processValue(LIRInstruction inst, InstructionValueProcedure proc, Value value) {
+    protected Value processValue(LIRInstruction inst, InstructionValueProcedureBase proc, Value value) {
         if (processed(value)) {
-            return proc.doValue(inst, value, OperandMode.ALIVE, STATE_FLAGS);
+            return proc.processValue(inst, value, OperandMode.ALIVE, STATE_FLAGS);
         }
         return value;
     }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java	Tue Aug 12 16:18:07 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java	Tue Aug 12 17:38:00 2014 +0200
@@ -343,23 +343,23 @@
         forEach(obj, obj, directDefCount, defOffsets, OperandMode.DEF, defFlags, proc, ValuePosition.ROOT_VALUE_POSITION);
     }
 
-    public final void forEachUse(LIRInstruction obj, InstructionValueProcedure proc) {
+    public final void forEachUse(LIRInstruction obj, InstructionValueProcedureBase proc) {
         forEach(obj, directUseCount, useOffsets, OperandMode.USE, useFlags, proc);
     }
 
-    public final void forEachAlive(LIRInstruction obj, InstructionValueProcedure proc) {
+    public final void forEachAlive(LIRInstruction obj, InstructionValueProcedureBase proc) {
         forEach(obj, directAliveCount, aliveOffsets, OperandMode.ALIVE, aliveFlags, proc);
     }
 
-    public final void forEachTemp(LIRInstruction obj, InstructionValueProcedure proc) {
+    public final void forEachTemp(LIRInstruction obj, InstructionValueProcedureBase proc) {
         forEach(obj, directTempCount, tempOffsets, OperandMode.TEMP, tempFlags, proc);
     }
 
-    public final void forEachDef(LIRInstruction obj, InstructionValueProcedure proc) {
+    public final void forEachDef(LIRInstruction obj, InstructionValueProcedureBase proc) {
         forEach(obj, directDefCount, defOffsets, OperandMode.DEF, defFlags, proc);
     }
 
-    public final void forEachState(LIRInstruction obj, InstructionValueProcedure proc) {
+    final void forEachState(LIRInstruction obj, InstructionValueProcedureBase proc) {
         for (int i = 0; i < stateOffsets.length; i++) {
             LIRFrameState state = getState(obj, stateOffsets[i]);
             if (state != null) {
@@ -393,7 +393,7 @@
         for (int i = 0; i < hintOffsets.length; i++) {
             if (i < hintDirectCount) {
                 Value hintValue = getValue(obj, hintOffsets[i]);
-                Value result = proc.doValue(obj, hintValue, null, null);
+                Value result = proc.processValue(obj, hintValue, null, null);
                 if (result != null) {
                     return result;
                 }
@@ -401,7 +401,7 @@
                 Value[] hintValues = getValueArray(obj, hintOffsets[i]);
                 for (int j = 0; j < hintValues.length; j++) {
                     Value hintValue = hintValues[j];
-                    Value result = proc.doValue(obj, hintValue, null, null);
+                    Value result = proc.processValue(obj, hintValue, null, null);
                     if (result != null) {
                         return result;
                     }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Tue Aug 12 16:18:07 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Tue Aug 12 17:38:00 2014 +0200
@@ -118,7 +118,7 @@
         }
     }
 
-    protected static void forEach(LIRInstruction inst, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags, InstructionValueProcedure proc) {
+    protected static void forEach(LIRInstruction inst, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags, InstructionValueProcedureBase proc) {
         for (int i = 0; i < offsets.length; i++) {
             assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(flags[i]);
 
@@ -129,7 +129,7 @@
                     CompositeValue composite = (CompositeValue) value;
                     newValue = composite.forEachComponent(inst, mode, proc);
                 } else {
-                    newValue = proc.doValue(inst, value, mode, flags[i]);
+                    newValue = proc.processValue(inst, value, mode, flags[i]);
                 }
                 if (!value.identityEquals(newValue)) {
                     setValue(inst, offsets[i], newValue);
@@ -143,7 +143,7 @@
                         CompositeValue composite = (CompositeValue) value;
                         newValue = composite.forEachComponent(inst, mode, proc);
                     } else {
-                        newValue = proc.doValue(inst, value, mode, flags[i]);
+                        newValue = proc.processValue(inst, value, mode, flags[i]);
                     }
                     if (!value.identityEquals(newValue)) {
                         values[j] = newValue;
@@ -154,7 +154,7 @@
     }
 
     protected static CompositeValue forEachComponent(LIRInstruction inst, CompositeValue obj, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags,
-                    InstructionValueProcedure proc) {
+                    InstructionValueProcedureBase proc) {
         CompositeValue newCompValue = null;
         for (int i = 0; i < offsets.length; i++) {
             assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(flags[i]);
@@ -166,7 +166,7 @@
                     CompositeValue composite = (CompositeValue) value;
                     newValue = composite.forEachComponent(inst, mode, proc);
                 } else {
-                    newValue = proc.doValue(inst, value, mode, flags[i]);
+                    newValue = proc.processValue(inst, value, mode, flags[i]);
                 }
                 if (!value.identityEquals(newValue)) {
                     // lazy initialize
@@ -185,7 +185,7 @@
                         CompositeValue composite = (CompositeValue) value;
                         newValue = composite.forEachComponent(inst, mode, proc);
                     } else {
-                        newValue = proc.doValue(inst, value, mode, flags[i]);
+                        newValue = proc.processValue(inst, value, mode, flags[i]);
                     }
                     if (!value.identityEquals(newValue)) {
                         // lazy initialize