Search in sources :

Example 1 with MemoryProxyNode

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

the class ScheduleVerification 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);
            }
        }
    }
    if (beginNode instanceof LoopExitNode) {
        LoopExitNode loopExitNode = (LoopExitNode) beginNode;
        for (ProxyNode proxy : loopExitNode.proxies()) {
            if (proxy instanceof MemoryProxyNode) {
                MemoryProxyNode memoryProxyNode = (MemoryProxyNode) proxy;
                addFloatingReadUsages(currentState, memoryProxyNode);
            }
        }
    }
    for (Node n : blockToNodesMap.get(block)) {
        if (n instanceof MemoryKill) {
            if (n instanceof SingleMemoryKill) {
                SingleMemoryKill single = (SingleMemoryKill) n;
                processLocation(n, single.getKilledLocationIdentity(), currentState);
            } else if (n instanceof MultiMemoryKill) {
                MultiMemoryKill multi = (MultiMemoryKill) n;
                for (LocationIdentity location : multi.getKilledLocationIdentities()) {
                    processLocation(n, location, currentState);
                }
            }
            addFloatingReadUsages(currentState, n);
        } else if (n instanceof MemoryAccess) {
            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));
                }
            }
        }
        assert nodeMap.get(n) == block;
        if (graph.isBeforeStage(StageFlag.VALUE_PROXY_REMOVAL) && block.getLoop() != null && !(n instanceof VirtualState)) {
            for (Node usage : n.usages()) {
                Node usageNode = usage;
                if (usageNode instanceof PhiNode) {
                    PhiNode phiNode = (PhiNode) usage;
                    usageNode = phiNode.merge();
                }
                if (usageNode instanceof LoopExitNode) {
                    LoopExitNode loopExitNode = (LoopExitNode) usageNode;
                    if (loopExitNode.loopBegin() == n || loopExitNode.stateAfter() == n) {
                        continue;
                    }
                }
                Block usageBlock = nodeMap.get(usageNode);
                if (usageBlock == null) {
                    if (usage instanceof FloatingNode || usage instanceof VirtualState || usage instanceof CallTargetNode) {
                        if (!(usage instanceof GuardNode)) {
                            /*
                                 * We do not want to run the schedule behind the verification with
                                 * dead code elimination, i.e., floating nodes without usages are
                                 * not removed, thus we must handle the case that a floating node
                                 * without a usage occurs here.
                                 */
                            if (nonFixedNodeTreeWithoutUsages(usage)) {
                                continue;
                            }
                        }
                    }
                }
                assert usageBlock != null || usage instanceof ProxyNode : "Usage " + usageNode + " of node " + n + " has no block";
                Loop<Block> usageLoop = null;
                if (usageNode instanceof ProxyNode) {
                    ProxyNode proxyNode = (ProxyNode) usageNode;
                    usageLoop = nodeMap.get(proxyNode.proxyPoint().loopBegin()).getLoop();
                } else {
                    if (usageBlock.getBeginNode() instanceof LoopExitNode) {
                        // For nodes in the loop exit node block, we don't know for sure
                        // whether they are "in the loop" or not. It depends on whether
                        // one of their transient usages is a loop proxy node.
                        // For now, let's just assume those nodes are OK, i.e., "in the loop".
                        LoopExitNode loopExitNode = (LoopExitNode) usageBlock.getBeginNode();
                        usageLoop = nodeMap.get(loopExitNode.loopBegin()).getLoop();
                    } else {
                        usageLoop = usageBlock.getLoop();
                    }
                }
                assert usageLoop != null : n + ", " + nodeMap.get(n) + " / " + usageNode + ", " + nodeMap.get(usageNode);
                while (usageLoop != block.getLoop() && usageLoop != null) {
                    usageLoop = usageLoop.getParent();
                }
                assert usageLoop != null : n + ", " + usageNode + ", " + usageBlock + ", " + usageBlock.getLoop() + ", " + block + ", " + block.getLoop();
            }
        }
    }
    return currentState;
}
Also used : MemoryProxyNode(org.graalvm.compiler.nodes.MemoryProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) SingleMemoryKill(org.graalvm.compiler.nodes.memory.SingleMemoryKill) MultiMemoryKill(org.graalvm.compiler.nodes.memory.MultiMemoryKill) MemoryKill(org.graalvm.compiler.nodes.memory.MemoryKill) MemoryProxyNode(org.graalvm.compiler.nodes.MemoryProxyNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) MemoryProxyNode(org.graalvm.compiler.nodes.MemoryProxyNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) VirtualState(org.graalvm.compiler.nodes.VirtualState) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) MultiMemoryKill(org.graalvm.compiler.nodes.memory.MultiMemoryKill) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) LocationIdentity(org.graalvm.word.LocationIdentity) Block(org.graalvm.compiler.nodes.cfg.Block) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryAccess(org.graalvm.compiler.nodes.memory.MemoryAccess) SingleMemoryKill(org.graalvm.compiler.nodes.memory.SingleMemoryKill) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode)

Aggregations

Node (org.graalvm.compiler.graph.Node)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)1 GuardNode (org.graalvm.compiler.nodes.GuardNode)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)1 MemoryProxyNode (org.graalvm.compiler.nodes.MemoryProxyNode)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)1 VirtualState (org.graalvm.compiler.nodes.VirtualState)1 FloatingNode (org.graalvm.compiler.nodes.calc.FloatingNode)1 Block (org.graalvm.compiler.nodes.cfg.Block)1 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)1 MemoryAccess (org.graalvm.compiler.nodes.memory.MemoryAccess)1 MemoryKill (org.graalvm.compiler.nodes.memory.MemoryKill)1 MemoryPhiNode (org.graalvm.compiler.nodes.memory.MemoryPhiNode)1 MultiMemoryKill (org.graalvm.compiler.nodes.memory.MultiMemoryKill)1 SingleMemoryKill (org.graalvm.compiler.nodes.memory.SingleMemoryKill)1 LocationIdentity (org.graalvm.word.LocationIdentity)1