diff graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest1.java @ 20973:cb406df0ecc3

Visit CompositeValues manually
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 14 Apr 2015 11:36:42 -0700
parents 8fc336a04d77
children 1af76d197949
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest1.java	Tue Apr 07 12:09:46 2015 -0700
+++ b/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest1.java	Tue Apr 14 11:36:42 2015 -0700
@@ -25,11 +25,14 @@
 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.*;
 
 /**
@@ -38,17 +41,26 @@
  */
 public class CompositeValueReplacementTest1 {
 
-    private static class NestedCompositeValue extends CompositeValue {
-        public static final CompositeValueClass<NestedCompositeValue> TYPE = CompositeValueClass.create(NestedCompositeValue.class);
+    private static class TestCompositeValue extends CompositeValue {
 
         private static final long serialVersionUID = -8804214200173503527L;
         @Component({REG, OperandFlag.ILLEGAL}) protected Value value;
 
-        public NestedCompositeValue(Value value) {
-            super(TYPE, LIRKind.Illegal);
+        public TestCompositeValue(Value value) {
+            super(LIRKind.Illegal);
             this.value = value;
         }
 
+        private static final EnumSet<OperandFlag> flags = EnumSet.of(OperandFlag.REG, OperandFlag.ILLEGAL);
+
+        @Override
+        public CompositeValue forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueProcedure proc) {
+            Value newValue = proc.doValue(inst, value, mode, flags);
+            if (!value.identityEquals(newValue)) {
+                return new TestCompositeValue(newValue);
+            }
+            return this;
+        }
     }
 
     private static class DummyValue extends AbstractValue {
@@ -98,9 +110,9 @@
     private static final class TestOp extends LIRInstruction {
         public static final LIRInstructionClass<TestOp> TYPE = LIRInstructionClass.create(TestOp.class);
 
-        @Use({COMPOSITE}) protected NestedCompositeValue compValue;
+        @Use({COMPOSITE}) protected TestCompositeValue compValue;
 
-        public TestOp(NestedCompositeValue compValue) {
+        public TestOp(TestCompositeValue compValue) {
             super(TYPE);
             this.compValue = compValue;
         }
@@ -112,43 +124,12 @@
 
     }
 
-    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.forEachInput((instruction, value, mode, flags) -> {
-            assertEquals(dummyValue1, value);
-            return dummyValue2;
-        });
-
-        op2.forEachInput((instruction, value, mode, flags) -> {
-            assertEquals(dummyValue1, value);
-            return dummyValue3;
-        });
-
-        op1.visitEachInput((instruction, value, mode, flags) -> assertEquals(dummyValue2, value));
-        op2.visitEachInput((instruction, value, mode, flags) -> assertEquals(dummyValue3, value));
-    }
-
-    @Test
-    public void replaceCompValueTest1() {
-        DummyValue dummyValue1 = new DummyValue();
-        DummyValue dummyValue2 = new DummyValue();
-        DummyValue dummyValue3 = new DummyValue();
-        NestedCompositeValue compValue1 = createNestedCompValue(dummyValue1, 1);
+        TestCompositeValue compValue1 = new TestCompositeValue(dummyValue1);
         LIRInstruction op1 = new TestOp(compValue1);
         LIRInstruction op2 = new TestOp(compValue1);