Search in sources :

Example 16 with PhiNode

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

the class GraphOrder method assertNonCyclicGraph.

/**
 * Quick (and imprecise) assertion that there are no (invalid) cycles in the given graph. First,
 * an ordered list of all nodes in the graph (a total ordering) is created. A second run over
 * this list checks whether inputs are scheduled before their usages.
 *
 * @param graph the graph to be checked.
 * @throws AssertionError if a cycle was detected.
 */
public static boolean assertNonCyclicGraph(StructuredGraph graph) {
    List<Node> order = createOrder(graph);
    NodeBitMap visited = graph.createNodeBitMap();
    visited.clearAll();
    for (Node node : order) {
        if (node instanceof PhiNode && ((PhiNode) node).merge() instanceof LoopBeginNode) {
            assert visited.isMarked(((PhiNode) node).valueAt(0));
        // nothing to do
        } else {
            for (Node input : node.inputs()) {
                if (!visited.isMarked(input)) {
                    if (input instanceof FrameState) {
                    // nothing to do - frame states are known, allowed cycles
                    } else {
                        assert false : "unexpected cycle detected at input " + node + " -> " + input;
                    }
                }
            }
        }
        visited.mark(node);
    }
    return true;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) NodeBitMap(org.graalvm.compiler.graph.NodeBitMap) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 17 with PhiNode

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

the class MemoryScheduleVerification method processBlock.

@Override
protected EconomicSet<FloatingReadNode> processBlock(Block block, EconomicSet<FloatingReadNode> currentState) {
    AbstractBeginNode beginNode = block.getBeginNode();
    if (beginNode instanceof AbstractMergeNode) {
        AbstractMergeNode abstractMergeNode = (AbstractMergeNode) beginNode;
        for (PhiNode phi : abstractMergeNode.phis()) {
            if (phi instanceof MemoryPhiNode) {
                MemoryPhiNode memoryPhiNode = (MemoryPhiNode) phi;
                addFloatingReadUsages(currentState, memoryPhiNode);
            }
        }
    }
    for (Node n : blockToNodesMap.get(block)) {
        if (n instanceof MemoryCheckpoint) {
            if (n instanceof MemoryCheckpoint.Single) {
                MemoryCheckpoint.Single single = (MemoryCheckpoint.Single) n;
                processLocation(n, single.getLocationIdentity(), currentState);
            } else if (n instanceof MemoryCheckpoint.Multi) {
                MemoryCheckpoint.Multi multi = (MemoryCheckpoint.Multi) n;
                for (LocationIdentity location : multi.getLocationIdentities()) {
                    processLocation(n, location, currentState);
                }
            }
            addFloatingReadUsages(currentState, n);
        } else if (n instanceof MemoryNode) {
            addFloatingReadUsages(currentState, n);
        } else if (n instanceof FloatingReadNode) {
            FloatingReadNode floatingReadNode = (FloatingReadNode) n;
            if (floatingReadNode.getLastLocationAccess() != null && floatingReadNode.getLocationIdentity().isMutable()) {
                if (currentState.contains(floatingReadNode)) {
                    // Floating read was found in the state.
                    currentState.remove(floatingReadNode);
                } else {
                    throw new RuntimeException("Floating read node " + n + " was not found in the state, i.e., it was killed by a memory check point before its place in the schedule. Block=" + block + ", block begin: " + block.getBeginNode() + " block loop: " + block.getLoop() + ", " + blockToNodesMap.get(block).get(0));
                }
            }
        }
    }
    return currentState;
}
Also used : MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) LocationIdentity(org.graalvm.word.LocationIdentity)

Example 18 with PhiNode

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

the class PEReadEliminationClosure method processInitialLoopState.

@SuppressWarnings("unchecked")
@Override
protected void processInitialLoopState(Loop<Block> loop, PEReadEliminationBlockState initialState) {
    super.processInitialLoopState(loop, initialState);
    if (!initialState.getReadCache().isEmpty()) {
        EconomicMap<ValueNode, Pair<ValueNode, Object>> firstValueSet = null;
        for (PhiNode phi : ((LoopBeginNode) loop.getHeader().getBeginNode()).phis()) {
            ValueNode firstValue = phi.valueAt(0);
            if (firstValue != null && phi.getStackKind().isObject()) {
                ValueNode unproxified = GraphUtil.unproxify(firstValue);
                if (firstValueSet == null) {
                    firstValueSet = EconomicMap.create(Equivalence.IDENTITY_WITH_SYSTEM_HASHCODE);
                }
                Pair<ValueNode, Object> pair = Pair.create(unproxified, firstValueSet.get(unproxified));
                firstValueSet.put(unproxified, pair);
            }
        }
        if (firstValueSet != null) {
            ReadCacheEntry[] entries = new ReadCacheEntry[initialState.getReadCache().size()];
            int z = 0;
            for (ReadCacheEntry entry : initialState.getReadCache().getKeys()) {
                entries[z++] = entry;
            }
            for (ReadCacheEntry entry : entries) {
                ValueNode object = entry.object;
                if (object != null) {
                    Pair<ValueNode, Object> pair = firstValueSet.get(object);
                    while (pair != null) {
                        initialState.addReadCache(pair.getLeft(), entry.identity, entry.index, entry.kind, entry.overflowAccess, initialState.getReadCache().get(entry), this);
                        pair = (Pair<ValueNode, Object>) pair.getRight();
                    }
                }
            }
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) Pair(org.graalvm.collections.Pair)

Example 19 with PhiNode

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

the class PartialEscapeClosure method processInitialLoopState.

@Override
protected void processInitialLoopState(Loop<Block> loop, BlockT initialState) {
    for (PhiNode phi : ((LoopBeginNode) loop.getHeader().getBeginNode()).phis()) {
        if (phi.valueAt(0) != null) {
            ValueNode alias = getAliasAndResolve(initialState, phi.valueAt(0));
            if (alias instanceof VirtualObjectNode) {
                VirtualObjectNode virtual = (VirtualObjectNode) alias;
                addVirtualAlias(virtual, phi);
            } else {
                aliases.set(phi, null);
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 20 with PhiNode

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

the class StrengthenStampsPhase method run.

@Override
protected void run(StructuredGraph graph) {
    for (Node n : graph.getNodes()) {
        if (n instanceof ValueNode && !(n instanceof LimitedValueProxy) && !(n instanceof PhiNode)) {
            /*
                 * The stamp of proxy nodes and phi nodes is inferred automatically, so we do not
                 * need to improve them.
                 */
            ValueNode node = (ValueNode) n;
            /*
                 * First ask the node to improve the stamp itself, to incorporate already improved
                 * input stamps.
                 */
            node.inferStamp();
            Stamp newStamp = strengthen(node.stamp(NodeView.DEFAULT));
            if (newStamp != null) {
                node.setStamp(newStamp);
            }
        }
        if (n instanceof LoadFieldNode) {
            LoadFieldNode node = (LoadFieldNode) n;
            updateStamp(node, toHosted(node.field()).getFieldTypeProfile());
        } else if (n instanceof InstanceOfNode) {
            InstanceOfNode node = (InstanceOfNode) n;
            ObjectStamp newStamp = (ObjectStamp) strengthen(node.getCheckedStamp());
            if (newStamp != null) {
                node.strengthenCheckedStamp(newStamp);
            }
        } else if (n instanceof PiNode) {
            PiNode node = (PiNode) n;
            Stamp newStamp = strengthen(node.piStamp());
            if (newStamp != null) {
                node.strengthenPiStamp(newStamp);
            }
        }
    }
}
Also used : PhiNode(org.graalvm.compiler.nodes.PhiNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AssertStampNode(com.oracle.svm.hosted.nodes.AssertStampNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AssertTypeStateNode(com.oracle.svm.hosted.nodes.AssertTypeStateNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) PiNode(org.graalvm.compiler.nodes.PiNode) LimitedValueProxy(org.graalvm.compiler.nodes.spi.LimitedValueProxy) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode)

Aggregations

PhiNode (org.graalvm.compiler.nodes.PhiNode)41 ValueNode (org.graalvm.compiler.nodes.ValueNode)31 Node (org.graalvm.compiler.graph.Node)22 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)21 FixedNode (org.graalvm.compiler.nodes.FixedNode)21 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)19 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)18 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)17 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)15 EndNode (org.graalvm.compiler.nodes.EndNode)15 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)15 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)14 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)13 FrameState (org.graalvm.compiler.nodes.FrameState)10 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)10 MergeNode (org.graalvm.compiler.nodes.MergeNode)9 PiNode (org.graalvm.compiler.nodes.PiNode)9 BeginNode (org.graalvm.compiler.nodes.BeginNode)7