Search in sources :

Example 11 with ParameterNode

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

the class MonitorGraphTest method parseAndProcess.

private StructuredGraph parseAndProcess(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    ParameterNode param = graph.getNodes(ParameterNode.TYPE).first();
    if (param != null) {
        ConstantNode constant = ConstantNode.forInt(0, graph);
        for (Node n : param.usages().snapshot()) {
            if (!(n instanceof FrameState)) {
                n.replaceFirstInput(param, constant);
            }
        }
    }
    Map<Invoke, Double> hints = new HashMap<>();
    for (Invoke invoke : graph.getInvokes()) {
        hints.put(invoke, 1000d);
    }
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(hints, new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, context);
    new DeadCodeEliminationPhase().apply(graph);
    return graph;
}
Also used : HashMap(java.util.HashMap) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) FrameState(org.graalvm.compiler.nodes.FrameState) Invoke(org.graalvm.compiler.nodes.Invoke) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 12 with ParameterNode

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

the class TypeFlowGraphBuilder method checkFormalParameterBuilder.

/**
 * Check if the formal parameter is a parameter of one of the wait/notify/hashCode methods. If
 * so add it as a sink since it must be retained. Don't need to check the position of the
 * parameter, since each of the checked methods has at most one object parameter.
 */
public void checkFormalParameterBuilder(TypeFlowBuilder<?> paramBuilder) {
    AnalysisMethod method = (AnalysisMethod) ((ParameterNode) paramBuilder.getSource()).graph().method();
    String methodFormat = method.format("%H.%n(%P)");
    for (String specialMethodFormat : waitNotifyHashCodeMethods) {
        if (methodFormat.equals(specialMethodFormat)) {
            dataFlowSinkBuilders.add(paramBuilder);
        }
    }
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ParameterNode(org.graalvm.compiler.nodes.ParameterNode)

Example 13 with ParameterNode

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

the class CEntryPointCallStubMethod method adaptParameterTypes.

private EnumInfo[] adaptParameterTypes(HostedProviders providers, NativeLibraries nativeLibraries, HostedGraphKit kit, JavaType[] parameterTypes, JavaType[] parameterLoadTypes, Purpose purpose) {
    EnumInfo[] parameterEnumInfos = null;
    for (int i = 0; i < parameterTypes.length; i++) {
        if (!parameterTypes[i].getJavaKind().isPrimitive() && !providers.getWordTypes().isWord(parameterTypes[i])) {
            ElementInfo typeInfo = nativeLibraries.findElementInfo(parameterTypes[i]);
            if (typeInfo instanceof EnumInfo) {
                UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumLookupInfo.class::isInstance), "Enum class " + parameterTypes[i].toJavaName() + " needs a method that is annotated with @" + CEnumLookup.class + " because it is used as a parameter of an entry point method: " + targetMethod.format("%H.%n(%p)"));
                if (parameterEnumInfos == null) {
                    parameterEnumInfos = new EnumInfo[parameterTypes.length];
                }
                parameterEnumInfos[i] = (EnumInfo) typeInfo;
                parameterLoadTypes[i] = providers.getMetaAccess().lookupJavaType(cEnumParameterKind.toJavaClass());
                final int parameterIndex = i;
                FrameState initialState = kit.getGraph().start().stateAfter();
                Iterator<ValueNode> matchingNodes = initialState.values().filter(node -> ((ParameterNode) node).index() == parameterIndex).iterator();
                ValueNode parameterNode = matchingNodes.next();
                assert !matchingNodes.hasNext() && parameterNode.usages().filter(n -> n != initialState).isEmpty();
                parameterNode.setStamp(StampFactory.forKind(cEnumParameterKind));
            } else if (purpose != Purpose.ANALYSIS) {
                // for analysis test cases: abort only during compilation
                throw UserError.abort("Entry point method parameter types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + targetMethod.format("%H.%n(%p)"));
            }
        }
    }
    return parameterEnumInfos;
}
Also used : Isolate(org.graalvm.nativeimage.Isolate) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphProvider(com.oracle.graal.pointsto.infrastructure.GraphProvider) NativeBootImage(com.oracle.svm.hosted.image.NativeBootImage) Constant(jdk.vm.ci.meta.Constant) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) CInterfaceEnumTool(com.oracle.svm.hosted.phases.CInterfaceEnumTool) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) JavaKind(jdk.vm.ci.meta.JavaKind) IsolateThread(org.graalvm.nativeimage.IsolateThread) UserError(com.oracle.svm.core.util.UserError) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointPrologueBailoutNode(com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode) CEntryPointSetup(com.oracle.svm.core.c.function.CEntryPointSetup) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) ConstantPool(jdk.vm.ci.meta.ConstantPool) CEnumValue(org.graalvm.nativeimage.c.constant.CEnumValue) UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) VMError(com.oracle.svm.core.util.VMError) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) FrameState(org.graalvm.compiler.nodes.FrameState) Type(java.lang.reflect.Type) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) NoPrologue(com.oracle.svm.core.c.function.CEntryPointOptions.NoPrologue) NoEpilogue(com.oracle.svm.core.c.function.CEntryPointOptions.NoEpilogue) SpeculationLog(jdk.vm.ci.meta.SpeculationLog) CEnum(org.graalvm.nativeimage.c.constant.CEnum) HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Signature(jdk.vm.ci.meta.Signature) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) EnumValueInfo(com.oracle.svm.hosted.c.info.EnumValueInfo) DebugContext(org.graalvm.compiler.debug.DebugContext) CEntryPointCallStubs(com.oracle.svm.core.code.CEntryPointCallStubs) EnumLookupInfo(com.oracle.svm.hosted.c.info.EnumLookupInfo) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Iterator(java.util.Iterator) CEnumLookup(org.graalvm.nativeimage.c.constant.CEnumLookup) ExceptionHandler(jdk.vm.ci.meta.ExceptionHandler) ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) SubstrateGraphKit(com.oracle.svm.core.graal.replacements.SubstrateGraphKit) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) LineNumberTable(jdk.vm.ci.meta.LineNumberTable) LocalVariableTable(jdk.vm.ci.meta.LocalVariableTable) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DeadEndNode(com.oracle.svm.core.graal.nodes.DeadEndNode) LeaveAction(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode.LeaveAction) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CEnumLookup(org.graalvm.nativeimage.c.constant.CEnumLookup) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) CEnum(org.graalvm.nativeimage.c.constant.CEnum) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 14 with ParameterNode

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

the class CompileQueue method ensureCompiled.

protected void ensureCompiled(HostedMethod method, CompileReason reason) {
    CompileTask task = new CompileTask(method, reason);
    CompileTask oldTask = compilations.putIfAbsent(method, task);
    if (oldTask != null) {
        // Method is already scheduled for compilation.
        if (oldTask.allReasons != null) {
            oldTask.allReasons.add(reason);
        }
        return;
    }
    if (method.compilationInfo.specializedArguments != null) {
        // Do the specialization: replace the argument locals with the constant arguments.
        StructuredGraph graph = method.compilationInfo.graph;
        int idx = 0;
        for (ConstantNode argument : method.compilationInfo.specializedArguments) {
            ParameterNode local = graph.getParameter(idx++);
            if (local != null) {
                local.replaceAndDelete(ConstantNode.forConstant(argument.asJavaConstant(), runtimeConfig.getProviders().getMetaAccess(), graph));
            }
        }
    }
    executor.execute(task);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint)

Example 15 with ParameterNode

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

the class InliningUtilities method isTrivialMethod.

public static boolean isTrivialMethod(StructuredGraph graph) {
    int numInvokes = 0;
    int numOthers = 0;
    for (Node n : graph.getNodes()) {
        if (n instanceof StartNode || n instanceof ParameterNode || n instanceof FullInfopointNode || n instanceof ValueProxy || n instanceof AssertValueNode) {
            continue;
        }
        if (n instanceof MethodCallTargetNode) {
            numInvokes++;
        } else {
            numOthers++;
        }
        if (!shouldBeTrivial(numInvokes, numOthers, graph)) {
            return false;
        }
    }
    return true;
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueProxy(org.graalvm.compiler.nodes.spi.ValueProxy) StartNode(org.graalvm.compiler.nodes.StartNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) AssertValueNode(com.oracle.svm.hosted.nodes.AssertValueNode) AssertValueNode(com.oracle.svm.hosted.nodes.AssertValueNode)

Aggregations

ParameterNode (org.graalvm.compiler.nodes.ParameterNode)46 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 ValueNode (org.graalvm.compiler.nodes.ValueNode)19 Node (org.graalvm.compiler.graph.Node)13 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)13 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)13 Test (org.junit.Test)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 FrameState (org.graalvm.compiler.nodes.FrameState)7 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)7 FixedNode (org.graalvm.compiler.nodes.FixedNode)6 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)6 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)5 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)5 ArrayList (java.util.ArrayList)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)4