changeset 16281:14e56cef5be8

Start to make ValuePosition aware of CompositeValues.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 25 Jun 2014 19:23:30 +0200
parents 266db8cf4dc6
children aabd00bc6028
files 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/LIRInstructionClass.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java
diffstat 4 files changed, 104 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java	Wed Jun 25 16:15:35 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java	Wed Jun 25 19:23:30 2014 +0200
@@ -29,6 +29,8 @@
 import com.oracle.graal.lir.LIRInstruction.InstructionValueProcedure;
 import com.oracle.graal.lir.LIRInstruction.OperandFlag;
 import com.oracle.graal.lir.LIRInstruction.OperandMode;
+import com.oracle.graal.lir.LIRInstruction.ValuePositionProcedure;
+import com.oracle.graal.lir.LIRInstructionClass.ValuePosition;
 
 /**
  * Base class to represent values that need to be stored in more than one register.
@@ -58,6 +60,10 @@
         valueClass.forEachComponent(inst, this, mode, proc);
     }
 
+    public final void forEachComponent(LIRInstruction inst, OperandMode mode, ValuePositionProcedure proc, ValuePosition superPosition) {
+        valueClass.forEachComponent(inst, this, mode, proc, superPosition);
+    }
+
     @Override
     public String toString() {
         return valueClass.toString(this);
@@ -76,4 +82,9 @@
         }
         return false;
     }
+
+    CompositeValueClass getValueClass() {
+        return valueClass;
+    }
+
 }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java	Wed Jun 25 16:15:35 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java	Wed Jun 25 19:23:30 2014 +0200
@@ -25,11 +25,14 @@
 import java.lang.reflect.*;
 import java.util.*;
 
+import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.lir.CompositeValue.Component;
 import com.oracle.graal.lir.LIRInstruction.InstructionValueProcedure;
 import com.oracle.graal.lir.LIRInstruction.OperandFlag;
 import com.oracle.graal.lir.LIRInstruction.OperandMode;
+import com.oracle.graal.lir.LIRInstruction.ValuePositionProcedure;
+import com.oracle.graal.lir.LIRInstructionClass.ValuePosition;
 
 /**
  * Lazily associated metadata for every {@link CompositeValue} type. The metadata includes:
@@ -143,6 +146,10 @@
         forEach(inst, obj, directComponentCount, componentOffsets, mode, componentFlags, proc);
     }
 
+    public final void forEachComponent(LIRInstruction inst, CompositeValue obj, OperandMode mode, ValuePositionProcedure proc, ValuePosition superPosition) {
+        forEach(inst, obj, directComponentCount, componentOffsets, mode, componentFlags, proc, superPosition);
+    }
+
     public String toString(CompositeValue obj) {
         StringBuilder result = new StringBuilder();
 
@@ -154,4 +161,8 @@
 
         return result.toString();
     }
+
+    Value get(CompositeValue obj, ValuePosition pos) {
+        return getValueForPosition(obj, componentOffsets, directComponentCount, pos);
+    }
 }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java	Wed Jun 25 16:15:35 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java	Wed Jun 25 19:23:30 2014 +0200
@@ -252,21 +252,34 @@
         private final OperandMode mode;
         private final int index;
         private final int subIndex;
+        private final ValuePosition superPosition;
 
-        public ValuePosition(OperandMode mode, int index, int subIndex) {
+        public static final int NO_SUBINDEX = -1;
+        public static final ValuePosition ROOT_VALUE_POSITION = null;
+
+        public ValuePosition(OperandMode mode, int index, int subIndex, ValuePosition superPosition) {
             this.mode = mode;
             this.index = index;
             this.subIndex = subIndex;
+            this.superPosition = superPosition;
         }
 
         public Value get(LIRInstruction inst) {
             return inst.getLIRInstructionClass().get(inst, this);
         }
 
+        /**
+         * @deprecated Not yet sure this is safe for {@link CompositeValue}s.
+         */
+        @Deprecated
         public EnumSet<OperandFlag> getFlags(LIRInstruction inst) {
             return inst.getLIRInstructionClass().getFlags(this);
         }
 
+        /**
+         * @deprecated Not yet sure this is safe for {@link CompositeValue}s.
+         */
+        @Deprecated
         public void set(LIRInstruction inst, Value value) {
             inst.getLIRInstructionClass().set(inst, this, value);
         }
@@ -283,9 +296,16 @@
             return mode;
         }
 
+        public ValuePosition getSuperPosition() {
+            return superPosition;
+        }
+
         @Override
         public String toString() {
-            return mode.toString() + index + "/" + subIndex;
+            if (superPosition == ROOT_VALUE_POSITION) {
+                return mode.toString() + index + "/" + subIndex;
+            }
+            return superPosition.toString() + "[" + mode.toString() + index + "/" + subIndex + "]";
         }
 
         @Override
@@ -295,6 +315,7 @@
             result = prime * result + index;
             result = prime * result + ((mode == null) ? 0 : mode.hashCode());
             result = prime * result + subIndex;
+            result = prime * result + ((superPosition == null) ? 0 : superPosition.hashCode());
             return result;
         }
 
@@ -319,11 +340,19 @@
             if (subIndex != other.subIndex) {
                 return false;
             }
+            if (superPosition == null) {
+                if (other.superPosition != null) {
+                    return false;
+                }
+            } else if (!superPosition.equals(other.superPosition)) {
+                return false;
+            }
             return true;
         }
+
     }
 
-    protected Value get(LIRInstruction obj, ValuePosition pos) {
+    private Value getValueFromLIRInstruction(LIRInstruction obj, ValuePosition pos) {
         long[] offsets;
         int directCount;
         switch (pos.getMode()) {
@@ -346,13 +375,29 @@
             default:
                 throw GraalInternalError.shouldNotReachHere("unkown OperandMode: " + pos.getMode());
         }
-        if (pos.index < directCount) {
-            return getValue(obj, offsets[pos.getIndex()]);
-        }
-        return getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()];
+        return getValueForPosition(obj, offsets, directCount, pos);
     }
 
-    protected void set(LIRInstruction obj, ValuePosition pos, Value value) {
+    private Value getRecursive(LIRInstruction obj, ValuePosition pos) {
+        ValuePosition superPosition = pos.getSuperPosition();
+        if (superPosition == ValuePosition.ROOT_VALUE_POSITION) {
+            // At this point we are at the top of the ValuePosition tree
+            return getValueFromLIRInstruction(obj, pos);
+        }
+        // Get the containing value
+        Value superValue = getRecursive(obj, superPosition);
+        assert superValue instanceof CompositeValue : "only CompositeValue can contain nested values " + superValue;
+        CompositeValue compValue = (CompositeValue) superValue;
+        return compValue.getValueClass().get(compValue, pos);
+    }
+
+    private Value get(LIRInstruction obj, ValuePosition pos) {
+        Value value = getRecursive(obj, pos);
+        assert !(value instanceof CompositeValue) : "should never return a CompositeValue";
+        return value;
+    }
+
+    private void set(LIRInstruction obj, ValuePosition pos, Value value) {
         long[] offsets;
         int directCount;
         switch (pos.getMode()) {
@@ -381,7 +426,7 @@
         getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()] = value;
     }
 
-    public EnumSet<OperandFlag> getFlags(ValuePosition pos) {
+    private EnumSet<OperandFlag> getFlags(ValuePosition pos) {
         switch (pos.getMode()) {
             case USE:
                 return useFlags[pos.getIndex()];
@@ -418,19 +463,19 @@
     }
 
     public final void forEachUse(LIRInstruction obj, ValuePositionProcedure proc) {
-        forEach(obj, obj, directUseCount, useOffsets, OperandMode.USE, useFlags, proc);
+        forEach(obj, obj, directUseCount, useOffsets, OperandMode.USE, useFlags, proc, ValuePosition.ROOT_VALUE_POSITION);
     }
 
     public final void forEachAlive(LIRInstruction obj, ValuePositionProcedure proc) {
-        forEach(obj, obj, directAliveCount, aliveOffsets, OperandMode.ALIVE, aliveFlags, proc);
+        forEach(obj, obj, directAliveCount, aliveOffsets, OperandMode.ALIVE, aliveFlags, proc, ValuePosition.ROOT_VALUE_POSITION);
     }
 
     public final void forEachTemp(LIRInstruction obj, ValuePositionProcedure proc) {
-        forEach(obj, obj, directTempCount, tempOffsets, OperandMode.TEMP, tempFlags, proc);
+        forEach(obj, obj, directTempCount, tempOffsets, OperandMode.TEMP, tempFlags, proc, ValuePosition.ROOT_VALUE_POSITION);
     }
 
     public final void forEachDef(LIRInstruction obj, ValuePositionProcedure proc) {
-        forEach(obj, obj, directDefCount, defOffsets, OperandMode.DEF, defFlags, proc);
+        forEach(obj, obj, directDefCount, defOffsets, OperandMode.DEF, defFlags, proc, ValuePosition.ROOT_VALUE_POSITION);
     }
 
     public final void forEachUse(LIRInstruction obj, InstructionValueProcedure proc) {
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Wed Jun 25 16:15:35 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Wed Jun 25 19:23:30 2014 +0200
@@ -23,6 +23,7 @@
 package com.oracle.graal.lir;
 
 import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
+import static com.oracle.graal.lir.LIRInstructionClass.ValuePosition.*;
 
 import java.lang.annotation.*;
 import java.lang.reflect.*;
@@ -148,21 +149,41 @@
         }
     }
 
-    protected static void forEach(LIRInstruction inst, Object obj, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags, ValuePositionProcedure proc) {
+    protected static void forEach(LIRInstruction inst, Object obj, int directCount, long[] offsets, OperandMode mode, EnumSet<OperandFlag>[] flags, ValuePositionProcedure proc,
+                    ValuePosition superPosition) {
         for (int i = 0; i < offsets.length; i++) {
             assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(flags[i]);
 
             if (i < directCount) {
-                proc.doValue(inst, new ValuePosition(mode, i, 0));
+                Value value = getValue(obj, offsets[i]);
+                doForValue(inst, mode, proc, superPosition, i, NO_SUBINDEX, value);
             } else {
                 Value[] values = getValueArray(obj, offsets[i]);
                 for (int j = 0; j < values.length; j++) {
-                    proc.doValue(inst, new ValuePosition(mode, i, j));
+                    Value value = values[j];
+                    doForValue(inst, mode, proc, superPosition, i, j, value);
                 }
             }
         }
     }
 
+    private static void doForValue(LIRInstruction inst, OperandMode mode, ValuePositionProcedure proc, ValuePosition superPosition, int index, int subIndex, Value value) {
+        ValuePosition position = new ValuePosition(mode, index, subIndex, superPosition);
+        if (value instanceof CompositeValue) {
+            CompositeValue composite = (CompositeValue) value;
+            composite.forEachComponent(inst, mode, proc, position);
+        } else {
+            proc.doValue(inst, position);
+        }
+    }
+
+    protected static Value getValueForPosition(Object obj, long[] offsets, int directCount, ValuePosition pos) {
+        if (pos.getIndex() < directCount) {
+            return getValue(obj, offsets[pos.getIndex()]);
+        }
+        return getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()];
+    }
+
     protected static Value getValue(Object obj, long offset) {
         return (Value) unsafe.getObject(obj, offset);
     }