Search in sources :

Example 56 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class MacroNode method lower.

@Override
public void lower(LoweringTool tool) {
    StructuredGraph replacementGraph = getLoweredSnippetGraph(tool);
    InvokeNode invoke = replaceWithInvoke();
    assert invoke.verify();
    if (replacementGraph != null) {
        // receiver can be lowered if necessary
        if (!targetMethod.isStatic()) {
            ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
            if (nonNullReceiver instanceof Lowerable) {
                ((Lowerable) nonNullReceiver).lower(tool);
            }
        }
        InliningUtil.inline(invoke, replacementGraph, false, targetMethod);
        replacementGraph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph(), "After inlining replacement %s", replacementGraph);
    } else {
        if (isPlaceholderBci(invoke.bci())) {
            throw new GraalError("%s: cannot lower to invoke with placeholder BCI: %s", graph(), this);
        }
        if (invoke.stateAfter() == null) {
            ResolvedJavaMethod method = graph().method();
            if (method.getAnnotation(MethodSubstitution.class) != null || method.getAnnotation(Snippet.class) != null) {
                // implementation in JDK9.
                throw new GraalError("%s macro created for call to %s in %s must be lowerable to a snippet or intrinsic graph. " + "Maybe a macro node is not needed for this method in the current JDK?", getClass().getSimpleName(), targetMethod.format("%h.%n(%p)"), graph());
            }
            throw new GraalError("%s: cannot lower to invoke without state: %s", graph(), this);
        }
        invoke.lower(tool);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Lowerable(org.graalvm.compiler.nodes.spi.Lowerable) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 57 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class MethodHandleNode method createTargetInvokeNode.

/**
 * Creates an {@link InvokeNode} for the given target method. The {@link CallTargetNode} passed
 * to the InvokeNode is in fact a {@link ResolvedMethodHandleCallTargetNode}.
 *
 * @return invoke node for the member name target
 */
private static InvokeNode createTargetInvokeNode(Assumptions assumptions, IntrinsicMethod intrinsicMethod, ResolvedJavaMethod target, ResolvedJavaMethod original, int bci, StampPair returnStamp, ValueNode[] arguments) {
    InvokeKind targetInvokeKind = target.isStatic() ? InvokeKind.Static : InvokeKind.Special;
    JavaType targetReturnType = target.getSignature().getReturnType(null);
    // MethodHandleLinkTo* nodes have a trailing MemberName argument which
    // needs to be popped.
    ValueNode[] targetArguments;
    switch(intrinsicMethod) {
        case INVOKE_BASIC:
            targetArguments = arguments;
            break;
        case LINK_TO_STATIC:
        case LINK_TO_SPECIAL:
        case LINK_TO_VIRTUAL:
        case LINK_TO_INTERFACE:
            targetArguments = Arrays.copyOfRange(arguments, 0, arguments.length - 1);
            break;
        default:
            throw GraalError.shouldNotReachHere();
    }
    StampPair targetReturnStamp = StampFactory.forDeclaredType(assumptions, targetReturnType, false);
    MethodCallTargetNode callTarget = ResolvedMethodHandleCallTargetNode.create(targetInvokeKind, target, targetArguments, targetReturnStamp, original, arguments, returnStamp);
    // (usually java.lang.Object).
    if (returnStamp.getTrustedStamp().getStackKind() == JavaKind.Void) {
        return new InvokeNode(callTarget, bci, StampFactory.forVoid());
    } else {
        return new InvokeNode(callTarget, bci);
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)

Example 58 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class MethodHandleNode method maybeCastArgument.

/**
 * Inserts a node to cast the argument at index to the given type if the given type is more
 * concrete than the argument type.
 *
 * @param adder
 * @param index of the argument to be cast
 * @param type the type the argument should be cast to
 */
private static void maybeCastArgument(GraphAdder adder, ValueNode[] arguments, int index, JavaType type) {
    ValueNode argument = arguments[index];
    if (type instanceof ResolvedJavaType && !((ResolvedJavaType) type).isJavaLangObject()) {
        Assumptions assumptions = adder.getAssumptions();
        TypeReference targetType = TypeReference.create(assumptions, (ResolvedJavaType) type);
        /*
             * When an argument is a Word type, we can have a mismatch of primitive/object types
             * here. Not inserting a PiNode is a safe fallback, and Word types need no additional
             * type information anyway.
             */
        if (targetType != null && !targetType.getType().isPrimitive() && !argument.getStackKind().isPrimitive()) {
            ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp(NodeView.DEFAULT));
            if (argumentType == null || (argumentType.isAssignableFrom(targetType.getType()) && !argumentType.equals(targetType.getType()))) {
                LogicNode inst = InstanceOfNode.createAllowNull(targetType, argument, null, null);
                assert !inst.isAlive();
                if (!inst.isTautology()) {
                    inst = adder.add(inst);
                    AnchoringNode guardAnchor = adder.getGuardAnchor();
                    DeoptimizationReason reason = DeoptimizationReason.ClassCastException;
                    DeoptimizationAction action = DeoptimizationAction.InvalidateRecompile;
                    JavaConstant speculation = JavaConstant.NULL_POINTER;
                    GuardingNode guard;
                    if (guardAnchor == null) {
                        FixedGuardNode fixedGuard = adder.add(new FixedGuardNode(inst, reason, action, speculation, false));
                        guard = fixedGuard;
                    } else {
                        GuardNode newGuard = adder.add(new GuardNode(inst, guardAnchor, reason, action, false, speculation));
                        adder.add(new ValueAnchorNode(newGuard));
                        guard = newGuard;
                    }
                    ValueNode valueNode = adder.add(PiNode.create(argument, StampFactory.object(targetType), guard.asNode()));
                    arguments[index] = valueNode;
                }
            }
        }
    }
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) AnchoringNode(org.graalvm.compiler.nodes.extended.AnchoringNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Assumptions(jdk.vm.ci.meta.Assumptions) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 59 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class ArrayCompareToNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias1 = tool.getAlias(array1);
    ValueNode alias2 = tool.getAlias(array2);
    if (alias1 == alias2) {
        // the same virtual objects will always have the same contents
        tool.replaceWithValue(ConstantNode.forInt(0, graph()));
    }
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 60 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class ArrayEqualsNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (tool.allUsagesAvailable() && hasNoUsages()) {
        return null;
    }
    ValueNode a1 = GraphUtil.unproxify(array1);
    ValueNode a2 = GraphUtil.unproxify(array2);
    if (a1 == a2) {
        return ConstantNode.forBoolean(true);
    }
    if (a1.isConstant() && a2.isConstant() && length.isConstant()) {
        ConstantNode c1 = (ConstantNode) a1;
        ConstantNode c2 = (ConstantNode) a2;
        if (c1.getStableDimension() >= 1 && c2.getStableDimension() >= 1) {
            boolean ret = arrayEquals(tool.getConstantReflection(), c1.asJavaConstant(), c2.asJavaConstant(), length.asJavaConstant().asInt());
            return ConstantNode.forBoolean(ret);
        }
    }
    return this;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)482 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)104 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)77 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)76 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)69 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)67 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)60 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)52 Node (org.graalvm.compiler.graph.Node)50 JavaKind (jdk.vm.ci.meta.JavaKind)48 Stamp (org.graalvm.compiler.core.common.type.Stamp)48 LogicNode (org.graalvm.compiler.nodes.LogicNode)48 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)38 FixedNode (org.graalvm.compiler.nodes.FixedNode)37 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)37 NodeView (org.graalvm.compiler.nodes.NodeView)36 PhiNode (org.graalvm.compiler.nodes.PhiNode)36 Test (org.junit.Test)36