# HG changeset patch # User Tom Rodriguez # Date 1428433786 25200 # Node ID a69a7c0e0ccc264fa9c30125be81a04d7fab0213 # Parent da2251d7d3c5eb5a57a3382fdca68b350e4fb7cf Remove ValuePosition machinery diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest3.java --- a/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest3.java Tue Apr 14 17:53:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,187 +0,0 @@ -/* - * 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 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.asm.*; - -/** - * Same as {@link CompositeValueReplacementTest1} but with for {@link ValuePosition}s. - * - * @see CompositeValueReplacementTest1 - */ -public class CompositeValueReplacementTest3 { - - private static class NestedCompositeValue extends CompositeValue { - public static final CompositeValueClass TYPE = CompositeValueClass.create(NestedCompositeValue.class); - - private static final long serialVersionUID = -8804214200173503527L; - @Component({REG, OperandFlag.ILLEGAL}) protected Value value; - - public NestedCompositeValue(Value value) { - super(TYPE, LIRKind.Illegal); - this.value = value; - } - - } - - private static class DummyValue extends AbstractValue { - - private static final long serialVersionUID = -645435039553382737L; - private final int id; - private static int counter = 1; - - 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=" + id + "]"; - } - - } - - private static final class TestOp extends LIRInstruction { - public static final LIRInstructionClass TYPE = LIRInstructionClass.create(TestOp.class); - - @Use({COMPOSITE}) protected NestedCompositeValue compValue; - - public TestOp(NestedCompositeValue compValue) { - super(TYPE); - this.compValue = compValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb) { - fail("should not reach!"); - } - - } - - private static NestedCompositeValue createNestedCompValue(Value value, int nestingLevel) { - NestedCompositeValue compValue = new NestedCompositeValue(value); - for (int i = 0; i < nestingLevel; i++) { - compValue = new NestedCompositeValue(compValue); - } - return compValue; - } - - @Test - public void replaceCompValueTest0() { - DummyValue dummyValue1 = new DummyValue(); - DummyValue dummyValue2 = new DummyValue(); - DummyValue dummyValue3 = new DummyValue(); - NestedCompositeValue compValue1 = createNestedCompValue(dummyValue1, 0); - LIRInstruction op1 = new TestOp(compValue1); - LIRInstruction op2 = new TestOp(compValue1); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue2); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue3); - }); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue2, value); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue3, value); - }); - } - - @Test - public void replaceCompValueTest1() { - DummyValue dummyValue1 = new DummyValue(); - DummyValue dummyValue2 = new DummyValue(); - DummyValue dummyValue3 = new DummyValue(); - NestedCompositeValue compValue1 = createNestedCompValue(dummyValue1, 1); - LIRInstruction op1 = new TestOp(compValue1); - LIRInstruction op2 = new TestOp(compValue1); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue2); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue3); - }); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue2, value); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue3, value); - }); - } -} diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest4.java --- a/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest4.java Tue Apr 14 17:53:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,187 +0,0 @@ -/* - * 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 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.asm.*; - -/** - * Same as {@link CompositeValueReplacementTest2} but with value arrays {@link ValuePosition}s. - * - * @see CompositeValueReplacementTest2 - */ -public class CompositeValueReplacementTest4 { - - private static class NestedCompositeValue extends CompositeValue { - public static final CompositeValueClass TYPE = CompositeValueClass.create(NestedCompositeValue.class); - - private static final long serialVersionUID = -8804214200173503527L; - @Component({REG, OperandFlag.ILLEGAL}) protected Value[] values; - - public NestedCompositeValue(Value value) { - super(TYPE, LIRKind.Illegal); - this.values = new Value[]{value}; - } - - } - - private static class DummyValue extends AbstractValue { - - private static final long serialVersionUID = -645435039553382737L; - private final int id; - private static int counter = 1; - - 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=" + id + "]"; - } - - } - - private static class TestOp extends LIRInstruction { - public static final LIRInstructionClass TYPE = LIRInstructionClass.create(TestOp.class); - - @Use({COMPOSITE}) protected NestedCompositeValue compValue; - - public TestOp(NestedCompositeValue compValue) { - super(TYPE); - this.compValue = compValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb) { - fail("should not reach!"); - } - - } - - private static NestedCompositeValue createNestedCompValue(Value value, int nestingLevel) { - NestedCompositeValue compValue = new NestedCompositeValue(value); - for (int i = 0; i < nestingLevel; i++) { - compValue = new NestedCompositeValue(compValue); - } - return compValue; - } - - @Test - public void replaceCompValueTest0() { - DummyValue dummyValue1 = new DummyValue(); - DummyValue dummyValue2 = new DummyValue(); - DummyValue dummyValue3 = new DummyValue(); - NestedCompositeValue compValue1 = createNestedCompValue(dummyValue1, 0); - LIRInstruction op1 = new TestOp(compValue1); - LIRInstruction op2 = new TestOp(compValue1); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue2); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue3); - }); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue2, value); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue3, value); - }); - } - - @Test - public void replaceCompValueTest1() { - DummyValue dummyValue1 = new DummyValue(); - DummyValue dummyValue2 = new DummyValue(); - DummyValue dummyValue3 = new DummyValue(); - NestedCompositeValue compValue1 = createNestedCompValue(dummyValue1, 1); - LIRInstruction op1 = new TestOp(compValue1); - LIRInstruction op2 = new TestOp(compValue1); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue2); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue1, value); - position.set(instruction, dummyValue3); - }); - - op1.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue2, value); - }); - - op2.forEachInputPos((instruction, position) -> { - Value value = position.get(instruction); - assertEquals(dummyValue3, value); - }); - } -} diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/ValuePositionTest1.java --- a/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/ValuePositionTest1.java Tue Apr 14 17:53:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2014, 2015, 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.asm.*; - -public class ValuePositionTest1 { - - private static class NestedCompositeValue extends CompositeValue { - public static final CompositeValueClass TYPE = CompositeValueClass.create(NestedCompositeValue.class); - - private static final long serialVersionUID = -8804214200173503527L; - @Component({REG, OperandFlag.ILLEGAL}) protected Value value; - - public NestedCompositeValue(Value value) { - super(TYPE, LIRKind.Illegal); - this.value = value; - } - - } - - private static class DummyValue extends AbstractValue { - - private static final long serialVersionUID = -645435039553382737L; - private final int id; - private static int counter = 1; - - 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; - } - } - - private static final class TestOp extends LIRInstruction { - public static final LIRInstructionClass TYPE = LIRInstructionClass.create(TestOp.class); - - @Use({COMPOSITE}) protected NestedCompositeValue compValue; - - public TestOp(NestedCompositeValue compValue) { - super(TYPE); - this.compValue = compValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb) { - fail("should not reach!"); - } - - } - - private static LIRInstruction createNestedOp(Value value, int nestingLevel) { - NestedCompositeValue compValue = new NestedCompositeValue(value); - for (int i = 0; i < nestingLevel; i++) { - compValue = new NestedCompositeValue(compValue); - } - TestOp op = new TestOp(compValue); - return op; - } - - @Test - public void nestedTest0() { - DummyValue dummyValue = new DummyValue(); - LIRInstruction op = createNestedOp(dummyValue, 0); - - List positions = new ArrayList<>(); - - op.forEachInputPos((instruction, position) -> positions.add(position)); - - assertEquals(1, positions.size()); - assertEquals(dummyValue, positions.get(0).get(op)); - } - - @Test - public void nestedTest1() { - DummyValue dummyValue = new DummyValue(); - LIRInstruction op = createNestedOp(dummyValue, 1); - - List positions = new ArrayList<>(); - - op.forEachInputPos((instruction, position) -> positions.add(position)); - - assertEquals(1, positions.size()); - assertEquals(dummyValue, positions.get(0).get(op)); - } - - @Test - public void nestedTest2() { - DummyValue dummyValue = new DummyValue(); - LIRInstruction op = createNestedOp(dummyValue, 2); - - List positions = new ArrayList<>(); - - op.forEachInputPos((instruction, position) -> positions.add(position)); - - assertEquals(1, positions.size()); - assertEquals(dummyValue, positions.get(0).get(op)); - } - -} diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/ValuePositionTest2.java --- a/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/ValuePositionTest2.java Tue Apr 14 17:53:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2014, 2015, 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.asm.*; - -public class ValuePositionTest2 { - - private static class NestedCompositeValue extends CompositeValue { - public static final CompositeValueClass TYPE = CompositeValueClass.create(NestedCompositeValue.class); - - private static final long serialVersionUID = -2243948303328857965L; - @Component({REG, OperandFlag.ILLEGAL}) protected Value value1; - @Component({REG, OperandFlag.ILLEGAL}) protected Value value2; - - public NestedCompositeValue(Value value1, Value value2) { - super(TYPE, LIRKind.Illegal); - this.value1 = value1; - this.value2 = value2; - } - - } - - private static class DummyValue extends AbstractValue { - - 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; - } - } - - private static class TestOp extends LIRInstruction { - public static final LIRInstructionClass TYPE = LIRInstructionClass.create(TestOp.class); - - @Use({COMPOSITE}) protected NestedCompositeValue compValue; - - public TestOp(NestedCompositeValue compValue) { - super(TYPE); - this.compValue = compValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb) { - fail("should not reach!"); - } - - } - - @Test - public void testSetGet() { - DummyValue dummyValue0 = new DummyValue(); - DummyValue dummyValue1 = new DummyValue(); - DummyValue dummyValue2 = new DummyValue(); - DummyValue dummyValue3 = new DummyValue(); - - NestedCompositeValue compValue0 = new NestedCompositeValue(dummyValue0, dummyValue1); - NestedCompositeValue compValue1 = new NestedCompositeValue(compValue0, dummyValue2); - NestedCompositeValue compValue2 = new NestedCompositeValue(dummyValue3, compValue1); - - LIRInstruction op = new TestOp(compValue2); - List positions = new ArrayList<>(); - - op.forEachInputPos((instruction, position) -> positions.add(position)); - - assertEquals(4, positions.size()); - - // replace values - List replValues = new ArrayList<>(); - for (ValuePosition pos : positions) { - Value v = new DummyValue(); - replValues.add(v); - pos.set(op, v); - - } - - // check replaced values - Iterator it = replValues.iterator(); - for (ValuePosition pos : positions) { - Value v = pos.get(op); - assertEquals(it.next(), v); - } - assertFalse(it.hasNext()); - } - -} diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/ValuePositionTest3.java --- a/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/ValuePositionTest3.java Tue Apr 14 17:53:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2014, 2015, 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 { - public static final CompositeValueClass TYPE = CompositeValueClass.create(TestAddressValue.class); - - 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(TYPE, 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 { - public static final LIRInstructionClass TYPE = LIRInstructionClass.create(TestOp.class); - - @Use({COMPOSITE}) protected Value value; - - public TestOp(Value value) { - super(TYPE); - 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> positionMap = new HashMap<>(); - HashMap> 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 flags) { - normalMap.put(value, flags); - } - }); - - assertEquals(normalMap.size(), positionMap.size()); - assertTrue(normalMap.keySet().containsAll(positionMap.keySet())); - normalMap.keySet().forEach(key -> { - EnumSet normal = normalMap.get(key); - EnumSet position = positionMap.get(key); - assertTrue(normal.containsAll(position)); - assertTrue(position.containsAll(normal)); - }); - } -} diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java Tue Apr 14 17:53:28 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java Tue Apr 07 12:09:46 2015 -0700 @@ -59,10 +59,6 @@ return valueClass.forEachComponent(inst, this, mode, proc); } - final void forEachComponent(LIRInstruction inst, OperandMode mode, ValuePositionProcedure proc, ValuePosition outerPosition) { - valueClass.forEachComponent(inst, this, mode, proc, outerPosition); - } - @Override public String toString() { return valueClass.toString(this); diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java Tue Apr 14 17:53:28 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java Tue Apr 07 12:09:46 2015 -0700 @@ -92,10 +92,6 @@ return super.forEachComponent(inst, obj, values, mode, proc); } - final void forEachComponent(LIRInstruction inst, CompositeValue obj, OperandMode mode, ValuePositionProcedure proc, ValuePosition outerPosition) { - forEach(inst, obj, values, mode, proc, outerPosition); - } - public String toString(CompositeValue obj) { StringBuilder result = new StringBuilder(); diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Tue Apr 14 17:53:28 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Tue Apr 07 12:09:46 2015 -0700 @@ -211,23 +211,6 @@ return false; } - // ValuePositionProcedures - public final void forEachInputPos(ValuePositionProcedure proc) { - instructionClass.forEachUsePos(this, proc); - } - - public final void forEachAlivePos(ValuePositionProcedure proc) { - instructionClass.forEachAlivePos(this, proc); - } - - public final void forEachTempPos(ValuePositionProcedure proc) { - instructionClass.forEachTempPos(this, proc); - } - - public final void forEachOutputPos(ValuePositionProcedure proc) { - instructionClass.forEachDefPos(this, proc); - } - // InstructionValueProcedures public final void forEachInput(InstructionValueProcedure proc) { instructionClass.forEachUse(this, proc); diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java Tue Apr 14 17:53:28 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java Tue Apr 07 12:09:46 2015 -0700 @@ -205,22 +205,6 @@ return false; } - final void forEachUsePos(LIRInstruction obj, ValuePositionProcedure proc) { - forEach(obj, obj, uses, OperandMode.USE, proc, ValuePosition.ROOT_VALUE_POSITION); - } - - final void forEachAlivePos(LIRInstruction obj, ValuePositionProcedure proc) { - forEach(obj, obj, alives, OperandMode.ALIVE, proc, ValuePosition.ROOT_VALUE_POSITION); - } - - final void forEachTempPos(LIRInstruction obj, ValuePositionProcedure proc) { - forEach(obj, obj, temps, OperandMode.TEMP, proc, ValuePosition.ROOT_VALUE_POSITION); - } - - final void forEachDefPos(LIRInstruction obj, ValuePositionProcedure proc) { - forEach(obj, obj, defs, OperandMode.DEF, proc, ValuePosition.ROOT_VALUE_POSITION); - } - final void forEachUse(LIRInstruction obj, InstructionValueProcedure proc) { forEach(obj, uses, OperandMode.USE, proc); } diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java Tue Apr 14 17:53:28 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java Tue Apr 07 12:09:46 2015 -0700 @@ -284,33 +284,6 @@ return newCompValue != null ? newCompValue : obj; } - protected static void forEach(LIRInstruction inst, Object obj, Values values, OperandMode mode, ValuePositionProcedure proc, ValuePosition outerPosition) { - for (int i = 0; i < values.getCount(); i++) { - assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(values.getFlags(i)); - - if (i < values.getDirectCount()) { - Value value = values.getValue(obj, i); - 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, values, mode, proc, outerPosition, i, j, value); - } - } - } - } - - 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; - composite.forEachComponent(inst, mode, proc, position); - } else { - proc.doValue(inst, position); - } - } - protected void appendValues(StringBuilder sb, Object obj, String start, String end, String startMultiple, String endMultiple, String[] prefix, Fields... fieldsList) { int total = 0; for (Fields fields : fieldsList) { diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePosition.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePosition.java Tue Apr 14 17:53:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ -/* - * 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.OperandFlag; -import com.oracle.graal.lir.LIRIntrospection.Values; - -/** - * 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; - /** - * The {@link ValuePosition} of the containing {@link CompositeValue} if this value is part of a - * {@link CompositeValue}, otherwise {@link #ROOT_VALUE_POSITION}. - */ - private final ValuePosition outerPosition; - - public static final int NO_SUBINDEX = -1; - public static final ValuePosition ROOT_VALUE_POSITION = null; - - 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}. - */ - private boolean isCompositePosition() { - return outerPosition != ROOT_VALUE_POSITION; - } - - /** - * @param inst The instruction this {@linkplain ValuePosition position} belongs to. - * @return The value denoted by this {@linkplain ValuePosition position}. - */ - public Value get(LIRInstruction inst) { - Object obj = inst; - if (isCompositePosition()) { - obj = outerPosition.get(inst); - assert obj instanceof CompositeValue : "The holder of a composite position is not a CompositeValue? " + obj; - } - if (index < values.getDirectCount()) { - return values.getValue(obj, index); - } - return values.getValueArray(obj, 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) { - Object obj = inst; - if (isCompositePosition()) { - CompositeValue compValue = (CompositeValue) outerPosition.get(inst); - CompositeValue newCompValue = compValue.clone(); - outerPosition.set(inst, newCompValue); - obj = newCompValue; - } - if (index < values.getDirectCount()) { - values.setValue(obj, index, value); - } else { - values.getValueArray(obj, index)[subIndex] = value; - } - } - - /** - * @return The flags associated with the value denoted by this {@linkplain ValuePosition - * position}. - */ - public EnumSet getFlags() { - return values.getFlags(index); - } - - @Override - public String toString() { - String str = "(" + index + (subIndex < 0 ? "" : "/" + subIndex) + ")"; - if (isCompositePosition()) { - return outerPosition.toString() + "[" + str + "]"; - } - return str; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + index; - result = prime * result + subIndex; - result = prime * result + ((outerPosition == null) ? 0 : outerPosition.hashCode()); - result = prime * result + ((values == null) ? 0 : values.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ValuePosition other = (ValuePosition) obj; - if (index != other.index) { - return false; - } - if (subIndex != other.subIndex) { - return false; - } - if (outerPosition == null) { - if (other.outerPosition != null) { - return false; - } - } else if (!outerPosition.equals(other.outerPosition)) { - return false; - } - if (values == null) { - if (other.values != null) { - return false; - } - } else if (!values.equals(other.values)) { - return false; - } - return true; - } - -} diff -r da2251d7d3c5 -r a69a7c0e0ccc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePositionProcedure.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValuePositionProcedure.java Tue Apr 14 17:53:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * 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; - -/** - * Iterator for iterating over a list of {@linkplain ValuePosition value positions}. - */ -@FunctionalInterface -public interface ValuePositionProcedure { - - /** - * Iterator method to be overwritten. This version of the iterator does not take additional - * parameters to keep the signature short. - * - * @param instruction The current instruction. - * @param position The position of the value that is iterated. - */ - void doValue(LIRInstruction instruction, ValuePosition position); -}