Search in sources :

Example 6 with ForeignCallDescriptor

use of org.graalvm.compiler.core.common.spi.ForeignCallDescriptor in project graal by oracle.

the class StubUtil method descriptorFor.

/**
 * Looks for a {@link StubForeignCallNode} node intrinsic named {@code name} in
 * {@code stubClass} and returns a {@link ForeignCallDescriptor} based on its signature and the
 * value of {@code hasSideEffect}.
 */
private static ForeignCallDescriptor descriptorFor(Class<?> stubClass, String name) {
    Method found = null;
    for (Method method : stubClass.getDeclaredMethods()) {
        if (Modifier.isStatic(method.getModifiers()) && method.getAnnotation(NodeIntrinsic.class) != null && method.getName().equals(name)) {
            if (method.getAnnotation(NodeIntrinsic.class).value().equals(StubForeignCallNode.class)) {
                assert found == null : "found more than one foreign call named " + name + " in " + stubClass;
                assert method.getParameterTypes().length != 0 && method.getParameterTypes()[0] == ForeignCallDescriptor.class : "first parameter of foreign call '" + name + "' in " + stubClass + " must be of type " + ForeignCallDescriptor.class.getSimpleName();
                found = method;
            }
        }
    }
    assert found != null : "could not find foreign call named " + name + " in " + stubClass;
    List<Class<?>> paramList = Arrays.asList(found.getParameterTypes());
    Class<?>[] cCallTypes = paramList.subList(1, paramList.size()).toArray(new Class<?>[paramList.size() - 1]);
    return new ForeignCallDescriptor(name, found.getReturnType(), cCallTypes);
}
Also used : ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) Method(java.lang.reflect.Method) NodeIntrinsic(org.graalvm.compiler.graph.Node.NodeIntrinsic)

Example 7 with ForeignCallDescriptor

use of org.graalvm.compiler.core.common.spi.ForeignCallDescriptor in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerBinaryMath.

private void lowerBinaryMath(BinaryMathIntrinsicNode math, LoweringTool tool) {
    if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
        return;
    }
    ResolvedJavaMethod method = math.graph().method();
    if (method != null) {
        if (method.getAnnotation(Snippet.class) != null) {
            /*
                 * In the context of the snippet use the LIR lowering instead of the Node lowering.
                 */
            return;
        }
        if (method.getName().equalsIgnoreCase(math.getOperation().name()) && tool.getMetaAccess().lookupJavaType(Math.class).equals(method.getDeclaringClass())) {
            /*
                 * A root compilation of the intrinsic method should emit the full assembly
                 * implementation.
                 */
            return;
        }
    }
    ForeignCallDescriptor foreignCall = toForeignCall(math.getOperation());
    if (foreignCall != null) {
        StructuredGraph graph = math.graph();
        ForeignCallNode call = graph.add(new ForeignCallNode(foreignCalls, toForeignCall(math.getOperation()), math.getX(), math.getY()));
        graph.addAfterFixed(tool.lastFixedNode(), call);
        math.replaceAtUsages(call);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Snippet(org.graalvm.compiler.api.replacements.Snippet) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 8 with ForeignCallDescriptor

use of org.graalvm.compiler.core.common.spi.ForeignCallDescriptor in project graal by oracle.

the class HotSpotHostForeignCallsProvider method buildDescriptor.

private ForeignCallDescriptor buildDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) {
    assert !killAny || kind == JavaKind.Object;
    String name = kind + (aligned ? "Aligned" : "") + (disjoint ? "Disjoint" : "") + (uninit ? "Uninit" : "") + "Arraycopy" + (killAny ? "KillAny" : "");
    ForeignCallDescriptor desc = new ForeignCallDescriptor(name, void.class, Word.class, Word.class, Word.class);
    LocationIdentity killed = killAny ? LocationIdentity.any() : NamedLocationIdentity.getArrayLocation(kind);
    registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
    return desc;
}
Also used : ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) LocationIdentity(org.graalvm.word.LocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity)

Example 9 with ForeignCallDescriptor

use of org.graalvm.compiler.core.common.spi.ForeignCallDescriptor in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerUnaryMath.

private void lowerUnaryMath(UnaryMathIntrinsicNode math, LoweringTool tool) {
    if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
        return;
    }
    ResolvedJavaMethod method = math.graph().method();
    if (method != null) {
        if (method.getAnnotation(Snippet.class) != null) {
            /*
                 * In the context of the snippet use the LIR lowering instead of the Node lowering.
                 */
            return;
        }
        if (method.getName().equalsIgnoreCase(math.getOperation().name()) && tool.getMetaAccess().lookupJavaType(Math.class).equals(method.getDeclaringClass())) {
            /*
                 * A root compilation of the intrinsic method should emit the full assembly
                 * implementation.
                 */
            return;
        }
    }
    ForeignCallDescriptor foreignCall = toForeignCall(math.getOperation());
    if (foreignCall != null) {
        StructuredGraph graph = math.graph();
        ForeignCallNode call = math.graph().add(new ForeignCallNode(foreignCalls, foreignCall, math.getValue()));
        graph.addAfterFixed(tool.lastFixedNode(), call);
        math.replaceAtUsages(call);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Snippet(org.graalvm.compiler.api.replacements.Snippet) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ForeignCallDescriptor (org.graalvm.compiler.core.common.spi.ForeignCallDescriptor)9 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Snippet (org.graalvm.compiler.api.replacements.Snippet)2 NamedLocationIdentity (org.graalvm.compiler.nodes.NamedLocationIdentity)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 LocationIdentity (org.graalvm.word.LocationIdentity)2 Method (java.lang.reflect.Method)1 NodeIntrinsic (org.graalvm.compiler.graph.Node.NodeIntrinsic)1