use of org.graalvm.compiler.core.common.LIRKind in project graal by oracle.
the class ArithmeticLIRGenerator method emitAddOrSub.
private Variable emitAddOrSub(Value aVal, Value bVal, boolean setFlags, boolean isAdd) {
LIRKind resultKind;
Value a = aVal;
Value b = bVal;
if (isNumericInteger(a.getPlatformKind())) {
LIRKind aKind = a.getValueKind(LIRKind.class);
LIRKind bKind = b.getValueKind(LIRKind.class);
assert a.getPlatformKind() == b.getPlatformKind() : a.getPlatformKind() + " vs. " + b.getPlatformKind();
if (aKind.isUnknownReference()) {
resultKind = aKind;
} else if (bKind.isUnknownReference()) {
resultKind = bKind;
} else if (aKind.isValue() && bKind.isValue()) {
resultKind = aKind;
} else if (aKind.isValue()) {
if (bKind.isDerivedReference()) {
resultKind = bKind;
} else {
AllocatableValue allocatable = getLIRGen().asAllocatable(b);
resultKind = bKind.makeDerivedReference(allocatable);
b = allocatable;
}
} else if (bKind.isValue()) {
if (aKind.isDerivedReference()) {
resultKind = aKind;
} else {
AllocatableValue allocatable = getLIRGen().asAllocatable(a);
resultKind = aKind.makeDerivedReference(allocatable);
a = allocatable;
}
} else {
resultKind = aKind.makeUnknownReference();
}
} else {
resultKind = LIRKind.combine(a, b);
}
return isAdd ? emitAdd(resultKind, a, b, setFlags) : emitSub(resultKind, a, b, setFlags);
}
use of org.graalvm.compiler.core.common.LIRKind in project graal by oracle.
the class NodeLIRBuilder method emitOverflowCheckBranch.
@Override
public void emitOverflowCheckBranch(AbstractBeginNode overflowSuccessor, AbstractBeginNode next, Stamp stamp, double probability) {
LIRKind cmpKind = getLIRGeneratorTool().getLIRKind(stamp);
gen.emitOverflowCheckBranch(getLIRBlock(overflowSuccessor), getLIRBlock(next), cmpKind, probability);
}
use of org.graalvm.compiler.core.common.LIRKind in project graal by oracle.
the class NodeLIRBuilder method emitNullCheckBranch.
private void emitNullCheckBranch(IsNullNode node, LabelRef trueSuccessor, LabelRef falseSuccessor, double trueSuccessorProbability) {
LIRKind kind = gen.getLIRKind(node.getValue().stamp(NodeView.DEFAULT));
Value nullValue = gen.emitConstant(kind, JavaConstant.NULL_POINTER);
gen.emitCompareBranch(kind.getPlatformKind(), operand(node.getValue()), nullValue, Condition.EQ, false, trueSuccessor, falseSuccessor, trueSuccessorProbability);
}
use of org.graalvm.compiler.core.common.LIRKind in project graal by oracle.
the class NodeLIRBuilder method emitConditional.
public Variable emitConditional(LogicNode node, Value trueValue, Value falseValue) {
if (node instanceof IsNullNode) {
IsNullNode isNullNode = (IsNullNode) node;
LIRKind kind = gen.getLIRKind(isNullNode.getValue().stamp(NodeView.DEFAULT));
Value nullValue = gen.emitConstant(kind, JavaConstant.NULL_POINTER);
return gen.emitConditionalMove(kind.getPlatformKind(), operand(isNullNode.getValue()), nullValue, Condition.EQ, false, trueValue, falseValue);
} else if (node instanceof CompareNode) {
CompareNode compare = (CompareNode) node;
PlatformKind kind = gen.getLIRKind(compare.getX().stamp(NodeView.DEFAULT)).getPlatformKind();
return gen.emitConditionalMove(kind, operand(compare.getX()), operand(compare.getY()), compare.condition().asCondition(), compare.unorderedIsTrue(), trueValue, falseValue);
} else if (node instanceof LogicConstantNode) {
return gen.emitMove(((LogicConstantNode) node).getValue() ? trueValue : falseValue);
} else if (node instanceof IntegerTestNode) {
IntegerTestNode test = (IntegerTestNode) node;
return gen.emitIntegerTestMove(operand(test.getX()), operand(test.getY()), trueValue, falseValue);
} else {
throw GraalError.unimplemented(node.toString());
}
}
use of org.graalvm.compiler.core.common.LIRKind in project graal by oracle.
the class NodeLIRBuilder method emitSwitch.
/**
* This method tries to create a switch implementation that is optimal for the given switch. It
* will either generate a sequential if/then/else cascade, a set of range tests or a table
* switch.
*
* If the given switch does not contain int keys, it will always create a sequential
* implementation.
*/
@Override
public void emitSwitch(SwitchNode x) {
assert x.defaultSuccessor() != null;
LabelRef defaultTarget = getLIRBlock(x.defaultSuccessor());
int keyCount = x.keyCount();
if (keyCount == 0) {
gen.emitJump(defaultTarget);
} else {
Variable value = gen.load(operand(x.value()));
if (keyCount == 1) {
assert defaultTarget != null;
double probability = x.probability(x.keySuccessor(0));
LIRKind kind = gen.getLIRKind(x.value().stamp(NodeView.DEFAULT));
Value key = gen.emitConstant(kind, x.keyAt(0));
gen.emitCompareBranch(kind.getPlatformKind(), gen.load(operand(x.value())), key, Condition.EQ, false, getLIRBlock(x.keySuccessor(0)), defaultTarget, probability);
} else if (x instanceof IntegerSwitchNode && x.isSorted()) {
IntegerSwitchNode intSwitch = (IntegerSwitchNode) x;
LabelRef[] keyTargets = new LabelRef[keyCount];
JavaConstant[] keyConstants = new JavaConstant[keyCount];
double[] keyProbabilities = new double[keyCount];
JavaKind keyKind = intSwitch.keyAt(0).getJavaKind();
for (int i = 0; i < keyCount; i++) {
keyTargets[i] = getLIRBlock(intSwitch.keySuccessor(i));
keyConstants[i] = intSwitch.keyAt(i);
keyProbabilities[i] = intSwitch.keyProbability(i);
assert keyConstants[i].getJavaKind() == keyKind;
}
gen.emitStrategySwitch(keyConstants, keyProbabilities, keyTargets, defaultTarget, value);
} else {
// keyKind != JavaKind.Int || !x.isSorted()
LabelRef[] keyTargets = new LabelRef[keyCount];
Constant[] keyConstants = new Constant[keyCount];
double[] keyProbabilities = new double[keyCount];
for (int i = 0; i < keyCount; i++) {
keyTargets[i] = getLIRBlock(x.keySuccessor(i));
keyConstants[i] = x.keyAt(i);
keyProbabilities[i] = x.keyProbability(i);
}
// hopefully only a few entries
gen.emitStrategySwitch(new SwitchStrategy.SequentialStrategy(keyProbabilities, keyConstants), value, keyTargets, defaultTarget);
}
}
}
Aggregations