Search in sources :

Example 1 with MemoryAccess

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

the class ReferenceGetLoopTest method checkMidTierGraph.

@Override
protected void checkMidTierGraph(StructuredGraph graph) {
    final LoopsData loops = getDefaultMidTierContext().getLoopsDataProvider().getLoopsData(graph);
    boolean found = false;
    for (LoopEx loop : loops.loops()) {
        for (Node node : loop.inside().nodes()) {
            if (node instanceof MemoryAccess) {
                MemoryAccess access = (MemoryAccess) node;
                LocationIdentity location = access.getLocationIdentity();
                if (location instanceof FieldLocationIdentity) {
                    ResolvedJavaField field = ((FieldLocationIdentity) location).getField();
                    if (field.getName().equals("referent") && field.getDeclaringClass().equals(getMetaAccess().lookupJavaType(Reference.class))) {
                        found = true;
                    }
                }
            }
        }
    }
    if (!found) {
        assertTrue(false, "Reference.referent not found in loop: " + getCanonicalGraphString(graph, true, false));
    }
}
Also used : FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) LoopsData(org.graalvm.compiler.nodes.loop.LoopsData) LoopEx(org.graalvm.compiler.nodes.loop.LoopEx) Node(org.graalvm.compiler.graph.Node) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) LocationIdentity(org.graalvm.word.LocationIdentity) MemoryAccess(org.graalvm.compiler.nodes.memory.MemoryAccess) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 2 with MemoryAccess

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

Example 3 with MemoryAccess

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

the class InsertGuardFencesPhase method isBoundsCheckGuard.

private static boolean isBoundsCheckGuard(AbstractBeginNode beginNode) {
    if (!(beginNode.predecessor() instanceof IfNode)) {
        return false;
    }
    IfNode ifNode = (IfNode) beginNode.predecessor();
    AbstractBeginNode otherBegin;
    if (ifNode.trueSuccessor() == beginNode) {
        otherBegin = ifNode.falseSuccessor();
    } else {
        assert ifNode.falseSuccessor() == beginNode;
        otherBegin = ifNode.trueSuccessor();
    }
    if (otherBegin.next() instanceof DeoptimizeNode) {
        DeoptimizeNode deopt = (DeoptimizeNode) otherBegin.next();
        if (deopt.getReason() == DeoptimizationReason.BoundsCheckException && !hasMultipleGuardUsages(beginNode)) {
            return true;
        }
    } else if (otherBegin instanceof LoopExitNode && beginNode.usages().filter(MultiGuardNode.class).isNotEmpty() && !hasMultipleGuardUsages(beginNode)) {
        return true;
    }
    for (Node usage : beginNode.usages()) {
        for (Position pos : usage.inputPositions()) {
            if (pos.getInputType() == InputType.Guard && pos.get(usage) == beginNode) {
                if (usage instanceof PiNode) {
                    if (!((PiNode) usage).piStamp().equals(POSITIVE_ARRAY_INDEX_STAMP)) {
                        return false;
                    }
                } else if (usage instanceof MemoryAccess) {
                    if (!NamedLocationIdentity.isArrayLocation(((MemoryAccess) usage).getLocationIdentity())) {
                        return false;
                    }
                } else {
                    return false;
                }
                break;
            }
        }
    }
    return true;
}
Also used : LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Position(org.graalvm.compiler.graph.Position) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) MultiGuardNode(org.graalvm.compiler.nodes.extended.MultiGuardNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) MemoryAccess(org.graalvm.compiler.nodes.memory.MemoryAccess) IfNode(org.graalvm.compiler.nodes.IfNode) PiNode(org.graalvm.compiler.nodes.PiNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

Node (org.graalvm.compiler.graph.Node)3 MemoryAccess (org.graalvm.compiler.nodes.memory.MemoryAccess)3 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)2 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)2 LocationIdentity (org.graalvm.word.LocationIdentity)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 Position (org.graalvm.compiler.graph.Position)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)1 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)1 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 GuardNode (org.graalvm.compiler.nodes.GuardNode)1 IfNode (org.graalvm.compiler.nodes.IfNode)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 MemoryProxyNode (org.graalvm.compiler.nodes.MemoryProxyNode)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 PiNode (org.graalvm.compiler.nodes.PiNode)1 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)1 VirtualState (org.graalvm.compiler.nodes.VirtualState)1