Search in sources :

Example 1 with TruffleCompilerRuntime

use of org.graalvm.compiler.truffle.common.TruffleCompilerRuntime in project graal by oracle.

the class TruffleGraphBuilderPlugins method registerFrameAccessors.

/**
 * We intrinsify the getXxx, setXxx, and isXxx methods for all type tags. The intrinsic nodes
 * are lightweight fixed nodes without a {@link FrameState}. No {@link FrameState} is important
 * for partial evaluation performance, because creating and later on discarding FrameStates for
 * the setXxx methods have a high compile time cost.
 *
 * Intrinsification requires the following conditions: (1) the accessed frame is directly the
 * {@link NewFrameNode}, (2) the accessed FrameSlot is a constant, and (3) the FrameDescriptor
 * was never materialized before. All three conditions together guarantee that the escape
 * analysis can virtualize the access. The condition (3) is necessary because a possible
 * materialization of the frame can prevent escape analysis - so in that case a FrameState for
 * setXxx methods is actually necessary since they stores can be state-changing memory
 * operations.
 *
 * Note that we do not register an intrinsification for {@code FrameWithoutBoxing.getValue()}.
 * It is a complicated method to intrinsify, and it is not used frequently enough to justify the
 * complexity of an intrinsification.
 */
private static void registerFrameAccessors(Registration r, JavaKind accessKind, ConstantReflectionProvider constantReflection, KnownTruffleTypes types) {
    TruffleCompilerRuntime runtime = TruffleCompilerRuntime.getRuntime();
    int accessTag = runtime.getFrameSlotKindTagForJavaKind(accessKind);
    String nameSuffix = accessKind.name();
    ResolvedJavaSymbol frameSlotType = new ResolvedJavaSymbol(types.classFrameSlot);
    r.register2("get" + nameSuffix, Receiver.class, frameSlotType, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode) {
            int frameSlotIndex = maybeGetConstantFrameSlotIndex(frameNode, frameSlotNode, constantReflection, types);
            if (frameSlotIndex >= 0) {
                b.addPush(accessKind, new VirtualFrameGetNode(frameNode, frameSlotIndex, accessKind, accessTag));
                return true;
            }
            return false;
        }
    });
    r.register3("set" + nameSuffix, Receiver.class, frameSlotType, accessKind == JavaKind.Object ? Object.class : accessKind.toJavaClass(), new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode, ValueNode value) {
            int frameSlotIndex = maybeGetConstantFrameSlotIndex(frameNode, frameSlotNode, constantReflection, types);
            if (frameSlotIndex >= 0) {
                b.add(new VirtualFrameSetNode(frameNode, frameSlotIndex, accessTag, value));
                return true;
            }
            return false;
        }
    });
    r.register2("is" + nameSuffix, Receiver.class, frameSlotType, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver frameNode, ValueNode frameSlotNode) {
            int frameSlotIndex = maybeGetConstantFrameSlotIndex(frameNode, frameSlotNode, constantReflection, types);
            if (frameSlotIndex >= 0) {
                b.addPush(JavaKind.Boolean, new VirtualFrameIsNode(frameNode, frameSlotIndex, accessTag));
                return true;
            }
            return false;
        }
    });
}
Also used : VirtualFrameIsNode(org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameIsNode) VirtualFrameSetNode(org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameSetNode) TruffleCompilerRuntime(org.graalvm.compiler.truffle.common.TruffleCompilerRuntime) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) VirtualFrameGetNode(org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameGetNode) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with TruffleCompilerRuntime

use of org.graalvm.compiler.truffle.common.TruffleCompilerRuntime in project graal by oracle.

the class HistogramInlineInvokePlugin method print.

public void print(CompilableTruffleAST target) {
    TruffleCompilerRuntime tcr = TruffleCompilerRuntime.getRuntime();
    tcr.log(String.format("Truffle expansion histogram for %s", target));
    tcr.log("  Invocations = Number of expanded invocations");
    tcr.log("  Nodes = Number of non-trival Graal nodes created for this method during partial evaluation.");
    tcr.log("  Calls = Number of not expanded calls created for this method during partial evaluation.");
    tcr.log(String.format(" %-11s |Nodes %5s %5s %5s %8s |Calls %5s %5s %5s %8s | Method Name", "Invocations", "Sum", "Min", "Max", "Avg", "Sum", "Min", "Max", "Avg"));
    /* First filter the statistics and collect them in a list. */
    List<MethodStatistics> statisticsList = new ArrayList<>();
    for (MethodStatistics statistics : histogram.values()) {
        if (statistics.shallowCount.getSum() > 0) {
            statisticsList.add(statistics);
        }
    }
    /* Then sort the list. */
    Collections.sort(statisticsList);
    /* Finally print the filtered and sorted statistics. */
    for (MethodStatistics statistics : statisticsList) {
        statistics.print();
    }
}
Also used : TruffleCompilerRuntime(org.graalvm.compiler.truffle.common.TruffleCompilerRuntime) ArrayList(java.util.ArrayList)

Example 3 with TruffleCompilerRuntime

use of org.graalvm.compiler.truffle.common.TruffleCompilerRuntime in project graal by oracle.

the class PartialEvaluator method postPartialEvaluation.

private static void postPartialEvaluation(final StructuredGraph graph) {
    NeverPartOfCompilationNode.verifyNotFoundIn(graph);
    for (AllowMaterializeNode materializeNode : graph.getNodes(AllowMaterializeNode.TYPE).snapshot()) {
        materializeNode.replaceAtUsages(materializeNode.getFrame());
        graph.removeFixed(materializeNode);
    }
    TruffleCompilerRuntime rt = TruffleCompilerRuntime.getRuntime();
    for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.TYPE)) {
        if (virtualObjectNode instanceof VirtualInstanceNode) {
            VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
            ResolvedJavaType type = virtualInstanceNode.type();
            if (rt.isValueType(type)) {
                virtualInstanceNode.setIdentity(false);
            }
        }
    }
    if (!TruffleCompilerOptions.getValue(TruffleInlineAcrossTruffleBoundary)) {
        // Do not inline across Truffle boundaries.
        for (MethodCallTargetNode mct : graph.getNodes(MethodCallTargetNode.TYPE)) {
            InlineInfo inlineInfo = rt.getInlineInfo(mct.targetMethod(), false);
            if (!inlineInfo.allowsInlining()) {
                mct.invoke().setUseForInlining(false);
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) TruffleCompilerRuntime(org.graalvm.compiler.truffle.common.TruffleCompilerRuntime) AllowMaterializeNode(org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

TruffleCompilerRuntime (org.graalvm.compiler.truffle.common.TruffleCompilerRuntime)3 ArrayList (java.util.ArrayList)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InlineInfo (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo)1 InlineInfo.createStandardInlineInfo (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)1 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)1 VirtualInstanceNode (org.graalvm.compiler.nodes.virtual.VirtualInstanceNode)1 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)1 AllowMaterializeNode (org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode)1 VirtualFrameGetNode (org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameGetNode)1 VirtualFrameIsNode (org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameIsNode)1 VirtualFrameSetNode (org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameSetNode)1