changeset 17330:106f78219955

Merge.
author Doug Simon <doug.simon@oracle.com>
date Fri, 03 Oct 2014 15:16:31 +0200
parents 1e7e354e407f (current diff) 0b8483cd42c0 (diff)
children 7b6e829e995a
files
diffstat 3 files changed, 217 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/ValuePositionTest3.java	Fri Oct 03 15:16:31 2014 +0200
@@ -0,0 +1,158 @@
+/*
+ * 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.test;
+
+import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
+import static org.junit.Assert.*;
+
+import java.util.*;
+
+import org.junit.*;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.lir.*;
+import com.oracle.graal.lir.LIRInstruction.OperandFlag;
+import com.oracle.graal.lir.LIRInstruction.OperandMode;
+import com.oracle.graal.lir.asm.*;
+
+public class ValuePositionTest3 {
+
+    public static final class TestAddressValue extends CompositeValue {
+
+        private static final long serialVersionUID = -2679790860680123026L;
+
+        @Component({REG, OperandFlag.ILLEGAL}) protected AllocatableValue base;
+        @Component({REG, OperandFlag.ILLEGAL}) protected AllocatableValue index;
+
+        public TestAddressValue(LIRKind kind, AllocatableValue base) {
+            this(kind, base, Value.ILLEGAL);
+        }
+
+        public TestAddressValue(LIRKind kind, AllocatableValue base, AllocatableValue index) {
+            super(kind);
+            this.base = base;
+            this.index = index;
+        }
+    }
+
+    private static class DummyValue extends AllocatableValue {
+
+        private static final long serialVersionUID = 3620305384660607012L;
+        private final int id;
+        private static int counter = 0;
+
+        protected DummyValue() {
+            super(LIRKind.Illegal);
+            this.id = counter++;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + id;
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (!super.equals(obj)) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            DummyValue other = (DummyValue) obj;
+            if (id != other.id) {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            return "DummyValue" + id;
+        }
+
+    }
+
+    private static class TestOp extends LIRInstruction {
+
+        @Use({COMPOSITE}) protected Value value;
+
+        public TestOp(Value value) {
+            this.value = value;
+        }
+
+        @Override
+        public void emitCode(CompilationResultBuilder crb) {
+            fail("should not reach!");
+        }
+
+        @Override
+        public String toString() {
+            return "TestOp [" + value + "]";
+        }
+
+    }
+
+    @Test
+    public void test0() {
+        DummyValue dummyValue0 = new DummyValue();
+        DummyValue dummyValue1 = new DummyValue();
+
+        TestAddressValue compValue0 = new TestAddressValue(LIRKind.Illegal, dummyValue0, dummyValue1);
+
+        LIRInstruction op = new TestOp(compValue0);
+
+        HashMap<Value, EnumSet<OperandFlag>> positionMap = new HashMap<>();
+        HashMap<Value, EnumSet<OperandFlag>> normalMap = new HashMap<>();
+
+        op.forEachInputPos(new ValuePositionProcedure() {
+
+            @Override
+            public void doValue(LIRInstruction instruction, ValuePosition position) {
+                positionMap.put(position.get(instruction), position.getFlags());
+            }
+        });
+        op.visitEachInput(new InstructionValueConsumer() {
+
+            @Override
+            public void visitValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+                normalMap.put(value, flags);
+            }
+        });
+
+        assertEquals(normalMap.size(), positionMap.size());
+        assertTrue(normalMap.keySet().containsAll(positionMap.keySet()));
+        normalMap.keySet().forEach(key -> {
+            EnumSet<OperandFlag> normal = normalMap.get(key);
+            EnumSet<OperandFlag> position = positionMap.get(key);
+            assertTrue(normal.containsAll(position));
+            assertTrue(position.containsAll(normal));
+        });
+    }
+}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Fri Oct 03 15:16:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java	Fri Oct 03 15:16:31 2014 +0200
@@ -304,19 +304,18 @@
 
             if (i < values.getDirectCount()) {
                 Value value = values.getValue(obj, i);
-                doForValue(inst, mode, proc, outerPosition, i, ValuePosition.NO_SUBINDEX, value);
+                doForValue(inst, values, mode, proc, outerPosition, i, ValuePosition.NO_SUBINDEX, value);
             } else {
                 Value[] valueArray = values.getValueArray(obj, i);
                 for (int j = 0; j < valueArray.length; j++) {
                     Value value = valueArray[j];
-                    doForValue(inst, mode, proc, outerPosition, i, j, value);
+                    doForValue(inst, values, mode, proc, outerPosition, i, j, value);
                 }
             }
         }
     }
 
-    private static void doForValue(LIRInstruction inst, OperandMode mode, ValuePositionProcedure proc, ValuePosition outerPosition, int index, int subIndex, Value value) {
-        Values values = inst.getLIRInstructionClass().getValues(mode);
+    private static void doForValue(LIRInstruction inst, Values values, OperandMode mode, ValuePositionProcedure proc, ValuePosition outerPosition, int index, int subIndex, Value value) {
         ValuePosition position = new ValuePosition(values, index, subIndex, outerPosition);
         if (value instanceof CompositeValue) {
             CompositeValue composite = (CompositeValue) value;
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePosition.java	Fri Oct 03 15:16:02 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePosition.java	Fri Oct 03 15:16:31 2014 +0200
@@ -29,75 +29,108 @@
 import com.oracle.graal.lir.LIRIntrospection.Values;
 
 /**
- * Describes an operand slot for a {@link LIRInstructionClass}.
+ * Describes an operand slot for a {@link LIRInstruction}.
  */
 public final class ValuePosition {
 
+    /**
+     * The {@linkplain Values offsets} to the fields of the containing element (either
+     * {@link LIRInstruction} or {@link CompositeValue}).
+     */
     private final Values values;
+    /**
+     * The index into {@link #values}.
+     *
+     * @see Values#getValue(Object, int)
+     */
     private final int index;
+    /**
+     * The sub-index if {@link #index} points to a value array, otherwise {@link #NO_SUBINDEX}.
+     *
+     * @see Values#getDirectCount()
+     * @see Values#getValueArray(Object, int)
+     */
     private final int subIndex;
+    /**
+     * @see #getOuterPosition()
+     */
     private final ValuePosition outerPosition;
 
     public static final int NO_SUBINDEX = -1;
     public static final ValuePosition ROOT_VALUE_POSITION = null;
 
-    public ValuePosition(Values values, int index, int subIndex, ValuePosition outerPosition) {
+    ValuePosition(Values values, int index, int subIndex, ValuePosition outerPosition) {
         this.values = values;
         this.index = index;
         this.subIndex = subIndex;
         this.outerPosition = outerPosition;
     }
 
+    /**
+     * @return True if the value denoted by this {@linkplain ValuePosition position} is part of a
+     *         {@link CompositeValue}.
+     */
     public boolean isCompositePosition() {
         return outerPosition != ROOT_VALUE_POSITION;
     }
 
-    public Value get(Object inst) {
+    /**
+     * @param inst The instruction this {@linkplain ValuePosition position} belongs to.
+     * @return The value denoted by this {@linkplain ValuePosition position}.
+     */
+    public Value get(LIRInstruction inst) {
         if (isCompositePosition()) {
             CompositeValue compValue = (CompositeValue) outerPosition.get(inst);
             return compValue.getValueClass().getValue(compValue, this);
         }
-        return getValue(inst);
+        if (index < values.getDirectCount()) {
+            return values.getValue(inst, index);
+        }
+        return values.getValueArray(inst, index)[subIndex];
     }
 
+    /**
+     * Sets the value denoted by this {@linkplain ValuePosition position}.
+     *
+     * @param inst The instruction this {@linkplain ValuePosition position} belongs to.
+     */
     public void set(LIRInstruction inst, Value value) {
         if (isCompositePosition()) {
             CompositeValue compValue = (CompositeValue) outerPosition.get(inst);
             CompositeValue newCompValue = compValue.getValueClass().createUpdatedValue(compValue, this, value);
             outerPosition.set(inst, newCompValue);
         } else {
-            setValue(inst, value);
+            if (index < values.getDirectCount()) {
+                values.setValue(inst, index, value);
+            } else {
+                values.getValueArray(inst, index)[subIndex] = value;
+            }
         }
     }
 
-    public int getSubIndex() {
+    int getSubIndex() {
         return subIndex;
     }
 
-    public int getIndex() {
+    int getIndex() {
         return index;
     }
 
+    /**
+     * @return The flags associated with the value denoted by this {@linkplain ValuePosition
+     *         position}.
+     */
     public EnumSet<OperandFlag> getFlags() {
         return values.getFlags(index);
     }
 
-    public Value getValue(Object obj) {
-        if (index < values.getDirectCount()) {
-            return values.getValue(obj, index);
-        }
-        return values.getValueArray(obj, index)[subIndex];
-    }
-
-    public void setValue(Object obj, Value value) {
-        if (index < values.getDirectCount()) {
-            values.setValue(obj, index, value);
-        } else {
-            values.getValueArray(obj, index)[subIndex] = value;
-        }
-    }
-
-    public ValuePosition getSuperPosition() {
+    /**
+     * @return The {@link ValuePosition} of the containing {@link CompositeValue} if this value is
+     *         part of a {@link CompositeValue}, otherwise {@link #ROOT_VALUE_POSITION}.
+     *
+     * @see #isCompositePosition()
+     */
+    public ValuePosition getOuterPosition() {
         return outerPosition;
     }