Search in sources :

Example 1 with EconomicSetNodeEventListener

use of org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener in project graal by oracle.

the class GraphChangeMonitoringPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, C context) {
    /*
         * Phase may add nodes but not end up using them so ignore additions. Nodes going dead and
         * having their inputs change are the main interesting differences.
         */
    EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener().exclude(NodeEvent.NODE_ADDED);
    StructuredGraph graphCopy = (StructuredGraph) graph.copy(graph.getDebug());
    DebugContext debug = graph.getDebug();
    try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) {
        try (DebugContext.Scope s2 = debug.sandbox("WithoutMonitoring", null)) {
            super.run(graphCopy, context);
        } catch (Throwable t) {
            debug.handle(t);
        }
    }
    EconomicSet<Node> filteredNodes = EconomicSet.create(Equivalence.IDENTITY);
    for (Node n : listener.getNodes()) {
        if (n instanceof LogicConstantNode) {
        // Ignore LogicConstantNode since those are sometimes created and deleted as part of
        // running a phase.
        } else {
            filteredNodes.add(n);
        }
    }
    if (!filteredNodes.isEmpty()) {
        /* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */
        listener = new EconomicSetNodeEventListener();
        try (NodeEventScope s = graph.trackNodeEvents(listener)) {
            try (DebugContext.Scope s2 = debug.scope("WithGraphChangeMonitoring")) {
                if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
                    debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** Before phase %s", getName());
                }
                super.run(graph, context);
                if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
                    debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** After phase %s %s", getName(), filteredNodes);
                }
                debug.log("*** %s %s %s\n", message, graph, filteredNodes);
            }
        }
    } else {
        // Go ahead and run it normally even though it should have no effect
        super.run(graph, context);
    }
}
Also used : NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) Node(org.graalvm.compiler.graph.Node) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) DebugContext(org.graalvm.compiler.debug.DebugContext) EconomicSetNodeEventListener(org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener)

Example 2 with EconomicSetNodeEventListener

use of org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener in project graal by oracle.

the class ReassociationPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, CoreProviders context) {
    EconomicSetNodeEventListener changedNodes = new EconomicSetNodeEventListener(EnumSet.of(NodeEvent.NODE_ADDED));
    try (NodeEventScope news = graph.trackNodeEvents(changedNodes)) {
        prepareGraphForReassociation(graph);
        reassociateConstants(graph, context);
        reassociateInvariants(graph, context);
    }
    canonicalizer.applyIncremental(graph, context, changedNodes.getNodes());
}
Also used : NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) EconomicSetNodeEventListener(org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener)

Example 3 with EconomicSetNodeEventListener

use of org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener in project graal by oracle.

the class ReassociationPhase method prepareGraphForReassociation.

/**
 * Prepare the given graph for reassociation: This means rewriting shift nodes back to
 * multiplication nodes if possible. Left shift is not an associative operation, thus we rewrite
 * all shifts derived from multiplications back to their multiplications and try to re-associate
 * them.
 */
@SuppressWarnings("try")
private static void prepareGraphForReassociation(StructuredGraph graph) {
    final DebugContext debug = graph.getDebug();
    EconomicSetNodeEventListener nev = new EconomicSetNodeEventListener(EnumSet.of(NodeEvent.NODE_ADDED));
    try (NodeEventScope news = graph.trackNodeEvents(nev)) {
        for (LeftShiftNode l : graph.getNodes().filter(LeftShiftNode.class)) {
            l.tryReplaceWithMulNode();
        }
    }
    debug.dump(DebugContext.VERY_DETAILED_LEVEL, graph, "Reassociation: after creating mul nodes from shifts");
    for (Node newNode : nev.getNodes()) {
        if (newNode instanceof MulNode) {
            assert ((MulNode) newNode).getY().isConstant();
            MulNode mul = (MulNode) newNode;
            for (Node usage : newNode.usages()) {
                if (usage instanceof AddNode) {
                    if (((BinaryArithmeticNode<?>) usage).getX() == mul.getX() && ((BinaryArithmeticNode<?>) usage).getY() == mul || ((BinaryArithmeticNode<?>) usage).getY() == mul.getX() && ((BinaryArithmeticNode<?>) usage).getX() == mul) {
                        long i = ((PrimitiveConstant) mul.getY().asConstant()).asLong();
                        MulNode newMul = graph.addOrUnique(new MulNode(mul.getX(), ConstantNode.forIntegerStamp(mul.getY().stamp(NodeView.DEFAULT), i + 1, graph)));
                        usage.replaceAtUsages(newMul);
                    }
                } else if (usage instanceof SubNode) {
                    if (((BinaryArithmeticNode<?>) usage).getX() == mul && ((BinaryArithmeticNode<?>) usage).getY() == mul.getX()) {
                        long i = ((PrimitiveConstant) mul.getY().asConstant()).asLong();
                        MulNode newMul = graph.addOrUnique(new MulNode(mul.getX(), ConstantNode.forIntegerStamp(mul.getY().stamp(NodeView.DEFAULT), i - 1, graph)));
                        usage.replaceAtUsages(newMul);
                    }
                }
            }
        }
    }
    debug.dump(DebugContext.VERY_DETAILED_LEVEL, graph, "Reassociation: after creating mul from add/sub");
}
Also used : NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) SubNode(org.graalvm.compiler.nodes.calc.SubNode) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SubNode(org.graalvm.compiler.nodes.calc.SubNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) Node(org.graalvm.compiler.graph.Node) MulNode(org.graalvm.compiler.nodes.calc.MulNode) DebugContext(org.graalvm.compiler.debug.DebugContext) MulNode(org.graalvm.compiler.nodes.calc.MulNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) EconomicSetNodeEventListener(org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener)

Example 4 with EconomicSetNodeEventListener

use of org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener in project graal by oracle.

the class FloatingReadPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph) {
    EconomicSet<ValueNode> initMemory = EconomicSet.create(Equivalence.IDENTITY);
    EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops = null;
    if (graph.hasLoops()) {
        modifiedInLoops = EconomicMap.create(Equivalence.IDENTITY);
        ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
        for (Loop<?> l : cfg.getLoops()) {
            HIRLoop loop = (HIRLoop) l;
            processLoop(loop, modifiedInLoops);
        }
    }
    EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener(EnumSet.of(NODE_ADDED, ZERO_USAGES));
    try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
        ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops, createFloatingReads, createMemoryMapNodes, initMemory), graph.start(), new MemoryMapImpl(graph.start()));
    }
    for (Node n : removeExternallyUsedNodes(listener.getNodes())) {
        if (n.isAlive() && n instanceof FloatingNode) {
            n.replaceAtUsages(null);
            GraphUtil.killWithUnusedFloatingInputs(n);
        }
    }
    if (createFloatingReads) {
        assert graph.isBeforeStage(StageFlag.FLOATING_READS);
        graph.setAfterStage(StageFlag.FLOATING_READS);
    }
}
Also used : AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatableAccessNode(org.graalvm.compiler.nodes.memory.FloatableAccessNode) MemoryMapControlSinkNode(org.graalvm.compiler.nodes.MemoryMapControlSinkNode) FloatingAccessNode(org.graalvm.compiler.nodes.memory.FloatingAccessNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) EconomicSet(org.graalvm.collections.EconomicSet) HIRLoop(org.graalvm.compiler.nodes.cfg.HIRLoop) EconomicSetNodeEventListener(org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode)

Example 5 with EconomicSetNodeEventListener

use of org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener in project graal by oracle.

the class FixReadsPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, CoreProviders context) {
    assert graph.verify();
    schedulePhase.apply(graph, context);
    ScheduleResult schedule = graph.getLastSchedule();
    FixReadsClosure fixReadsClosure = new FixReadsClosure();
    EconomicSetNodeEventListener ec = new EconomicSetNodeEventListener();
    try (Graph.NodeEventScope scope = graph.trackNodeEvents(ec)) {
        for (Block block : schedule.getCFG().getBlocks()) {
            fixReadsClosure.processNodes(block, schedule);
        }
        assert graph.verify();
        if (GraalOptions.RawConditionalElimination.getValue(graph.getOptions())) {
            schedule.getCFG().visitDominatorTree(createVisitor(graph, schedule, context), false);
        }
    }
    graph.setAfterStage(StageFlag.FIXED_READS);
    if (!ec.getNodes().isEmpty()) {
        canonicalizerPhase.applyIncremental(graph, context, ec.getNodes());
    }
}
Also used : ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) Graph(org.graalvm.compiler.graph.Graph) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Block(org.graalvm.compiler.nodes.cfg.Block) EconomicSetNodeEventListener(org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener)

Aggregations

EconomicSetNodeEventListener (org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener)9 NodeEventScope (org.graalvm.compiler.graph.Graph.NodeEventScope)7 Node (org.graalvm.compiler.graph.Node)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 DebugContext (org.graalvm.compiler.debug.DebugContext)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 ControlFlowGraph (org.graalvm.compiler.nodes.cfg.ControlFlowGraph)3 Graph (org.graalvm.compiler.graph.Graph)2 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)2 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)2 FixedNode (org.graalvm.compiler.nodes.FixedNode)2 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)2 PhiNode (org.graalvm.compiler.nodes.PhiNode)2 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)2 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)2 AddNode (org.graalvm.compiler.nodes.calc.AddNode)2 OpaqueNode (org.graalvm.compiler.nodes.extended.OpaqueNode)2 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)1 EconomicSet (org.graalvm.collections.EconomicSet)1