Search in sources :

Example 1 with IndexAddressNode

use of org.graalvm.compiler.nodes.memory.address.IndexAddressNode 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 IndexAddressNode

use of org.graalvm.compiler.nodes.memory.address.IndexAddressNode 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 IndexAddressNode

use of org.graalvm.compiler.nodes.memory.address.IndexAddressNode in project graal by oracle.

the class StandardGraphBuilderPlugins method registerStringPlugins.

private static void registerStringPlugins(InvocationPlugins plugins, Replacements replacements, SnippetReflectionProvider snippetReflection, boolean arrayEqualsSubstitution) {
    final Registration r = new Registration(plugins, String.class, replacements);
    r.register(new InvocationPlugin("hashCode", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant()) {
                String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
                if (s != null) {
                    b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
                    return true;
                }
            }
            return false;
        }
    });
    r.register(new InvocationPlugin("intern", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant()) {
                String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
                if (s != null) {
                    JavaConstant interned = snippetReflection.forObject(s.intern());
                    b.addPush(JavaKind.Object, b.add(ConstantNode.forConstant(interned, b.getMetaAccess(), b.getGraph())));
                    return true;
                }
            }
            return false;
        }
    });
    if (arrayEqualsSubstitution) {
        r.register(new StringEqualsInvocationPlugin());
    }
    final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16", replacements);
    utf16r.setAllowOverwrite(true);
    utf16r.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), BarrierType.NONE, false));
            return true;
        }
    });
    utf16r.register(new InvocationPlugin("putChar", byte[].class, int.class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3) {
            b.add(new JavaWriteNode(JavaKind.Char, new IndexAddressNode(arg1, new LeftShiftNode(arg2, ConstantNode.forInt(1)), JavaKind.Byte), NamedLocationIdentity.getArrayLocation(JavaKind.Byte), arg3, BarrierType.NONE, false));
            return true;
        }
    });
    Registration sr = new Registration(plugins, StringHelperIntrinsics.class);
    sr.register(new InlineOnlyInvocationPlugin("getByte", byte[].class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
            b.addPush(JavaKind.Byte, new JavaReadNode(JavaKind.Byte, new IndexAddressNode(arg1, arg2, JavaKind.Byte), NamedLocationIdentity.getArrayLocation(JavaKind.Byte), BarrierType.NONE, false));
            return true;
        }
    });
}
Also used : Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) IndexAddressNode(org.graalvm.compiler.nodes.memory.address.IndexAddressNode) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) RequiredInlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) OptionalInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) RequiredInlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 4 with IndexAddressNode

use of org.graalvm.compiler.nodes.memory.address.IndexAddressNode in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerIndexAddressNode.

protected void lowerIndexAddressNode(IndexAddressNode indexAddress) {
    AddressNode lowered = createArrayAddress(indexAddress.graph(), indexAddress.getArray(), indexAddress.getArrayKind(), indexAddress.getElementKind(), indexAddress.getIndex());
    indexAddress.replaceAndDelete(lowered);
}
Also used : GetObjectAddressNode(org.graalvm.compiler.nodes.GetObjectAddressNode) IndexAddressNode(org.graalvm.compiler.nodes.memory.address.IndexAddressNode) ComputeObjectAddressNode(org.graalvm.compiler.nodes.ComputeObjectAddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode)

Aggregations

IndexAddressNode (org.graalvm.compiler.nodes.memory.address.IndexAddressNode)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)3 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)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 NarrowNode (org.graalvm.compiler.nodes.calc.NarrowNode)2 ZeroExtendNode (org.graalvm.compiler.nodes.calc.ZeroExtendNode)2 InlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin)2 ArrayIndexOfNode (org.graalvm.compiler.replacements.ArrayIndexOfNode)2 SnippetSubstitutionInvocationPlugin (org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin)2 StringUTF16Snippets (org.graalvm.compiler.replacements.StringUTF16Snippets)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ComputeObjectAddressNode (org.graalvm.compiler.nodes.ComputeObjectAddressNode)1 GetObjectAddressNode (org.graalvm.compiler.nodes.GetObjectAddressNode)1 JavaWriteNode (org.graalvm.compiler.nodes.extended.JavaWriteNode)1 OptionalInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1