Search in sources :

Example 6 with ConditionalNode

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));
    }
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) LogicNode(org.graalvm.compiler.nodes.LogicNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 7 with ConditionalNode

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);
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ShortCircuitOrNode(org.graalvm.compiler.nodes.ShortCircuitOrNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 8 with ConditionalNode

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;
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode)

Example 9 with ConditionalNode

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;
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 10 with ConditionalNode

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);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Aggregations

ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)16 ValueNode (org.graalvm.compiler.nodes.ValueNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)6 IntegerLessThanNode (org.graalvm.compiler.nodes.calc.IntegerLessThanNode)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)3 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)3 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)2 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)2 Test (org.junit.Test)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 CanonicalizedCondition (org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition)1 FloatConvert (org.graalvm.compiler.core.common.calc.FloatConvert)1