Search in sources :

Example 56 with FixedNode

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

the class ControlFlowGraph method identifyBlocks.

/**
 * Identify and connect blocks (including loop backward edges). Predecessors need to be in the
 * order expected when iterating phi inputs.
 */
private void identifyBlocks() {
    // Find all block headers.
    int numBlocks = 0;
    for (AbstractBeginNode begin : graph.getNodes(AbstractBeginNode.TYPE)) {
        Block block = new Block(begin);
        identifyBlock(block);
        numBlocks++;
    }
    // Compute reverse post order.
    int count = 0;
    NodeMap<Block> nodeMap = this.nodeToBlock;
    Block[] stack = new Block[numBlocks];
    int tos = 0;
    Block startBlock = blockFor(graph.start());
    stack[0] = startBlock;
    startBlock.setPredecessors(Block.EMPTY_ARRAY);
    do {
        Block block = stack[tos];
        int id = block.getId();
        if (id == BLOCK_ID_INITIAL) {
            // First time we see this block: push all successors.
            FixedNode last = block.getEndNode();
            if (last instanceof EndNode) {
                EndNode endNode = (EndNode) last;
                Block suxBlock = nodeMap.get(endNode.merge());
                if (suxBlock.getId() == BLOCK_ID_INITIAL) {
                    stack[++tos] = suxBlock;
                }
                block.setSuccessors(new Block[] { suxBlock });
            } else if (last instanceof IfNode) {
                IfNode ifNode = (IfNode) last;
                Block trueSucc = nodeMap.get(ifNode.trueSuccessor());
                stack[++tos] = trueSucc;
                Block falseSucc = nodeMap.get(ifNode.falseSuccessor());
                stack[++tos] = falseSucc;
                block.setSuccessors(new Block[] { trueSucc, falseSucc });
                Block[] ifPred = new Block[] { block };
                trueSucc.setPredecessors(ifPred);
                falseSucc.setPredecessors(ifPred);
            } else if (last instanceof LoopEndNode) {
                LoopEndNode loopEndNode = (LoopEndNode) last;
                block.setSuccessors(new Block[] { nodeMap.get(loopEndNode.loopBegin()) });
            // Nothing to do push onto the stack.
            } else if (last instanceof ControlSinkNode) {
                block.setSuccessors(Block.EMPTY_ARRAY);
            } else {
                assert !(last instanceof AbstractEndNode) : "Algorithm only supports EndNode and LoopEndNode.";
                int startTos = tos;
                Block[] ifPred = new Block[] { block };
                for (Node suxNode : last.successors()) {
                    Block sux = nodeMap.get(suxNode);
                    stack[++tos] = sux;
                    sux.setPredecessors(ifPred);
                }
                int suxCount = tos - startTos;
                Block[] successors = new Block[suxCount];
                System.arraycopy(stack, startTos + 1, successors, 0, suxCount);
                block.setSuccessors(successors);
            }
            block.setId(BLOCK_ID_VISITED);
            AbstractBeginNode beginNode = block.getBeginNode();
            if (beginNode instanceof LoopBeginNode) {
                computeLoopPredecessors(nodeMap, block, (LoopBeginNode) beginNode);
            } else if (beginNode instanceof MergeNode) {
                MergeNode mergeNode = (MergeNode) beginNode;
                int forwardEndCount = mergeNode.forwardEndCount();
                Block[] predecessors = new Block[forwardEndCount];
                for (int i = 0; i < forwardEndCount; ++i) {
                    predecessors[i] = nodeMap.get(mergeNode.forwardEndAt(i));
                }
                block.setPredecessors(predecessors);
            }
        } else if (id == BLOCK_ID_VISITED) {
            // Second time we see this block: All successors have been processed, so add block
            // to result list. Can safely reuse the stack for this.
            --tos;
            count++;
            int index = numBlocks - count;
            stack[index] = block;
            block.setId(index);
        } else {
            throw GraalError.shouldNotReachHere();
        }
    } while (tos >= 0);
    // Compute reverse postorder and number blocks.
    assert count == numBlocks : "all blocks must be reachable";
    this.reversePostOrder = stack;
}
Also used : ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode)

Example 57 with FixedNode

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

the class ControlFlowGraph method identifyBlock.

private void identifyBlock(Block block) {
    FixedWithNextNode cur = block.getBeginNode();
    while (true) {
        assert !cur.isDeleted();
        assert nodeToBlock.get(cur) == null;
        nodeToBlock.set(cur, block);
        FixedNode next = cur.next();
        if (next instanceof AbstractBeginNode) {
            block.endNode = cur;
            return;
        } else if (next instanceof FixedWithNextNode) {
            cur = (FixedWithNextNode) next;
        } else {
            nodeToBlock.set(next, block);
            block.endNode = next;
            return;
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 58 with FixedNode

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

the class ValueAnchorNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    while (next() instanceof ValueAnchorNode) {
        ValueAnchorNode nextAnchor = (ValueAnchorNode) next();
        if (nextAnchor.anchored == anchored || nextAnchor.anchored == null) {
            // two anchors for the same anchored -> coalesce
            // nothing anchored on the next anchor -> coalesce
            nextAnchor.replaceAtUsages(this);
            GraphUtil.removeFixedWithUnusedInputs(nextAnchor);
        } else {
            break;
        }
    }
    if (tool.allUsagesAvailable() && hasNoUsages() && next() instanceof FixedAccessNode) {
        FixedAccessNode currentNext = (FixedAccessNode) next();
        if (currentNext.getGuard() == anchored) {
            GraphUtil.removeFixedWithUnusedInputs(this);
            return;
        }
    }
    if (anchored != null && (anchored.isConstant() || anchored instanceof FixedNode)) {
        // anchoring fixed nodes and constants is useless
        removeAnchoredNode();
    }
    if (anchored == null && hasNoUsages()) {
        // anchor is not necessary any more => remove.
        GraphUtil.removeFixedWithUnusedInputs(this);
    }
}
Also used : FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 59 with FixedNode

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

the class FarReturnLoweredNode method lower.

@Override
public void lower(LoweringTool tool) {
    FixedNode originalNext = next();
    replaceFirstSuccessor(originalNext, null);
    GraphUtil.killCFG(originalNext);
    replaceAtPredecessor(graph().add(new FarReturnLoweredNode(result, sp, ip)));
    safeDelete();
}
Also used : FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 60 with FixedNode

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

the class DefaultHotSpotLoweringProvider method lowerComputeObjectAddressNode.

private static void lowerComputeObjectAddressNode(ComputeObjectAddressNode n) {
    /*
         * Lower the node into a ComputeObjectAddress node and an Add but ensure that it's below any
         * potential safepoints and above it's uses.
         */
    for (Node use : n.usages().snapshot()) {
        if (use instanceof FixedNode) {
            FixedNode fixed = (FixedNode) use;
            StructuredGraph graph = n.graph();
            GetObjectAddressNode address = graph.add(new GetObjectAddressNode(n.getObject()));
            graph.addBeforeFixed(fixed, address);
            AddNode add = graph.addOrUnique(new AddNode(address, n.getOffset()));
            use.replaceFirstInput(n, add);
        } else {
            throw GraalError.shouldNotReachHere("Unexpected floating use of ComputeObjectAddressNode " + n);
        }
    }
    GraphUtil.unlinkFixedNode(n);
    n.safeDelete();
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) OSRLocalNode(org.graalvm.compiler.nodes.extended.OSRLocalNode) RawMonitorEnterNode(org.graalvm.compiler.nodes.java.RawMonitorEnterNode) AbstractDeoptimizeNode(org.graalvm.compiler.nodes.AbstractDeoptimizeNode) StringToBytesNode(org.graalvm.compiler.nodes.debug.StringToBytesNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) LoadExceptionObjectNode(org.graalvm.compiler.nodes.java.LoadExceptionObjectNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoadMethodNode(org.graalvm.compiler.nodes.extended.LoadMethodNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) BeginLockScopeNode(org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) IdentityHashCodeNode(org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) HotSpotDirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) VerifyHeapNode(org.graalvm.compiler.nodes.debug.VerifyHeapNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) ArrayCopyWithSlowPathNode(org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyWithSlowPathNode) KlassLayoutHelperNode(org.graalvm.compiler.hotspot.replacements.KlassLayoutHelperNode) ClassGetHubNode(org.graalvm.compiler.hotspot.replacements.ClassGetHubNode) HotSpotCompressionNode(org.graalvm.compiler.hotspot.nodes.HotSpotCompressionNode) OSRLockNode(org.graalvm.compiler.nodes.extended.OSRLockNode) AssertionNode(org.graalvm.compiler.replacements.nodes.AssertionNode) IntegerDivRemNode(org.graalvm.compiler.nodes.calc.IntegerDivRemNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) ProfileNode(org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) HotSpotIndirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode) ArrayCopyNode(org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyNode) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) OSRMonitorEnterNode(org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) StoreHubNode(org.graalvm.compiler.nodes.extended.StoreHubNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) StartNode(org.graalvm.compiler.nodes.StartNode) RemNode(org.graalvm.compiler.nodes.calc.RemNode) ClassIsAssignableFromNode(org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) InstanceOfDynamicNode(org.graalvm.compiler.nodes.java.InstanceOfDynamicNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ComputeObjectAddressNode(org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) GuardedUnsafeLoadNode(org.graalvm.compiler.nodes.extended.GuardedUnsafeLoadNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) BytecodeExceptionNode(org.graalvm.compiler.nodes.extended.BytecodeExceptionNode) Node(org.graalvm.compiler.graph.Node) FixedNode(org.graalvm.compiler.nodes.FixedNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)

Aggregations

FixedNode (org.graalvm.compiler.nodes.FixedNode)87 Node (org.graalvm.compiler.graph.Node)41 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)41 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)39 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)39 ValueNode (org.graalvm.compiler.nodes.ValueNode)34 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)33 EndNode (org.graalvm.compiler.nodes.EndNode)27 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)25 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)23 PhiNode (org.graalvm.compiler.nodes.PhiNode)22 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)21 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)21 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)20 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)17 MergeNode (org.graalvm.compiler.nodes.MergeNode)17 StartNode (org.graalvm.compiler.nodes.StartNode)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)16 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)13 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)13