Search in sources :

Example 6 with ControlSplitNode

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

the class LoopTransformations method unswitch.

public static void unswitch(LoopEx loop, List<ControlSplitNode> controlSplitNodeSet) {
    ControlSplitNode firstNode = controlSplitNodeSet.iterator().next();
    LoopFragmentWhole originalLoop = loop.whole();
    StructuredGraph graph = firstNode.graph();
    loop.loopBegin().incrementUnswitches();
    // create new control split out of loop
    ControlSplitNode newControlSplit = (ControlSplitNode) firstNode.copyWithInputs();
    originalLoop.entryPoint().replaceAtPredecessor(newControlSplit);
    /*
         * The code below assumes that all of the control split nodes have the same successor
         * structure, which should have been enforced by findUnswitchable.
         */
    Iterator<Position> successors = firstNode.successorPositions().iterator();
    assert successors.hasNext();
    // original loop is used as first successor
    Position firstPosition = successors.next();
    AbstractBeginNode originalLoopBegin = BeginNode.begin(originalLoop.entryPoint());
    firstPosition.set(newControlSplit, originalLoopBegin);
    while (successors.hasNext()) {
        Position position = successors.next();
        // create a new loop duplicate and connect it.
        LoopFragmentWhole duplicateLoop = originalLoop.duplicate();
        AbstractBeginNode newBegin = BeginNode.begin(duplicateLoop.entryPoint());
        position.set(newControlSplit, newBegin);
        // For each cloned ControlSplitNode, simplify the proper path
        for (ControlSplitNode controlSplitNode : controlSplitNodeSet) {
            ControlSplitNode duplicatedControlSplit = duplicateLoop.getDuplicatedNode(controlSplitNode);
            if (duplicatedControlSplit.isAlive()) {
                AbstractBeginNode survivingSuccessor = (AbstractBeginNode) position.get(duplicatedControlSplit);
                survivingSuccessor.replaceAtUsages(InputType.Guard, newBegin);
                graph.removeSplitPropagate(duplicatedControlSplit, survivingSuccessor);
            }
        }
    }
    // original loop is simplified last to avoid deleting controlSplitNode too early
    for (ControlSplitNode controlSplitNode : controlSplitNodeSet) {
        if (controlSplitNode.isAlive()) {
            AbstractBeginNode survivingSuccessor = (AbstractBeginNode) firstPosition.get(controlSplitNode);
            survivingSuccessor.replaceAtUsages(InputType.Guard, originalLoopBegin);
            graph.removeSplitPropagate(controlSplitNode, survivingSuccessor);
        }
    }
// TODO (gd) probabilities need some amount of fixup.. (probably also in other transforms)
}
Also used : LoopFragmentWhole(org.graalvm.compiler.loop.LoopFragmentWhole) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Position(org.graalvm.compiler.graph.Position) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 7 with ControlSplitNode

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

the class BinaryGraphPrinter method nodeProperties.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void nodeProperties(GraphInfo info, Node node, Map<String, Object> props) {
    node.getDebugProperties((Map) props);
    Graph graph = info.graph;
    ControlFlowGraph cfg = info.cfg;
    NodeMap<Block> nodeToBlocks = info.nodeToBlocks;
    if (cfg != null && DebugOptions.PrintGraphProbabilities.getValue(graph.getOptions()) && node instanceof FixedNode) {
        try {
            props.put("probability", cfg.blockFor(node).probability());
        } catch (Throwable t) {
            props.put("probability", 0.0);
            props.put("probability-exception", t);
        }
    }
    try {
        props.put("NodeCost-Size", node.estimatedNodeSize());
        props.put("NodeCost-Cycles", node.estimatedNodeCycles());
    } catch (Throwable t) {
        props.put("node-cost-exception", t.getMessage());
    }
    if (nodeToBlocks != null) {
        Object block = getBlockForNode(node, nodeToBlocks);
        if (block != null) {
            props.put("node-to-block", block);
        }
    }
    if (node instanceof ControlSinkNode) {
        props.put("category", "controlSink");
    } else if (node instanceof ControlSplitNode) {
        props.put("category", "controlSplit");
    } else if (node instanceof AbstractMergeNode) {
        props.put("category", "merge");
    } else if (node instanceof AbstractBeginNode) {
        props.put("category", "begin");
    } else if (node instanceof AbstractEndNode) {
        props.put("category", "end");
    } else if (node instanceof FixedNode) {
        props.put("category", "fixed");
    } else if (node instanceof VirtualState) {
        props.put("category", "state");
    } else if (node instanceof PhiNode) {
        props.put("category", "phi");
    } else if (node instanceof ProxyNode) {
        props.put("category", "proxy");
    } else {
        if (node instanceof ConstantNode) {
            ConstantNode cn = (ConstantNode) node;
            updateStringPropertiesForConstant((Map) props, cn);
        }
        props.put("category", "floating");
    }
    if (getSnippetReflectionProvider() != null) {
        for (Map.Entry<String, Object> prop : props.entrySet()) {
            if (prop.getValue() instanceof JavaConstantFormattable) {
                props.put(prop.getKey(), ((JavaConstantFormattable) prop.getValue()).format(this));
            }
        }
    }
}
Also used : ProxyNode(org.graalvm.compiler.nodes.ProxyNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) VirtualState(org.graalvm.compiler.nodes.VirtualState) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) Graph(org.graalvm.compiler.graph.Graph) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CachedGraph(org.graalvm.compiler.graph.CachedGraph) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) Block(org.graalvm.compiler.nodes.cfg.Block) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) Map(java.util.Map) NodeMap(org.graalvm.compiler.graph.NodeMap) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) JavaConstantFormattable(org.graalvm.compiler.nodes.util.JavaConstantFormattable)

Example 8 with ControlSplitNode

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

the class PostOrderNodeIterator method apply.

public void apply() {
    FixedNode current = start;
    do {
        if (current instanceof InvokeWithExceptionNode) {
            invoke((Invoke) current);
            queueSuccessors(current, null);
            current = nextQueuedNode();
        } else if (current instanceof LoopBeginNode) {
            state.loopBegin((LoopBeginNode) current);
            nodeStates.put(current, state);
            state = state.clone();
            loopBegin((LoopBeginNode) current);
            current = ((LoopBeginNode) current).next();
            assert current != null;
        } else if (current instanceof LoopEndNode) {
            loopEnd((LoopEndNode) current);
            finishLoopEnds((LoopEndNode) current);
            current = nextQueuedNode();
        } else if (current instanceof AbstractMergeNode) {
            merge((AbstractMergeNode) current);
            current = ((AbstractMergeNode) current).next();
            assert current != null;
        } else if (current instanceof FixedWithNextNode) {
            FixedNode next = ((FixedWithNextNode) current).next();
            assert next != null : current;
            node(current);
            current = next;
        } else if (current instanceof EndNode) {
            end((EndNode) current);
            queueMerge((EndNode) current);
            current = nextQueuedNode();
        } else if (current instanceof ControlSinkNode) {
            node(current);
            current = nextQueuedNode();
        } else if (current instanceof ControlSplitNode) {
            Set<Node> successors = controlSplit((ControlSplitNode) current);
            queueSuccessors(current, successors);
            current = nextQueuedNode();
        } else {
            assert false : current;
        }
    } while (current != null);
    finished();
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) Set(java.util.Set) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Example 9 with ControlSplitNode

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

the class ComputeInliningRelevance method computeFastPathMinProbability.

/**
 * Computes the minimum probability along the most probable path within the scope. During
 * iteration, the method returns immediately once a loop exit is discovered.
 */
private double computeFastPathMinProbability(FixedNode scopeStart) {
    ArrayList<FixedNode> pathBeginNodes = new ArrayList<>();
    pathBeginNodes.add(scopeStart);
    double minPathProbability = nodeProbabilities.applyAsDouble(scopeStart);
    boolean isLoopScope = scopeStart instanceof LoopBeginNode;
    do {
        Node current = pathBeginNodes.remove(pathBeginNodes.size() - 1);
        do {
            if (isLoopScope && current instanceof LoopExitNode && ((LoopBeginNode) scopeStart).loopExits().contains((LoopExitNode) current)) {
                return minPathProbability;
            } else if (current instanceof LoopBeginNode && current != scopeStart) {
                current = getMaxProbabilityLoopExit((LoopBeginNode) current, pathBeginNodes);
                minPathProbability = getMinPathProbability((FixedNode) current, minPathProbability);
            } else if (current instanceof ControlSplitNode) {
                current = getMaxProbabilitySux((ControlSplitNode) current, pathBeginNodes);
                minPathProbability = getMinPathProbability((FixedNode) current, minPathProbability);
            } else {
                assert current.successors().count() <= 1;
                current = current.successors().first();
            }
        } while (current != null);
    } while (!pathBeginNodes.isEmpty());
    return minPathProbability;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ArrayList(java.util.ArrayList) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 10 with ControlSplitNode

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

the class FixedNodeProbabilityCache method findBegin.

private static FixedNode findBegin(FixedNode node) {
    FixedNode current = node;
    while (true) {
        assert current != null;
        Node predecessor = current.predecessor();
        if (current instanceof AbstractBeginNode) {
            if (predecessor == null) {
                break;
            } else if (predecessor.successors().count() != 1) {
                assert predecessor instanceof ControlSplitNode : "a FixedNode with multiple successors needs to be a ControlSplitNode: " + current + " / " + predecessor;
                break;
            }
        } else if (predecessor == null) {
            current = null;
            break;
        }
        current = (FixedNode) predecessor;
    }
    return current;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)21 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)15 FixedNode (org.graalvm.compiler.nodes.FixedNode)15 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)13 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)11 Node (org.graalvm.compiler.graph.Node)10 EndNode (org.graalvm.compiler.nodes.EndNode)10 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)10 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)9 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)8 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)7 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)5 MergeNode (org.graalvm.compiler.nodes.MergeNode)5 StartNode (org.graalvm.compiler.nodes.StartNode)5 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)3 ArrayList (java.util.ArrayList)2 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)2