Search in sources :

Example 1 with StringLatin1IndexOfCharPlugin

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

the class AArch64GraphBuilderPlugins method registerStringLatin1Plugins.

private static void registerStringLatin1Plugins(InvocationPlugins plugins, Replacements replacements) {
    Registration r = new Registration(plugins, "java.lang.StringLatin1", replacements);
    r.setAllowOverwrite(true);
    r.register(new ArrayCompareToPlugin(JavaKind.Byte, JavaKind.Byte, "compareTo", byte[].class, byte[].class));
    r.register(new ArrayCompareToPlugin(JavaKind.Byte, JavaKind.Char, "compareToUTF16", byte[].class, byte[].class));
    r.register(new SnippetSubstitutionInvocationPlugin<>(StringLatin1Snippets.Templates.class, "indexOf", byte[].class, int.class, byte[].class, int.class, int.class) {

        @Override
        public SnippetTemplate.SnippetInfo getSnippet(StringLatin1Snippets.Templates templates) {
            return templates.indexOf;
        }
    });
    r.register(new StringLatin1IndexOfCharPlugin());
}
Also used : StringLatin1Snippets(org.graalvm.compiler.replacements.StringLatin1Snippets) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StringLatin1IndexOfCharPlugin(org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.StringLatin1IndexOfCharPlugin)

Example 2 with StringLatin1IndexOfCharPlugin

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

the class AMD64GraphBuilderPlugins method registerStringLatin1Plugins.

private static void registerStringLatin1Plugins(InvocationPlugins plugins, Replacements replacements) {
    Registration r = new Registration(plugins, "java.lang.StringLatin1", replacements);
    r.setAllowOverwrite(true);
    r.register(new ArrayCompareToPlugin(JavaKind.Byte, JavaKind.Byte, "compareTo", byte[].class, byte[].class));
    r.register(new ArrayCompareToPlugin(JavaKind.Byte, JavaKind.Char, "compareToUTF16", byte[].class, byte[].class));
    r.register(new InvocationPlugin("inflate", 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) {
            // @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 srcLength = helper.length(b.nullCheckedValue(src));
                helper.intrinsicRangeCheck(helper.add(srcIndex, len), Condition.GT, srcLength);
                ValueNode scaledDestIndex = helper.scale(destIndex, JavaKind.Char);
                helper.intrinsicRangeCheck(scaledDestIndex, Condition.LT, ConstantNode.forInt(0));
                ValueNode end = helper.add(scaledDestIndex, helper.scale(len, JavaKind.Char));
                ValueNode destLength = helper.length(b.nullCheckedValue(dest));
                helper.intrinsicRangeCheck(end, Condition.GT, destLength);
                ValueNode srcPointer = helper.arrayElementPointer(src, JavaKind.Byte, srcIndex);
                ValueNode destPointer = helper.arrayElementPointer(dest, JavaKind.Byte, scaledDestIndex);
                b.add(new AMD64StringLatin1InflateNode(srcPointer, destPointer, len, JavaKind.Byte));
            }
            return true;
        }
    });
    r.register(new InvocationPlugin("inflate", byte[].class, int.class, char[].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 srcLength = helper.length(b.nullCheckedValue(src));
                helper.intrinsicRangeCheck(helper.add(srcIndex, len), Condition.GT, srcLength);
                helper.intrinsicRangeCheck(destIndex, Condition.LT, ConstantNode.forInt(0));
                ValueNode end = helper.add(destIndex, len);
                ValueNode destLength = helper.length(b.nullCheckedValue(dest));
                helper.intrinsicRangeCheck(end, Condition.GT, destLength);
                ValueNode srcPointer = helper.arrayElementPointer(src, JavaKind.Byte, srcIndex);
                ValueNode destPointer = helper.arrayElementPointer(dest, JavaKind.Char, destIndex);
                b.add(new AMD64StringLatin1InflateNode(srcPointer, destPointer, len, JavaKind.Char));
            }
            return true;
        }
    });
    r.register(new SnippetSubstitutionInvocationPlugin<>(StringLatin1Snippets.Templates.class, "indexOf", byte[].class, int.class, byte[].class, int.class, int.class) {

        @Override
        public SnippetTemplate.SnippetInfo getSnippet(StringLatin1Snippets.Templates templates) {
            return templates.indexOf;
        }
    });
    r.register(new StringLatin1IndexOfCharPlugin());
}
Also used : StringLatin1Snippets(org.graalvm.compiler.replacements.StringLatin1Snippets) 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) StringLatin1IndexOfCharPlugin(org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.StringLatin1IndexOfCharPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)2 StringLatin1IndexOfCharPlugin (org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.StringLatin1IndexOfCharPlugin)2 StringLatin1Snippets (org.graalvm.compiler.replacements.StringLatin1Snippets)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 InvocationPluginHelper (org.graalvm.compiler.replacements.InvocationPluginHelper)1 SnippetSubstitutionInvocationPlugin (org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin)1