Search in sources :

Example 1 with ArrayIndexOfNode

use of org.graalvm.compiler.replacements.ArrayIndexOfNode in project graal by oracle.

the class AArch64GraphBuilderPlugins method registerStringUTF16Plugins.

private static void registerStringUTF16Plugins(InvocationPlugins plugins, Replacements replacements) {
    Registration r = new Registration(plugins, "java.lang.StringUTF16", replacements);
    r.setAllowOverwrite(true);
    r.register(new ArrayCompareToPlugin(JavaKind.Char, JavaKind.Char, "compareTo", byte[].class, byte[].class));
    r.register(new ArrayCompareToPlugin(JavaKind.Char, JavaKind.Byte, true, "compareToLatin1", byte[].class, byte[].class));
    r.register(new SnippetSubstitutionInvocationPlugin<>(StringUTF16Snippets.Templates.class, "indexOfUnsafe", byte[].class, int.class, byte[].class, int.class, int.class) {

        @Override
        public SnippetTemplate.SnippetInfo getSnippet(StringUTF16Snippets.Templates templates) {
            return templates.indexOfUnsafe;
        }
    });
    r.register(new InvocationPlugin("indexOfCharUnsafe", byte[].class, int.class, int.class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value, ValueNode ch, ValueNode fromIndex, ValueNode max) {
            ZeroExtendNode toChar = b.add(new ZeroExtendNode(b.add(new NarrowNode(ch, JavaKind.Char.getBitCount())), JavaKind.Int.getBitCount()));
            b.addPush(JavaKind.Int, new ArrayIndexOfNode(JavaKind.Byte, JavaKind.Char, false, false, value, ConstantNode.forLong(0), max, fromIndex, toChar));
            return true;
        }
    });
    Registration r2 = new Registration(plugins, StringUTF16Snippets.class, replacements);
    r2.register(new InvocationPlugin("getChar", byte[].class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
            b.addPush(JavaKind.Char, new JavaReadNode(JavaKind.Char, new IndexAddressNode(arg1, new LeftShiftNode(arg2, ConstantNode.forInt(1)), JavaKind.Byte), NamedLocationIdentity.getArrayLocation(JavaKind.Byte), OnHeapMemoryAccess.BarrierType.NONE, false));
            return true;
        }
    });
}
Also used : ArrayIndexOfNode(org.graalvm.compiler.replacements.ArrayIndexOfNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) IndexAddressNode(org.graalvm.compiler.nodes.memory.address.IndexAddressNode) StringUTF16Snippets(org.graalvm.compiler.replacements.StringUTF16Snippets) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) SnippetSubstitutionInvocationPlugin(org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with ArrayIndexOfNode

use of org.graalvm.compiler.replacements.ArrayIndexOfNode in project graal by oracle.

the class AMD64GraphBuilderPlugins method registerStringUTF16Plugins.

private static void registerStringUTF16Plugins(InvocationPlugins plugins, Replacements replacements) {
    Registration r = new Registration(plugins, "java.lang.StringUTF16", replacements);
    r.setAllowOverwrite(true);
    r.register(new ArrayCompareToPlugin(JavaKind.Char, JavaKind.Char, "compareTo", byte[].class, byte[].class));
    r.register(new ArrayCompareToPlugin(JavaKind.Char, JavaKind.Byte, true, "compareToLatin1", byte[].class, byte[].class));
    r.register(new InvocationPlugin("compress", byte[].class, int.class, byte[].class, int.class, int.class) {

        @SuppressWarnings("try")
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode src, ValueNode srcIndex, ValueNode dest, ValueNode destIndex, ValueNode len) {
            try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) {
                helper.intrinsicRangeCheck(len, Condition.LT, ConstantNode.forInt(0));
                ValueNode scaledSrcIndex = helper.scale(srcIndex, JavaKind.Char);
                helper.intrinsicRangeCheck(scaledSrcIndex, Condition.LT, ConstantNode.forInt(0));
                ValueNode end = helper.add(scaledSrcIndex, helper.scale(len, JavaKind.Char));
                ValueNode srcLength = helper.length(b.nullCheckedValue(src));
                helper.intrinsicRangeCheck(end, Condition.GT, srcLength);
                helper.intrinsicRangeCheck(destIndex, Condition.LT, ConstantNode.forInt(0));
                ValueNode destLength = helper.length(b.nullCheckedValue(dest));
                helper.intrinsicRangeCheck(helper.add(destIndex, len), Condition.GT, destLength);
                ValueNode srcPointer = helper.arrayElementPointer(src, JavaKind.Byte, scaledSrcIndex);
                ValueNode destPointer = helper.arrayElementPointer(dest, JavaKind.Byte, destIndex);
                b.addPush(JavaKind.Int, new AMD64StringUTF16CompressNode(srcPointer, destPointer, len, JavaKind.Byte));
            }
            return true;
        }
    });
    r.register(new InvocationPlugin("compress", char[].class, int.class, byte[].class, int.class, int.class) {

        @SuppressWarnings("try")
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode src, ValueNode srcIndex, ValueNode dest, ValueNode destIndex, ValueNode len) {
            // @formatter:on
            try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) {
                helper.intrinsicRangeCheck(len, Condition.LT, ConstantNode.forInt(0));
                helper.intrinsicRangeCheck(srcIndex, Condition.LT, ConstantNode.forInt(0));
                ValueNode end = helper.add(srcIndex, len);
                ValueNode srcLength = helper.length(b.nullCheckedValue(src));
                helper.intrinsicRangeCheck(end, Condition.GT, srcLength);
                helper.intrinsicRangeCheck(destIndex, Condition.LT, ConstantNode.forInt(0));
                ValueNode destLength = helper.length(b.nullCheckedValue(dest));
                helper.intrinsicRangeCheck(helper.add(destIndex, len), Condition.GT, destLength);
                ValueNode srcPointer = helper.arrayElementPointer(src, JavaKind.Char, srcIndex);
                ValueNode destPointer = helper.arrayElementPointer(dest, JavaKind.Byte, destIndex);
                b.addPush(JavaKind.Int, new AMD64StringUTF16CompressNode(srcPointer, destPointer, len, JavaKind.Char));
            }
            return true;
        }
    });
    r.register(new SnippetSubstitutionInvocationPlugin<>(StringUTF16Snippets.Templates.class, "indexOfUnsafe", byte[].class, int.class, byte[].class, int.class, int.class) {

        @Override
        public SnippetTemplate.SnippetInfo getSnippet(StringUTF16Snippets.Templates templates) {
            return templates.indexOfUnsafe;
        }
    });
    r.register(new SnippetSubstitutionInvocationPlugin<>(StringUTF16Snippets.Templates.class, "indexOfLatin1Unsafe", byte[].class, int.class, byte[].class, int.class, int.class) {

        @Override
        public SnippetTemplate.SnippetInfo getSnippet(StringUTF16Snippets.Templates templates) {
            return templates.indexOfLatin1Unsafe;
        }
    });
    r.register(new InvocationPlugin("indexOfCharUnsafe", byte[].class, int.class, int.class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value, ValueNode ch, ValueNode fromIndex, ValueNode max) {
            ZeroExtendNode toChar = b.add(new ZeroExtendNode(b.add(new NarrowNode(ch, JavaKind.Char.getBitCount())), JavaKind.Int.getBitCount()));
            b.addPush(JavaKind.Int, new ArrayIndexOfNode(JavaKind.Byte, JavaKind.Char, false, false, value, ConstantNode.forLong(0), max, fromIndex, toChar));
            return true;
        }
    });
    Registration r2 = new Registration(plugins, StringUTF16Snippets.class, replacements);
    r2.register(new InvocationPlugin("getChar", byte[].class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
            b.addPush(JavaKind.Char, new JavaReadNode(JavaKind.Char, new IndexAddressNode(arg1, new LeftShiftNode(arg2, ConstantNode.forInt(1)), JavaKind.Byte), NamedLocationIdentity.getArrayLocation(JavaKind.Byte), OnHeapMemoryAccess.BarrierType.NONE, false));
            return true;
        }
    });
}
Also used : ArrayIndexOfNode(org.graalvm.compiler.replacements.ArrayIndexOfNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) IndexAddressNode(org.graalvm.compiler.nodes.memory.address.IndexAddressNode) StringUTF16Snippets(org.graalvm.compiler.replacements.StringUTF16Snippets) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) SnippetSubstitutionInvocationPlugin(org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) InvocationPluginHelper(org.graalvm.compiler.replacements.InvocationPluginHelper) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with ArrayIndexOfNode

use of org.graalvm.compiler.replacements.ArrayIndexOfNode in project graal by oracle.

the class TruffleAMD64InvocationPlugins method applyIndexOf.

public static boolean applyIndexOf(GraphBuilderContext b, boolean findTwoConsecutive, boolean withMask, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode... values) {
    JavaKind constStride = constantStrideParam(stride);
    LocationIdentity locationIdentity = inferLocationIdentity(isNative);
    b.addPush(JavaKind.Int, new ArrayIndexOfNode(NONE, constStride, findTwoConsecutive, withMask, locationIdentity, array, offset, length, fromIndex, values));
    return true;
}
Also used : ArrayIndexOfNode(org.graalvm.compiler.replacements.ArrayIndexOfNode) LocationIdentity(org.graalvm.word.LocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 4 with ArrayIndexOfNode

use of org.graalvm.compiler.replacements.ArrayIndexOfNode in project graal by oracle.

the class TruffleAMD64InvocationPlugins method arrayUtilsIndexOf.

public static boolean arrayUtilsIndexOf(GraphBuilderContext b, JavaKind arrayKind, JavaKind stride, boolean findTwoConsecutive, boolean withMask, ValueNode array, ValueNode fromIndex, ValueNode maxIndex, ValueNode... values) {
    ConstantNode zero = ConstantNode.forInt(0, b.getGraph());
    b.addPush(JavaKind.Int, new ArrayIndexOfNode(arrayKind, stride, findTwoConsecutive, withMask, getArrayLocation(arrayKind), array, zero, maxIndex, fromIndex, values));
    return true;
}
Also used : ArrayIndexOfNode(org.graalvm.compiler.replacements.ArrayIndexOfNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode)

Aggregations

ArrayIndexOfNode (org.graalvm.compiler.replacements.ArrayIndexOfNode)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)2 NarrowNode (org.graalvm.compiler.nodes.calc.NarrowNode)2 ZeroExtendNode (org.graalvm.compiler.nodes.calc.ZeroExtendNode)2 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)2 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)2 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)2 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)2 IndexAddressNode (org.graalvm.compiler.nodes.memory.address.IndexAddressNode)2 SnippetSubstitutionInvocationPlugin (org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin)2 StringUTF16Snippets (org.graalvm.compiler.replacements.StringUTF16Snippets)2 JavaKind (jdk.vm.ci.meta.JavaKind)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 NamedLocationIdentity (org.graalvm.compiler.nodes.NamedLocationIdentity)1 InlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin)1 InvocationPluginHelper (org.graalvm.compiler.replacements.InvocationPluginHelper)1 LocationIdentity (org.graalvm.word.LocationIdentity)1