use of org.graalvm.compiler.replacements.InvocationPluginHelper in project graal by oracle.
the class HotSpotGraphBuilderPlugins method registerBigIntegerPlugins.
private static void registerBigIntegerPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) {
Registration r = new Registration(plugins, BigInteger.class, replacements);
r.registerConditional(config.useMultiplyToLenIntrinsic(), new SnippetSubstitutionInvocationPlugin<>(BigIntegerSnippets.Templates.class, "implMultiplyToLen", int[].class, int.class, int[].class, int.class, int[].class) {
@Override
public SnippetTemplate.SnippetInfo getSnippet(BigIntegerSnippets.Templates templates) {
return templates.implMultiplyToLen;
}
});
r.registerConditional(config.useMulAddIntrinsic(), new InvocationPlugin("implMulAdd", int[].class, int[].class, int.class, int.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode out, ValueNode in, ValueNode offset, ValueNode len, ValueNode k) {
try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) {
ValueNode outNonNull = b.nullCheckedValue(out);
ValueNode outNonNullLength = b.add(new ArrayLengthNode(outNonNull));
ValueNode newOffset = new SubNode(outNonNullLength, offset);
ForeignCallNode call = new ForeignCallNode(HotSpotBackend.MUL_ADD, helper.arrayStart(outNonNull, JavaKind.Int), helper.arrayStart(in, JavaKind.Int), newOffset, len, k);
b.addPush(JavaKind.Int, call);
}
return true;
}
});
/*
* static int[] implMontgomeryMultiply(int[] a, int[] b, int[] n, int len, long inv, int[]
* product)
*/
r.registerConditional(config.useMontgomeryMultiplyIntrinsic(), new InvocationPlugin("implMontgomeryMultiply", int[].class, int[].class, int[].class, int.class, long.class, int[].class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a, ValueNode bObject, ValueNode n, ValueNode len, ValueNode inv, ValueNode product) {
try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) {
// The stub doesn't return the right value for the intrinsic so push it here
// and the proper after FrameState will be put on ForeignCallNode by add.
b.addPush(JavaKind.Object, product);
b.add(new ForeignCallNode(HotSpotBackend.MONTGOMERY_MULTIPLY, helper.arrayStart(a, JavaKind.Int), helper.arrayStart(bObject, JavaKind.Int), helper.arrayStart(n, JavaKind.Int), len, inv, helper.arrayStart(product, JavaKind.Int)));
}
return true;
}
});
/*
* static int[] implMontgomerySquare(int[] a, int[] n, int len, long inv, int[] product)
*/
r.registerConditional(config.useMontgomerySquareIntrinsic(), new InvocationPlugin("implMontgomerySquare", int[].class, int[].class, int.class, long.class, int[].class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a, ValueNode n, ValueNode len, ValueNode inv, ValueNode product) {
try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) {
// The stub doesn't return the right value for the intrinsic so push it here
// and the proper after FrameState will be put on ForeignCallNode by add.
b.addPush(JavaKind.Object, product);
b.add(new ForeignCallNode(HotSpotBackend.MONTGOMERY_SQUARE, helper.arrayStart(a, JavaKind.Int), helper.arrayStart(n, JavaKind.Int), len, inv, helper.arrayStart(product, JavaKind.Int)));
}
return true;
}
});
/*
* static int[] implSquareToLen(int[] x, int len, int[] z, int zLen)
*/
r.registerConditional(config.useSquareToLenIntrinsic(), new InvocationPlugin("implSquareToLen", int[].class, int.class, int[].class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode len, ValueNode z, ValueNode zlen) {
try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) {
// The stub doesn't return the right value for the intrinsic so push it here
// and the proper after FrameState will be put on ForeignCallNode by add.
b.addPush(JavaKind.Object, z);
b.add(new ForeignCallNode(HotSpotBackend.SQUARE_TO_LEN, helper.arrayStart(x, JavaKind.Int), len, helper.arrayStart(z, JavaKind.Int), zlen));
}
return true;
}
});
}
use of org.graalvm.compiler.replacements.InvocationPluginHelper 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.replacements.InvocationPluginHelper 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());
}
Aggregations