use of org.graalvm.compiler.nodes.calc.ConditionalNode 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.ConditionalNode 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);
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class DefaultJavaLoweringProvider method performBooleanCoercionIfNecessary.
private static ValueNode performBooleanCoercionIfNecessary(ValueNode readValue, JavaKind readKind) {
if (readKind == JavaKind.Boolean) {
StructuredGraph graph = readValue.graph();
IntegerEqualsNode eq = graph.addOrUnique(new IntegerEqualsNode(readValue, ConstantNode.forInt(0, graph)));
return graph.addOrUnique(new ConditionalNode(eq, ConstantNode.forBoolean(false, graph), ConstantNode.forBoolean(true, graph)));
}
return readValue;
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class InstanceOfSnippetsTemplates method createReplacer.
/**
* Gets the specific replacer object used to replace the usage of an instanceof node with the
* result of an instantiated instanceof snippet.
*/
protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instantiation instantiation, Node usage, final StructuredGraph graph) {
InstanceOfUsageReplacer replacer;
if (!canMaterialize(usage)) {
ValueNode trueValue = ConstantNode.forInt(1, graph);
ValueNode falseValue = ConstantNode.forInt(0, graph);
if (instantiation.isInitialized() && (trueValue != instantiation.trueValue || falseValue != instantiation.falseValue)) {
/*
* This code doesn't really care what values are used so adopt the values from the
* previous instantiation.
*/
trueValue = instantiation.trueValue;
falseValue = instantiation.falseValue;
}
replacer = new NonMaterializationUsageReplacer(instantiation, trueValue, falseValue, instanceOf, usage);
} else {
assert usage instanceof ConditionalNode : "unexpected usage of " + instanceOf + ": " + usage;
ConditionalNode c = (ConditionalNode) usage;
replacer = new MaterializationUsageReplacer(instantiation, c.trueValue(), c.falseValue(), instanceOf, c);
}
return replacer;
}
use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.
the class VirtualFrameIsNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode tagAlias = tool.getAlias(frame.virtualFrameTagArray);
if (tagAlias instanceof VirtualObjectNode) {
VirtualObjectNode tagVirtual = (VirtualObjectNode) tagAlias;
if (frameSlotIndex < tagVirtual.entryCount()) {
ValueNode actualTag = tool.getEntry(tagVirtual, frameSlotIndex);
if (actualTag.isConstant()) {
tool.replaceWith(getConstant(actualTag.asJavaConstant().asInt() == accessTag ? 1 : 0));
} else {
LogicNode comparison = new IntegerEqualsNode(actualTag, getConstant(accessTag));
tool.addNode(comparison);
ConditionalNode result = new ConditionalNode(comparison, getConstant(1), getConstant(0));
tool.addNode(result);
tool.replaceWith(result);
}
return;
}
}
/*
* We could "virtualize" to a UnsafeLoadNode here that remains a memory access. But it is
* simpler, and consistent with the get and set intrinsification, to deoptimize.
*/
insertDeoptimization(tool);
}
Aggregations