use of org.graalvm.compiler.nodes.calc.IntegerEqualsNode in project graal by oracle.
the class BranchProbabilityNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
if (!hasUsages()) {
return;
}
if (probability.isConstant()) {
double probabilityValue = probability.asJavaConstant().asDouble();
if (probabilityValue < 0.0) {
throw new GraalError("A negative probability of " + probabilityValue + " is not allowed!");
} else if (probabilityValue > 1.0) {
throw new GraalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!");
} else if (Double.isNaN(probabilityValue)) {
/*
* We allow NaN if the node is in unreachable code that will eventually fall away,
* or else an error will be thrown during lowering since we keep the node around.
*/
return;
}
boolean usageFound = false;
for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) {
assert node.condition() == CanonicalCondition.EQ;
ValueNode other = node.getX();
if (node.getX() == this) {
other = node.getY();
}
if (other.isConstant()) {
double probabilityToSet = probabilityValue;
if (other.asJavaConstant().asInt() == 0) {
probabilityToSet = 1.0 - probabilityToSet;
}
for (IfNode ifNodeUsages : node.usages().filter(IfNode.class)) {
usageFound = true;
ifNodeUsages.setTrueSuccessorProbability(probabilityToSet);
}
if (!usageFound) {
usageFound = node.usages().filter(NodePredicates.isA(FixedGuardNode.class).or(ConditionalNode.class)).isNotEmpty();
}
}
}
if (usageFound) {
ValueNode currentCondition = condition;
replaceAndDelete(currentCondition);
if (tool != null) {
tool.addToWorkList(currentCondition.usages());
}
} else {
if (!isSubstitutionGraph()) {
throw new GraalError("Wrong usage of branch probability injection!");
}
}
}
}
use of org.graalvm.compiler.nodes.calc.IntegerEqualsNode in project graal by oracle.
the class BytecodeParser method genIf.
protected void genIf(ValueNode x, Condition cond, ValueNode y) {
assert x.getStackKind() == y.getStackKind();
assert currentBlock.getSuccessorCount() == 2;
BciBlock trueBlock = currentBlock.getSuccessor(0);
BciBlock falseBlock = currentBlock.getSuccessor(1);
if (trueBlock == falseBlock) {
// The target block is the same independent of the condition.
appendGoto(trueBlock);
return;
}
ValueNode a = x;
ValueNode b = y;
BciBlock trueSuccessor = trueBlock;
BciBlock falseSuccessor = falseBlock;
CanonicalizedCondition canonicalizedCondition = cond.canonicalize();
// Check whether the condition needs to mirror the operands.
if (canonicalizedCondition.mustMirror()) {
a = y;
b = x;
}
if (canonicalizedCondition.mustNegate()) {
trueSuccessor = falseBlock;
falseSuccessor = trueBlock;
}
// Create the logic node for the condition.
LogicNode condition = createLogicNode(canonicalizedCondition.getCanonicalCondition(), a, b);
double probability = -1;
if (condition instanceof IntegerEqualsNode) {
probability = extractInjectedProbability((IntegerEqualsNode) condition);
// the probability coming from here is about the actual condition
}
if (probability == -1) {
probability = getProfileProbability(canonicalizedCondition.mustNegate());
}
probability = clampProbability(probability);
genIf(condition, trueSuccessor, falseSuccessor, probability);
}
use of org.graalvm.compiler.nodes.calc.IntegerEqualsNode in project graal by oracle.
the class WordOperationPlugin method comparisonOp.
private ValueNode comparisonOp(GraphBuilderContext graph, Condition condition, ValueNode left, ValueNode right) {
assert left.getStackKind() == wordKind && right.getStackKind() == wordKind;
CanonicalizedCondition canonical = condition.canonicalize();
ValueNode a = canonical.mustMirror() ? right : left;
ValueNode b = canonical.mustMirror() ? left : right;
CompareNode comparison;
if (canonical.getCanonicalCondition() == CanonicalCondition.EQ) {
comparison = new IntegerEqualsNode(a, b);
} else if (canonical.getCanonicalCondition() == CanonicalCondition.BT) {
comparison = new IntegerBelowNode(a, b);
} else {
assert canonical.getCanonicalCondition() == CanonicalCondition.LT;
comparison = new IntegerLessThanNode(a, b);
}
ConstantNode trueValue = graph.add(forInt(1));
ConstantNode falseValue = graph.add(forInt(0));
if (canonical.mustNegate()) {
ConstantNode temp = trueValue;
trueValue = falseValue;
falseValue = temp;
}
return graph.add(new ConditionalNode(graph.add(comparison), trueValue, falseValue));
}
use of org.graalvm.compiler.nodes.calc.IntegerEqualsNode in project graal by oracle.
the class CInterfaceInvocationPlugin method adaptPrimitiveType.
static ValueNode adaptPrimitiveType(StructuredGraph graph, ValueNode value, JavaKind fromKind, JavaKind toKind, boolean isUnsigned) {
if (fromKind == toKind) {
return value;
}
assert fromKind.isNumericFloat() == toKind.isNumericFloat();
int fromBits = fromKind.getBitCount();
int toBits = toKind.getBitCount();
if (fromBits == toBits) {
return value;
} else if (fromKind.isNumericFloat()) {
FloatConvert op;
if (fromKind == JavaKind.Float && toKind == JavaKind.Double) {
op = FloatConvert.F2D;
} else if (fromKind == JavaKind.Double && toKind == JavaKind.Float) {
op = FloatConvert.D2F;
} else {
throw shouldNotReachHere();
}
return graph.unique(new FloatConvertNode(op, value));
} else if (toKind == JavaKind.Boolean) {
JavaKind computeKind = fromKind == JavaKind.Long ? JavaKind.Long : JavaKind.Int;
LogicNode comparison = graph.unique(new IntegerEqualsNode(adaptPrimitiveType(graph, value, fromKind, computeKind, true), ConstantNode.forIntegerKind(computeKind, 0, graph)));
return graph.unique(new ConditionalNode(comparison, ConstantNode.forBoolean(false, graph), ConstantNode.forBoolean(true, graph)));
} else if (fromBits > toBits) {
return graph.unique(new NarrowNode(value, toBits));
} else if (isUnsigned) {
return graph.unique(new ZeroExtendNode(value, toBits));
} else {
return graph.unique(new SignExtendNode(value, toBits));
}
}
use of org.graalvm.compiler.nodes.calc.IntegerEqualsNode in project graal by oracle.
the class ShortCircuitOrNodeTest method registerInvocationPlugins.
@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
Registration r = new Registration(invocationPlugins, ShortCircuitOrNodeTest.class);
r.register2("shortCircuitOr", boolean.class, boolean.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode b1, ValueNode b2) {
LogicNode x = b.add(new IntegerEqualsNode(b1, b.add(ConstantNode.forInt(1))));
LogicNode y = b.add(new IntegerEqualsNode(b2, b.add(ConstantNode.forInt(1))));
ShortCircuitOrNode compare = b.add(new ShortCircuitOrNode(x, false, y, false, 0.5));
b.addPush(JavaKind.Boolean, new ConditionalNode(compare, b.add(ConstantNode.forBoolean(true)), b.add(ConstantNode.forBoolean(false))));
return true;
}
});
super.registerInvocationPlugins(invocationPlugins);
}
Aggregations