Search in sources :

Example 1 with ValueProxyNode

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

the class PEReadEliminationClosure method processLoopExit.

@Override
protected void processLoopExit(LoopExitNode exitNode, PEReadEliminationBlockState initialState, PEReadEliminationBlockState exitState, GraphEffectList effects) {
    super.processLoopExit(exitNode, initialState, exitState, effects);
    if (exitNode.graph().hasValueProxies()) {
        MapCursor<ReadCacheEntry, ValueNode> entry = exitState.getReadCache().getEntries();
        while (entry.advance()) {
            if (initialState.getReadCache().get(entry.getKey()) != entry.getValue()) {
                ValueNode value = exitState.getReadCache(entry.getKey().object, entry.getKey().identity, entry.getKey().index, entry.getKey().kind, this);
                assert value != null : "Got null from read cache, entry's value:" + entry.getValue();
                if (!(value instanceof ProxyNode) || ((ProxyNode) value).proxyPoint() != exitNode) {
                    ProxyNode proxy = new ValueProxyNode(value, exitNode);
                    effects.addFloatingNode(proxy, "readCacheProxy");
                    exitState.getReadCache().put(entry.getKey(), proxy);
                }
            }
        }
    }
}
Also used : ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 2 with ValueProxyNode

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

the class PartialEscapeClosure method processMaterializedAtLoopExit.

private static void processMaterializedAtLoopExit(LoopExitNode exitNode, GraphEffectList effects, EconomicMap<Integer, ProxyNode> proxies, int object, ObjectState exitObjState, ObjectState initialObjState, PartialEscapeBlockState<?> exitState) {
    if (initialObjState == null || initialObjState.isVirtual()) {
        ProxyNode proxy = proxies.get(object);
        if (proxy == null) {
            proxy = new ValueProxyNode(exitObjState.getMaterializedValue(), exitNode);
            effects.addFloatingNode(proxy, "proxy");
        } else {
            effects.replaceFirstInput(proxy, proxy.value(), exitObjState.getMaterializedValue());
        // nothing to do - will be handled in processNode
        }
        exitState.updateMaterializedValue(object, proxy);
    } else {
        if (initialObjState.getMaterializedValue() != exitObjState.getMaterializedValue()) {
            exitNode.getDebug().log("materialized value changes within loop: %s vs. %s at %s", initialObjState.getMaterializedValue(), exitObjState.getMaterializedValue(), exitNode);
        }
    }
}
Also used : ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode)

Example 3 with ValueProxyNode

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

the class PartialEscapeClosure method processVirtualAtLoopExit.

private static void processVirtualAtLoopExit(LoopExitNode exitNode, GraphEffectList effects, int object, ObjectState exitObjState, ObjectState initialObjState, PartialEscapeBlockState<?> exitState) {
    for (int i = 0; i < exitObjState.getEntries().length; i++) {
        ValueNode value = exitState.getObjectState(object).getEntry(i);
        if (!(value instanceof VirtualObjectNode || value.isConstant())) {
            if (exitNode.loopBegin().isPhiAtMerge(value) || initialObjState == null || !initialObjState.isVirtual() || initialObjState.getEntry(i) != value) {
                ProxyNode proxy = new ValueProxyNode(value, exitNode);
                exitState.setEntry(object, i, proxy);
                effects.addFloatingNode(proxy, "virtualProxy");
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 4 with ValueProxyNode

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

the class ReadEliminationClosure method processLoopExit.

@Override
protected void processLoopExit(LoopExitNode exitNode, ReadEliminationBlockState initialState, ReadEliminationBlockState exitState, GraphEffectList effects) {
    if (exitNode.graph().hasValueProxies()) {
        MapCursor<CacheEntry<?>, ValueNode> entry = exitState.getReadCache().getEntries();
        while (entry.advance()) {
            if (initialState.getReadCache().get(entry.getKey()) != entry.getValue()) {
                ProxyNode proxy = new ValueProxyNode(exitState.getCacheEntry(entry.getKey()), exitNode);
                effects.addFloatingNode(proxy, "readCacheProxy");
                exitState.getReadCache().put(entry.getKey(), proxy);
            }
        }
    }
}
Also used : ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.LoadCacheEntry) CacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.CacheEntry) UnsafeLoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry)

Example 5 with ValueProxyNode

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

the class LoopFragment method mergeEarlyExits.

/**
 * Merges the early exits (i.e. loop exits) that were duplicated as part of this fragment, with
 * the original fragment's exits.
 */
protected void mergeEarlyExits() {
    assert isDuplicate();
    StructuredGraph graph = graph();
    for (AbstractBeginNode earlyExit : LoopFragment.toHirBlocks(original().loop().loop().getExits())) {
        LoopExitNode loopEarlyExit = (LoopExitNode) earlyExit;
        FixedNode next = loopEarlyExit.next();
        if (loopEarlyExit.isDeleted() || !this.original().contains(loopEarlyExit)) {
            continue;
        }
        AbstractBeginNode newEarlyExit = getDuplicatedNode(loopEarlyExit);
        if (newEarlyExit == null) {
            continue;
        }
        MergeNode merge = graph.add(new MergeNode());
        EndNode originalEnd = graph.add(new EndNode());
        EndNode newEnd = graph.add(new EndNode());
        merge.addForwardEnd(originalEnd);
        merge.addForwardEnd(newEnd);
        loopEarlyExit.setNext(originalEnd);
        newEarlyExit.setNext(newEnd);
        merge.setNext(next);
        FrameState exitState = loopEarlyExit.stateAfter();
        if (exitState != null) {
            FrameState originalExitState = exitState;
            exitState = exitState.duplicateWithVirtualState();
            loopEarlyExit.setStateAfter(exitState);
            merge.setStateAfter(originalExitState);
            /*
                 * Using the old exit's state as the merge's state is necessary because some of the
                 * VirtualState nodes contained in the old exit's state may be shared by other
                 * dominated VirtualStates. Those dominated virtual states need to see the
                 * proxy->phi update that are applied below.
                 *
                 * We now update the original fragment's nodes accordingly:
                 */
            originalExitState.applyToVirtual(node -> original.nodes.clearAndGrow(node));
            exitState.applyToVirtual(node -> original.nodes.markAndGrow(node));
        }
        FrameState finalExitState = exitState;
        for (Node anchored : loopEarlyExit.anchored().snapshot()) {
            anchored.replaceFirstInput(loopEarlyExit, merge);
        }
        boolean newEarlyExitIsLoopExit = newEarlyExit instanceof LoopExitNode;
        for (ProxyNode vpn : loopEarlyExit.proxies().snapshot()) {
            if (vpn.hasNoUsages()) {
                continue;
            }
            if (vpn.value() == null) {
                assert vpn instanceof GuardProxyNode;
                vpn.replaceAtUsages(null);
                continue;
            }
            final ValueNode replaceWith;
            ValueNode newVpn = prim(newEarlyExitIsLoopExit ? vpn : vpn.value());
            if (newVpn != null) {
                PhiNode phi;
                if (vpn instanceof ValueProxyNode) {
                    phi = graph.addWithoutUnique(new ValuePhiNode(vpn.stamp(NodeView.DEFAULT), merge));
                } else if (vpn instanceof GuardProxyNode) {
                    phi = graph.addWithoutUnique(new GuardPhiNode(merge));
                } else {
                    throw GraalError.shouldNotReachHere();
                }
                phi.addInput(vpn);
                phi.addInput(newVpn);
                replaceWith = phi;
            } else {
                replaceWith = vpn.value();
            }
            vpn.replaceAtMatchingUsages(replaceWith, usage -> {
                if (merge.isPhiAtMerge(usage)) {
                    return false;
                }
                if (usage instanceof VirtualState) {
                    VirtualState stateUsage = (VirtualState) usage;
                    if (finalExitState != null && finalExitState.isPartOfThisState(stateUsage)) {
                        return false;
                    }
                }
                return true;
            });
        }
    }
}
Also used : GuardProxyNode(org.graalvm.compiler.nodes.GuardProxyNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) GuardProxyNode(org.graalvm.compiler.nodes.GuardProxyNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) GuardProxyNode(org.graalvm.compiler.nodes.GuardProxyNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) FrameState(org.graalvm.compiler.nodes.FrameState) VirtualState(org.graalvm.compiler.nodes.VirtualState) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) EndNode(org.graalvm.compiler.nodes.EndNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Aggregations

ProxyNode (org.graalvm.compiler.nodes.ProxyNode)5 ValueProxyNode (org.graalvm.compiler.nodes.ValueProxyNode)5 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)2 Node (org.graalvm.compiler.graph.Node)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 EndNode (org.graalvm.compiler.nodes.EndNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 FrameState (org.graalvm.compiler.nodes.FrameState)1 GuardNode (org.graalvm.compiler.nodes.GuardNode)1 GuardPhiNode (org.graalvm.compiler.nodes.GuardPhiNode)1 GuardProxyNode (org.graalvm.compiler.nodes.GuardProxyNode)1 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)1 MergeNode (org.graalvm.compiler.nodes.MergeNode)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)1 VirtualState (org.graalvm.compiler.nodes.VirtualState)1 MonitorEnterNode (org.graalvm.compiler.nodes.java.MonitorEnterNode)1