Search in sources :

Example 1 with BlockMap

use of org.graalvm.compiler.core.common.cfg.BlockMap in project graal by oracle.

the class NodeCostUtil method computeGraphCycles.

@SuppressWarnings("try")
public static double computeGraphCycles(StructuredGraph graph, boolean fullSchedule) {
    Function<Block, Iterable<? extends Node>> blockToNodes;
    ControlFlowGraph cfg;
    if (fullSchedule) {
        SchedulePhase schedule = new SchedulePhase(SchedulePhase.SchedulingStrategy.LATEST_OUT_OF_LOOPS, true);
        schedule.apply(graph);
        cfg = graph.getLastSchedule().getCFG();
        blockToNodes = b -> graph.getLastSchedule().getBlockToNodesMap().get(b);
    } else {
        cfg = ControlFlowGraph.compute(graph, true, true, false, false);
        BlockMap<List<FixedNode>> nodes = new BlockMap<>(cfg);
        for (Block b : cfg.getBlocks()) {
            ArrayList<FixedNode> curNodes = new ArrayList<>();
            for (FixedNode node : b.getNodes()) {
                curNodes.add(node);
            }
            nodes.put(b, curNodes);
        }
        blockToNodes = b -> nodes.get(b);
    }
    double weightedCycles = 0D;
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope s = debug.scope("NodeCostSummary")) {
        for (Block block : cfg.getBlocks()) {
            for (Node n : blockToNodes.apply(block)) {
                double probWeighted = n.estimatedNodeCycles().value * block.probability();
                assert Double.isFinite(probWeighted);
                weightedCycles += probWeighted;
                if (debug.isLogEnabled()) {
                    debug.log("Node %s contributes cycles:%f size:%d to graph %s [block prob:%f]", n, n.estimatedNodeCycles().value * block.probability(), n.estimatedNodeSize().value, graph, block.probability());
                }
            }
        }
    }
    assert weightedCycles >= 0D;
    assert Double.isFinite(weightedCycles);
    return weightedCycles;
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) FixedNode(org.graalvm.compiler.nodes.FixedNode) Node(org.graalvm.compiler.graph.Node) ArrayList(java.util.ArrayList) FixedNode(org.graalvm.compiler.nodes.FixedNode) DebugContext(org.graalvm.compiler.debug.DebugContext) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) Block(org.graalvm.compiler.nodes.cfg.Block) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with BlockMap

use of org.graalvm.compiler.core.common.cfg.BlockMap in project graal by oracle.

the class ReplaceConstantNodesPhase method tryToReplaceWithExisting.

/**
 * Try to find dominating node doing the resolution that can be reused.
 *
 * @param graph
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private static void tryToReplaceWithExisting(StructuredGraph graph, ConstantNode node) {
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    BlockMap<List<Node>> blockToNodes = schedule.getBlockToNodesMap();
    EconomicMap<Block, Node> blockToExisting = EconomicMap.create();
    for (Node n : node.usages().filter(n -> isReplacementNode(n))) {
        blockToExisting.put(nodeToBlock.get(n), n);
    }
    for (Node use : node.usages().filter(n -> !isReplacementNode(n)).snapshot()) {
        boolean replaced = false;
        Block b = nodeToBlock.get(use);
        Node e = blockToExisting.get(b);
        if (e != null) {
            // the use is scheduled after it.
            for (Node n : blockToNodes.get(b)) {
                if (n.equals(use)) {
                    // Usage is before initialization, can't use it
                    break;
                }
                if (n.equals(e)) {
                    use.replaceFirstInput(node, e);
                    replaced = true;
                    break;
                }
            }
        }
        if (!replaced) {
            // Look for dominating blocks that have existing nodes
            for (Block d : blockToExisting.getKeys()) {
                if (strictlyDominates(d, b)) {
                    use.replaceFirstInput(node, blockToExisting.get(d));
                    break;
                }
            }
        }
    }
}
Also used : LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) Constant(jdk.vm.ci.meta.Constant) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) EconomicMap(org.graalvm.collections.EconomicMap) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) HotSpotConstantLoadAction(org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ReentrantNodeIterator(org.graalvm.compiler.phases.graph.ReentrantNodeIterator) NodeIteratorClosure(org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) BasePhase(org.graalvm.compiler.phases.BasePhase) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) SchedulingStrategy(org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) FrameState(org.graalvm.compiler.nodes.FrameState) ConstantNode.getConstantNodes(org.graalvm.compiler.nodes.ConstantNode.getConstantNodes) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) StateSplit(org.graalvm.compiler.nodes.StateSplit) LoadMethodCountersNode.getLoadMethodCountersNodes(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode.getLoadMethodCountersNodes) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) HashSet(java.util.HashSet) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) NodeMap(org.graalvm.compiler.graph.NodeMap) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) AbstractControlFlowGraph.strictlyDominates(org.graalvm.compiler.core.common.cfg.AbstractControlFlowGraph.strictlyDominates) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Block(org.graalvm.compiler.nodes.cfg.Block) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List)

Aggregations

List (java.util.List)2 BlockMap (org.graalvm.compiler.core.common.cfg.BlockMap)2 Node (org.graalvm.compiler.graph.Node)2 FixedNode (org.graalvm.compiler.nodes.FixedNode)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)1 HotSpotMetaspaceConstant (jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)1 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)1 HotSpotResolvedJavaType (jdk.vm.ci.hotspot.HotSpotResolvedJavaType)1 HotSpotResolvedObjectType (jdk.vm.ci.hotspot.HotSpotResolvedObjectType)1 Constant (jdk.vm.ci.meta.Constant)1 ConstantReflectionProvider (jdk.vm.ci.meta.ConstantReflectionProvider)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 EconomicMap (org.graalvm.collections.EconomicMap)1 AbstractControlFlowGraph.strictlyDominates (org.graalvm.compiler.core.common.cfg.AbstractControlFlowGraph.strictlyDominates)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1 StampFactory (org.graalvm.compiler.core.common.type.StampFactory)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1