Search in sources :

Example 1 with IntegerMulExactNode

use of org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulExactNode in project graal by oracle.

the class StandardGraphBuilderPlugins method registerMathPlugins.

private static void registerMathPlugins(InvocationPlugins plugins, boolean allowDeoptimization) {
    Registration r = new Registration(plugins, Math.class);
    if (allowDeoptimization) {
        for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long }) {
            Class<?> type = kind.toJavaClass();
            r.register1("decrementExact", type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) {
                    b.addPush(kind, new IntegerSubExactNode(x, ConstantNode.forIntegerKind(kind, 1)));
                    return true;
                }
            });
            r.register1("incrementExact", type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) {
                    b.addPush(kind, new IntegerAddExactNode(x, ConstantNode.forIntegerKind(kind, 1)));
                    return true;
                }
            });
            r.register2("addExact", type, type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                    b.addPush(kind, new IntegerAddExactNode(x, y));
                    return true;
                }
            });
            r.register2("subtractExact", type, type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                    b.addPush(kind, new IntegerSubExactNode(x, y));
                    return true;
                }
            });
            r.register2("multiplyExact", type, type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                    b.addPush(kind, new IntegerMulExactNode(x, y));
                    return true;
                }
            });
        }
    }
    r.register1("abs", Float.TYPE, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Float, b.append(new AbsNode(value).canonical(null)));
            return true;
        }
    });
    r.register1("abs", Double.TYPE, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Double, b.append(new AbsNode(value).canonical(null)));
            return true;
        }
    });
    r.register1("sqrt", Double.TYPE, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Double, b.append(SqrtNode.create(value, NodeView.DEFAULT)));
            return true;
        }
    });
}
Also used : IntegerAddExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerAddExactNode) IntegerSubExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerSubExactNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) IntegerMulExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulExactNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) AbsNode(org.graalvm.compiler.nodes.calc.AbsNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 AbsNode (org.graalvm.compiler.nodes.calc.AbsNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)1 IntegerAddExactNode (org.graalvm.compiler.replacements.nodes.arithmetic.IntegerAddExactNode)1 IntegerMulExactNode (org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulExactNode)1 IntegerSubExactNode (org.graalvm.compiler.replacements.nodes.arithmetic.IntegerSubExactNode)1