Search in sources :

Example 46 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class TraceGlobalMoveResolver method resolveMappings.

@SuppressWarnings("try")
private void resolveMappings() {
    try (Indent indent = debug.logAndIndent("resolveMapping")) {
        assert verifyBeforeResolve();
        if (debug.isLogEnabled()) {
            printMapping();
        }
        // This is necessary for detecting cycles in moves.
        for (int i = mappingFrom.size() - 1; i >= 0; i--) {
            Value from = mappingFrom.get(i);
            block(from);
        }
        ArrayList<AllocatableValue> busySpillSlots = null;
        while (mappingFrom.size() > 0) {
            boolean processedInterval = false;
            int spillCandidate = -1;
            for (int i = mappingFrom.size() - 1; i >= 0; i--) {
                Value fromLocation = mappingFrom.get(i);
                AllocatableValue toLocation = mappingTo.get(i);
                if (safeToProcessMove(fromLocation, toLocation)) {
                    // this interval can be processed because target is free
                    LIRInstruction move = insertMove(fromLocation, toLocation);
                    move.setComment(res, "TraceGlobalMoveResolver: resolveMapping");
                    unblock(fromLocation);
                    if (isStackSlotValue(toLocation)) {
                        if (busySpillSlots == null) {
                            busySpillSlots = new ArrayList<>(2);
                        }
                        busySpillSlots.add(toLocation);
                    }
                    mappingFrom.remove(i);
                    mappingFromStack.remove(i);
                    mappingTo.remove(i);
                    processedInterval = true;
                } else if (fromLocation != null) {
                    if (isRegister(fromLocation) && (busySpillSlots == null || !busySpillSlots.contains(mappingFromStack.get(i)))) {
                        // this interval cannot be processed now because target is not free
                        // it starts in a register, so it is a possible candidate for spilling
                        spillCandidate = i;
                    } else if (isStackSlotValue(fromLocation) && spillCandidate == -1) {
                        // fall back to spill a stack slot in case no other candidate is found
                        spillCandidate = i;
                    }
                }
            }
            if (!processedInterval) {
                breakCycle(spillCandidate);
            }
        }
    }
    // check that all intervals have been processed
    assert checkEmpty();
}
Also used : Indent(org.graalvm.compiler.debug.Indent) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) LIRValueUtil.isStackSlotValue(org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue) TraceUtil.isShadowedRegisterValue(org.graalvm.compiler.lir.alloc.trace.TraceUtil.isShadowedRegisterValue) TraceUtil.asShadowedRegisterValue(org.graalvm.compiler.lir.alloc.trace.TraceUtil.asShadowedRegisterValue) ValueUtil.asAllocatableValue(jdk.vm.ci.code.ValueUtil.asAllocatableValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ValueUtil.asAllocatableValue(jdk.vm.ci.code.ValueUtil.asAllocatableValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 47 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class TrivialTraceAllocator method handlePhiOut.

private static void handlePhiOut(LIRInstruction jump, int[] varIn, Value[] locIn) {
    // handle outgoing phi values
    ValueProcedure outputConsumer = new ValueProcedure() {

        @Override
        public Value doValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
            if (isVariable(value)) {
                // since incoming variables are sorted, we can do a binary search
                return locIn[Arrays.binarySearch(varIn, asVariable(value).index)];
            }
            return value;
        }
    };
    // Jumps have only alive values (outgoing phi values)
    jump.forEachAlive(outputConsumer);
}
Also used : ValueProcedure(org.graalvm.compiler.lir.ValueProcedure) EnumSet(java.util.EnumSet) Value(jdk.vm.ci.meta.Value) OperandMode(org.graalvm.compiler.lir.LIRInstruction.OperandMode)

Example 48 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class UseEntry method replaceValue.

private static void replaceValue(LIRInstruction op, Value oldValue, Value newValue) {
    ValueProcedure proc = (value, mode, flags) -> value.identityEquals(oldValue) ? newValue : value;
    op.forEachAlive(proc);
    op.forEachInput(proc);
    op.forEachOutput(proc);
    op.forEachTemp(proc);
    op.forEachState(proc);
}
Also used : ValueProcedure(org.graalvm.compiler.lir.ValueProcedure) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) Value(jdk.vm.ci.meta.Value) ValueProcedure(org.graalvm.compiler.lir.ValueProcedure) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction)

Example 49 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class LIRInstructionClass method forEachRegisterHint.

final Value forEachRegisterHint(LIRInstruction obj, OperandMode mode, InstructionValueProcedure proc) {
    Values hints;
    if (mode == OperandMode.USE) {
        hints = defs;
    } else if (mode == OperandMode.DEF) {
        hints = uses;
    } else {
        return null;
    }
    for (int i = 0; i < hints.getCount(); i++) {
        if (i < hints.getDirectCount()) {
            Value hintValue = hints.getValue(obj, i);
            Value result = proc.doValue(obj, hintValue, null, null);
            if (result != null) {
                return result;
            }
        } else {
            Value[] hintValues = hints.getValueArray(obj, i);
            for (int j = 0; j < hintValues.length; j++) {
                Value hintValue = hintValues[j];
                Value result = proc.doValue(obj, hintValue, null, null);
                if (result != null) {
                    return result;
                }
            }
        }
    }
    return null;
}
Also used : Value(jdk.vm.ci.meta.Value)

Example 50 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class LIRIntrospection method forEach.

protected static void forEach(LIRInstruction inst, Values values, OperandMode mode, InstructionValueProcedure 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);
            Value newValue;
            if (value instanceof CompositeValue) {
                CompositeValue composite = (CompositeValue) value;
                newValue = composite.forEachComponent(inst, mode, proc);
            } else {
                newValue = proc.doValue(inst, value, mode, values.getFlags(i));
            }
            if (!value.identityEquals(newValue)) {
                values.setValue(inst, i, newValue);
            }
        } else {
            Value[] valueArray = values.getValueArray(inst, i);
            for (int j = 0; j < valueArray.length; j++) {
                Value value = valueArray[j];
                Value newValue;
                if (value instanceof CompositeValue) {
                    CompositeValue composite = (CompositeValue) value;
                    newValue = composite.forEachComponent(inst, mode, proc);
                } else {
                    newValue = proc.doValue(inst, value, mode, values.getFlags(i));
                }
                if (!value.identityEquals(newValue)) {
                    valueArray[j] = newValue;
                }
            }
        }
    }
}
Also used : RegisterValue(jdk.vm.ci.code.RegisterValue) Value(jdk.vm.ci.meta.Value)

Aggregations

Value (jdk.vm.ci.meta.Value)151 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)76 RegisterValue (jdk.vm.ci.code.RegisterValue)33 LIRKind (org.graalvm.compiler.core.common.LIRKind)18 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)14 LIRValueUtil.isConstantValue (org.graalvm.compiler.lir.LIRValueUtil.isConstantValue)14 LIRValueUtil.isStackSlotValue (org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue)14 OperandMode (org.graalvm.compiler.lir.LIRInstruction.OperandMode)12 Variable (org.graalvm.compiler.lir.Variable)12 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)11 Indent (org.graalvm.compiler.debug.Indent)11 EnumSet (java.util.EnumSet)10 DebugContext (org.graalvm.compiler.debug.DebugContext)10 GraalError (org.graalvm.compiler.debug.GraalError)10 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)10 BitSet (java.util.BitSet)9 Register (jdk.vm.ci.code.Register)9 ConstantValue (org.graalvm.compiler.lir.ConstantValue)9 SPARCAddressValue (org.graalvm.compiler.lir.sparc.SPARCAddressValue)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)9