Search in sources :

Example 1 with Simplifiable

use of org.graalvm.compiler.graph.spi.Simplifiable in project graal by oracle.

the class IterativeConditionalEliminationPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, PhaseContext context) {
    HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NODE_ADDED);
    int count = 0;
    while (true) {
        try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
            new ConditionalEliminationPhase(fullSchedule).apply(graph, context);
        }
        if (listener.getNodes().isEmpty()) {
            break;
        }
        for (Node node : graph.getNodes()) {
            if (node instanceof Simplifiable) {
                listener.getNodes().add(node);
            }
        }
        canonicalizer.applyIncremental(graph, context, listener.getNodes());
        listener.getNodes().clear();
        if (++count > MAX_ITERATIONS) {
            throw new RetryableBailoutException("Number of iterations in ConditionalEliminationPhase phase exceeds %d", MAX_ITERATIONS);
        }
    }
}
Also used : HashSetNodeEventListener(org.graalvm.compiler.phases.common.util.HashSetNodeEventListener) NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException) Node(org.graalvm.compiler.graph.Node) Simplifiable(org.graalvm.compiler.graph.spi.Simplifiable)

Example 2 with Simplifiable

use of org.graalvm.compiler.graph.spi.Simplifiable in project graal by oracle.

the class EffectsPhase method runAnalysis.

@SuppressWarnings("try")
public boolean runAnalysis(StructuredGraph graph, PhaseContextT context) {
    boolean changed = false;
    CompilationAlarm compilationAlarm = CompilationAlarm.current();
    DebugContext debug = graph.getDebug();
    for (int iteration = 0; iteration < maxIterations && !compilationAlarm.hasExpired(); iteration++) {
        try (DebugContext.Scope s = debug.scope(debug.areScopesEnabled() ? "iteration " + iteration : null)) {
            ScheduleResult schedule;
            ControlFlowGraph cfg;
            if (unscheduled) {
                schedule = null;
                cfg = ControlFlowGraph.compute(graph, true, true, false, false);
            } else {
                new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST).apply(graph, false);
                schedule = graph.getLastSchedule();
                cfg = schedule.getCFG();
            }
            try (DebugContext.Scope scheduleScope = debug.scope("EffectsPhaseWithSchedule", schedule)) {
                Closure<?> closure = createEffectsClosure(context, schedule, cfg);
                ReentrantBlockIterator.apply(closure, cfg.getStartBlock());
                if (closure.needsApplyEffects()) {
                    // apply the effects collected during this iteration
                    HashSetNodeEventListener listener = new HashSetNodeEventListener();
                    try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
                        closure.applyEffects();
                    }
                    if (debug.isDumpEnabled(DebugContext.VERBOSE_LEVEL)) {
                        debug.dump(DebugContext.VERBOSE_LEVEL, graph, "%s iteration", getName());
                    }
                    new DeadCodeEliminationPhase(Required).apply(graph);
                    EconomicSet<Node> changedNodes = listener.getNodes();
                    for (Node node : graph.getNodes()) {
                        if (node instanceof Simplifiable) {
                            changedNodes.add(node);
                        }
                    }
                    postIteration(graph, context, changedNodes);
                }
                if (closure.hasChanged()) {
                    changed = true;
                } else {
                    break;
                }
            } catch (Throwable t) {
                throw debug.handle(t);
            }
        }
    }
    return changed;
}
Also used : ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) CompilationAlarm(org.graalvm.compiler.core.common.util.CompilationAlarm) Node(org.graalvm.compiler.graph.Node) DebugContext(org.graalvm.compiler.debug.DebugContext) HashSetNodeEventListener(org.graalvm.compiler.phases.common.util.HashSetNodeEventListener) NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) Simplifiable(org.graalvm.compiler.graph.spi.Simplifiable)

Aggregations

NodeEventScope (org.graalvm.compiler.graph.Graph.NodeEventScope)2 Node (org.graalvm.compiler.graph.Node)2 Simplifiable (org.graalvm.compiler.graph.spi.Simplifiable)2 HashSetNodeEventListener (org.graalvm.compiler.phases.common.util.HashSetNodeEventListener)2 RetryableBailoutException (org.graalvm.compiler.core.common.RetryableBailoutException)1 CompilationAlarm (org.graalvm.compiler.core.common.util.CompilationAlarm)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)1 ControlFlowGraph (org.graalvm.compiler.nodes.cfg.ControlFlowGraph)1 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)1 SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)1