Search in sources :

Example 1 with MemoryPhiNode

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

the class FloatingReadPhase method mergeMemoryMaps.

public static MemoryMapImpl mergeMemoryMaps(AbstractMergeNode merge, List<? extends MemoryMap> states) {
    MemoryMapImpl newState = new MemoryMapImpl();
    EconomicSet<LocationIdentity> keys = EconomicSet.create(Equivalence.DEFAULT);
    for (MemoryMap other : states) {
        keys.addAll(other.getLocations());
    }
    assert checkNoImmutableLocations(keys);
    for (LocationIdentity key : keys) {
        int mergedStatesCount = 0;
        boolean isPhi = false;
        MemoryNode merged = null;
        for (MemoryMap state : states) {
            MemoryNode last = state.getLastLocationAccess(key);
            if (isPhi) {
                ((MemoryPhiNode) merged).addInput(ValueNodeUtil.asNode(last));
            } else {
                if (merged == last) {
                // nothing to do
                } else if (merged == null) {
                    merged = last;
                } else {
                    MemoryPhiNode phi = merge.graph().addWithoutUnique(new MemoryPhiNode(merge, key));
                    for (int j = 0; j < mergedStatesCount; j++) {
                        phi.addInput(ValueNodeUtil.asNode(merged));
                    }
                    phi.addInput(ValueNodeUtil.asNode(last));
                    merged = phi;
                    isPhi = true;
                }
            }
            mergedStatesCount++;
        }
        newState.lastMemorySnapshot.put(key, merged);
    }
    return newState;
}
Also used : MemoryMap(org.graalvm.compiler.nodes.memory.MemoryMap) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) LocationIdentity(org.graalvm.word.LocationIdentity) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint)

Example 2 with MemoryPhiNode

use of org.graalvm.compiler.nodes.memory.MemoryPhiNode 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)

Aggregations

MemoryCheckpoint (org.graalvm.compiler.nodes.memory.MemoryCheckpoint)2 MemoryNode (org.graalvm.compiler.nodes.memory.MemoryNode)2 MemoryPhiNode (org.graalvm.compiler.nodes.memory.MemoryPhiNode)2 LocationIdentity (org.graalvm.word.LocationIdentity)2 Node (org.graalvm.compiler.graph.Node)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)1 MemoryMap (org.graalvm.compiler.nodes.memory.MemoryMap)1