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;
}
});
}
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;
}
});
}
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;
}
});
}
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);
}
Aggregations