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();
}
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);
}
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);
}
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;
}
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;
}
}
}
}
}
Aggregations