use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class StandardGraphBuilderPlugins method registerClassPlugins.
private static void registerClassPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Class.class);
r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode object) {
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), type.get(), object, false));
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
ClassIsAssignableFromNode condition = b.append(new ClassIsAssignableFromNode(type.get(), otherType));
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class CountedLoopInfo method maxTripCountNode.
/**
* Returns a node that computes the maximum trip count of this loop. That is the trip count of
* this loop assuming it is not exited by an other exit than the {@linkplain #getLimitTest()
* count check}.
*
* This count is exact if {@link #isExactTripCount()} returns true.
*
* THIS VALUE SHOULD BE TREATED AS UNSIGNED.
*
* @param assumePositive if true the check that the loop is entered at all will be omitted.
*/
public ValueNode maxTripCountNode(boolean assumePositive) {
StructuredGraph graph = iv.valueNode().graph();
Stamp stamp = iv.valueNode().stamp(NodeView.DEFAULT);
ValueNode max;
ValueNode min;
ValueNode range;
ValueNode absStride;
if (iv.direction() == Direction.Up) {
absStride = iv.strideNode();
range = sub(graph, end, iv.initNode());
max = end;
min = iv.initNode();
} else {
assert iv.direction() == Direction.Down;
absStride = graph.maybeAddOrUnique(NegateNode.create(iv.strideNode(), NodeView.DEFAULT));
range = sub(graph, iv.initNode(), end);
max = iv.initNode();
min = end;
}
ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
if (oneOff) {
range = add(graph, range, one);
}
// round-away-from-zero divison: (range + stride -/+ 1) / stride
ValueNode denominator = add(graph, range, sub(graph, absStride, one));
ValueNode div = unsignedDivBefore(graph, loop.entryPoint(), denominator, absStride);
if (assumePositive) {
return div;
}
ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(max, min)), zero, div));
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class CompareCanonicalizerTest method testIntegerTest.
@Test
public void testIntegerTest() {
for (int i = 1; i <= 4; i++) {
StructuredGraph graph = getCanonicalizedGraph("integerTest" + i);
ReturnNode returnNode = (ReturnNode) graph.start().next();
ConditionalNode conditional = (ConditionalNode) returnNode.result();
IntegerTestNode test = (IntegerTestNode) conditional.condition();
ParameterNode param0 = graph.getParameter(0);
ParameterNode param1 = graph.getParameter(1);
assertTrue((test.getX() == param0 && test.getY() == param1) || (test.getX() == param1 && test.getY() == param0));
}
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode 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.ConditionalNode in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerClassPlugins.
private static void registerClassPlugins(InvocationPlugins plugins) {
/*
* We have our own Java-level implementation of isAssignableFrom() in DynamicHub, so we do
* not need to intrinsifiy that to a Graal node. Therefore, we overwrite and deactivate the
* invocation plugin registered in StandardGraphBuilderPlugins.
*
* TODO we should remove the implementation from DynamicHub to a lowering of
* ClassIsAssignableFromNode. Then we can remove this code.
*/
Registration r = new Registration(plugins, Class.class).setAllowOverwrite(true);
r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
return false;
}
});
r.register2("cast", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
ValueNode toType = receiver.get();
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), toType, object, true));
if (condition.isTautology()) {
b.addPush(JavaKind.Object, object);
} else {
FixedGuardNode fixedGuard = b.add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
b.addPush(JavaKind.Object, DynamicPiNode.create(b.getAssumptions(), b.getConstantReflection(), object, fixedGuard, toType));
}
return true;
}
});
r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
ValueNode type = receiver.get();
LogicNode condition = b.append(InstanceOfDynamicNode.create(null, b.getConstantReflection(), type, object, false));
b.push(JavaKind.Boolean.getStackKind(), b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
}
Aggregations