# HG changeset patch # User Tom Rodriguez # Date 1429036608 25200 # Node ID 1af76d1979495bd9a2581fe2ace942a36099283b # Parent cb406df0ecc3a8764e0a13e203794f15bcd65217 Specialize LIRInstruction visit paths a little diff -r cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64AddressValue.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64AddressValue.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64AddressValue.java Tue Apr 14 11:36:48 2015 -0700 @@ -68,6 +68,12 @@ return this; } + @Override + protected void forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc) { + proc.visitValue(inst, base, mode, flags); + proc.visitValue(inst, index, mode, flags); + } + private static Register toRegister(AllocatableValue value) { if (value.equals(Value.ILLEGAL)) { return Register.None; diff -r cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCAddressValue.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCAddressValue.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCAddressValue.java Tue Apr 14 11:36:48 2015 -0700 @@ -65,6 +65,12 @@ return this; } + @Override + protected void forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc) { + proc.visitValue(inst, base, mode, flags); + proc.visitValue(inst, index, mode, flags); + } + private static Register toRegister(AllocatableValue value) { if (isIllegal(value)) { return Register.None; diff -r cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest1.java --- a/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest1.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir.test/src/com/oracle/graal/lir/test/CompositeValueReplacementTest1.java Tue Apr 14 11:36:48 2015 -0700 @@ -61,6 +61,11 @@ } return this; } + + @Override + protected void forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc) { + proc.visitValue(inst, value, mode, flags); + } } private static class DummyValue extends AbstractValue { diff -r cb406df0ecc3 -r 1af76d197949 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 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java Tue Apr 14 11:36:48 2015 -0700 @@ -91,6 +91,8 @@ return newValues != null ? newValues : values; } + protected abstract void forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc); + @Override public String toString() { return CompositeValueClass.format(this); diff -r cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueConsumer.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueConsumer.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueConsumer.java Tue Apr 14 11:36:48 2015 -0700 @@ -29,10 +29,11 @@ import com.oracle.graal.lir.LIRInstruction.OperandMode; /** - * Non-modifying version of {@link InstructionValueProcedure}. + * Functional interface for iterating over a list of values without modifying them. See + * {@link InstructionValueProcedure} for a version that can modify values. */ @FunctionalInterface -public interface InstructionValueConsumer extends InstructionValueProcedure { +public interface InstructionValueConsumer { /** * Iterator method to be overwritten. @@ -43,9 +44,4 @@ * @param flags A set of flags for the value. */ void visitValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet flags); - - default Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet flags) { - visitValue(instruction, value, mode, flags); - return value; - } } diff -r cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InstructionValueProcedure.java Tue Apr 14 11:36:48 2015 -0700 @@ -29,7 +29,8 @@ import com.oracle.graal.lir.LIRInstruction.OperandMode; /** - * Functional interface for iterating over a list of values. + * Functional interface for iterating over a list of values, possibly returning a value to replace + * the old value. */ @FunctionalInterface public interface InstructionValueProcedure { diff -r cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRFrameState.java Tue Apr 14 11:36:48 2015 -0700 @@ -75,6 +75,22 @@ } /** + * Iterates the frame state and calls the {@link InstructionValueProcedure} for every variable. + * + * @param proc The procedure called for variables. + */ + public void forEachState(LIRInstruction inst, InstructionValueConsumer proc) { + for (BytecodeFrame cur = topFrame; cur != null; cur = cur.caller()) { + processValues(inst, cur.values, proc); + } + if (virtualObjects != null) { + for (VirtualObject obj : virtualObjects) { + processValues(inst, obj.getValues(), proc); + } + } + } + + /** * We filter out constant and illegal values ourself before calling the procedure, so * {@link OperandFlag#CONST} and {@link OperandFlag#ILLEGAL} need not be set. */ @@ -83,29 +99,51 @@ protected void processValues(LIRInstruction inst, Value[] values, InstructionValueProcedure 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) { - if (value instanceof StackLockValue) { - StackLockValue monitor = (StackLockValue) value; - Value owner = monitor.getOwner(); - if (owner instanceof AllocatableValue) { - monitor.setOwner(proc.doValue(inst, owner, OperandMode.ALIVE, STATE_FLAGS)); + if (isIllegal(value)) { + continue; } - Value slot = monitor.getSlot(); - if (isVirtualStackSlot(slot)) { - monitor.setSlot(asStackSlotValue(proc.doValue(inst, slot, OperandMode.ALIVE, STATE_FLAGS))); - } - } else { - if (!isIllegal(value) && value instanceof AllocatableValue) { - return proc.doValue(inst, value, OperandMode.ALIVE, STATE_FLAGS); + if (value instanceof AllocatableValue) { + Value result = proc.doValue(inst, value, OperandMode.ALIVE, STATE_FLAGS); + if (!value.identityEquals(result)) { + values[i] = result; + } + } else if (value instanceof StackLockValue) { + StackLockValue monitor = (StackLockValue) value; + Value owner = monitor.getOwner(); + if (owner instanceof AllocatableValue) { + monitor.setOwner(proc.doValue(inst, owner, OperandMode.ALIVE, STATE_FLAGS)); + } + Value slot = monitor.getSlot(); + if (isVirtualStackSlot(slot)) { + monitor.setSlot(asStackSlotValue(proc.doValue(inst, slot, OperandMode.ALIVE, STATE_FLAGS))); + } } else { assert unprocessed(value); } } - return value; + } + + protected void processValues(LIRInstruction inst, Value[] values, InstructionValueConsumer proc) { + for (int i = 0; i < values.length; i++) { + Value value = values[i]; + if (isIllegal(value)) { + continue; + } else if (value instanceof AllocatableValue) { + proc.visitValue(inst, value, OperandMode.ALIVE, STATE_FLAGS); + } else if (value instanceof StackLockValue) { + StackLockValue monitor = (StackLockValue) value; + Value owner = monitor.getOwner(); + if (owner instanceof AllocatableValue) { + proc.visitValue(inst, owner, OperandMode.ALIVE, STATE_FLAGS); + } + Value slot = monitor.getSlot(); + if (isVirtualStackSlot(slot)) { + proc.visitValue(inst, slot, OperandMode.ALIVE, STATE_FLAGS); + } + } else { + assert unprocessed(value); + } + } } private boolean unprocessed(Value value) { diff -r cb406df0ecc3 -r 1af76d197949 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 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java Tue Apr 14 11:36:48 2015 -0700 @@ -221,6 +221,22 @@ forEach(obj, defs, OperandMode.DEF, proc); } + final void forEachUse(LIRInstruction obj, InstructionValueConsumer proc) { + forEach(obj, uses, OperandMode.USE, proc); + } + + final void forEachAlive(LIRInstruction obj, InstructionValueConsumer proc) { + forEach(obj, alives, OperandMode.ALIVE, proc); + } + + final void forEachTemp(LIRInstruction obj, InstructionValueConsumer proc) { + forEach(obj, temps, OperandMode.TEMP, proc); + } + + final void forEachDef(LIRInstruction obj, InstructionValueConsumer proc) { + forEach(obj, defs, OperandMode.DEF, proc); + } + final void forEachState(LIRInstruction obj, InstructionValueProcedure proc) { for (int i = 0; i < states.getCount(); i++) { LIRFrameState state = (LIRFrameState) states.getObject(obj, i); @@ -230,6 +246,15 @@ } } + final void forEachState(LIRInstruction obj, InstructionValueConsumer proc) { + for (int i = 0; i < states.getCount(); i++) { + LIRFrameState state = (LIRFrameState) states.getObject(obj, i); + if (state != null) { + state.forEachState(obj, proc); + } + } + } + final void forEachState(LIRInstruction obj, InstructionStateProcedure proc) { for (int i = 0; i < states.getCount(); i++) { LIRFrameState state = (LIRFrameState) states.getObject(obj, i); diff -r cb406df0ecc3 -r 1af76d197949 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 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java Tue Apr 14 11:36:48 2015 -0700 @@ -235,6 +235,33 @@ } } + protected static void forEach(LIRInstruction inst, Values values, OperandMode mode, InstructionValueConsumer proc) { + 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(inst, i); + if (value instanceof CompositeValue) { + CompositeValue composite = (CompositeValue) value; + composite.forEachComponent(inst, mode, proc); + } else { + proc.visitValue(inst, value, mode, values.getFlags(i)); + } + } else { + Value[] valueArray = values.getValueArray(inst, i); + for (int j = 0; j < valueArray.length; j++) { + Value value = valueArray[j]; + if (value instanceof CompositeValue) { + CompositeValue composite = (CompositeValue) value; + composite.forEachComponent(inst, mode, proc); + } else { + proc.visitValue(inst, value, mode, values.getFlags(i)); + } + } + } + } + } + protected static 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 cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueConsumer.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueConsumer.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ValueConsumer.java Tue Apr 14 11:36:48 2015 -0700 @@ -32,7 +32,7 @@ * Non-modifying version of {@link ValueProcedure}. */ @FunctionalInterface -public interface ValueConsumer extends InstructionValueProcedure { +public interface ValueConsumer extends InstructionValueConsumer { /** * Iterator method to be overwritten. @@ -43,8 +43,7 @@ */ void visitValue(Value value, OperandMode mode, EnumSet flags); - default Value doValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet flags) { + default void visitValue(LIRInstruction instruction, Value value, OperandMode mode, EnumSet flags) { visitValue(value, mode, flags); - return value; } } diff -r cb406df0ecc3 -r 1af76d197949 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/constopt/ConstantLoadOptimization.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/constopt/ConstantLoadOptimization.java Tue Apr 14 11:36:42 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/constopt/ConstantLoadOptimization.java Tue Apr 14 11:36:48 2015 -0700 @@ -214,8 +214,8 @@ // set instruction id to the index in the lir instruction list inst.setId(opId++); inst.visitEachOutput(loadConsumer); - inst.forEachInput(useConsumer); - inst.forEachAlive(useConsumer); + inst.visitEachInput(useConsumer); + inst.visitEachAlive(useConsumer); } }