Search in sources :

Example 1 with NarrowNode

use of org.graalvm.compiler.nodes.calc.NarrowNode in project graal by oracle.

the class StandardGraphBuilderPlugins method registerCharacterPlugins.

private static void registerCharacterPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Character.class);
    r.register1("reverseBytes", char.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            // return (char) (Integer.reverse(i) >> 16);
            ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
            RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
            ZeroExtendNode charCast = b.add(new ZeroExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
            b.push(JavaKind.Char, b.append(charCast.canonical(null)));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ReverseBytesNode(org.graalvm.compiler.replacements.nodes.ReverseBytesNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with NarrowNode

use of org.graalvm.compiler.nodes.calc.NarrowNode 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 3 with NarrowNode

use of org.graalvm.compiler.nodes.calc.NarrowNode in project graal by oracle.

the class StandardGraphBuilderPlugins method registerShortPlugins.

private static void registerShortPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Short.class);
    r.register1("reverseBytes", short.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            // return (short) (Integer.reverse(i) >> 16);
            ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
            RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
            SignExtendNode charCast = b.add(new SignExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
            b.push(JavaKind.Short, b.append(charCast.canonical(null)));
            return true;
        }
    });
}
Also used : SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ReverseBytesNode(org.graalvm.compiler.replacements.nodes.ReverseBytesNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 4 with NarrowNode

use of org.graalvm.compiler.nodes.calc.NarrowNode in project graal by oracle.

the class CEntryPointCallStubMethod method inlinePrologueAndEpilogue.

private static void inlinePrologueAndEpilogue(SubstrateGraphKit kit, InvokeNode prologueInvoke, InvokeNode epilogueInvoke, JavaKind returnKind) {
    assert (prologueInvoke != null) == (epilogueInvoke != null);
    if (prologueInvoke != null) {
        kit.inline(prologueInvoke);
        NodeIterable<CEntryPointPrologueBailoutNode> bailoutNodes = kit.getGraph().getNodes().filter(CEntryPointPrologueBailoutNode.class);
        for (CEntryPointPrologueBailoutNode node : bailoutNodes) {
            ValueNode result = node.getResult();
            switch(returnKind) {
                case Float:
                    assert result.getStackKind().isNumericFloat();
                    result = kit.unique(new FloatConvertNode(FloatConvert.D2F, result));
                    break;
                case Byte:
                case Char:
                case Short:
                case Int:
                    assert result.getStackKind().isNumericInteger();
                    result = kit.unique(new NarrowNode(result, returnKind.getBitCount()));
                    break;
                default:
                    // no conversion necessary
                    break;
            }
            ReturnNode returnNode = kit.add(new ReturnNode(result));
            node.replaceAndDelete(returnNode);
        }
        if (epilogueInvoke.isAlive()) {
            kit.inline(epilogueInvoke);
        }
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CEntryPointPrologueBailoutNode(com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode)

Aggregations

NarrowNode (org.graalvm.compiler.nodes.calc.NarrowNode)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 FloatConvertNode (org.graalvm.compiler.nodes.calc.FloatConvertNode)2 RightShiftNode (org.graalvm.compiler.nodes.calc.RightShiftNode)2 SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)2 ZeroExtendNode (org.graalvm.compiler.nodes.calc.ZeroExtendNode)2 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)2 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)2 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)2 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)2 ReverseBytesNode (org.graalvm.compiler.replacements.nodes.ReverseBytesNode)2 CEntryPointPrologueBailoutNode (com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 FloatConvert (org.graalvm.compiler.core.common.calc.FloatConvert)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)1 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)1 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)1