use of org.graalvm.compiler.phases.common.util.HashSetNodeEventListener in project graal by oracle.
the class FloatingReadPhase method run.
@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph) {
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);
}
}
HashSetNodeEventListener listener = new HashSetNodeEventListener(EnumSet.of(NODE_ADDED, ZERO_USAGES));
try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops, createFloatingReads, createMemoryMapNodes), 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.isAfterFloatingReadPhase();
graph.setAfterFloatingReadPhase(true);
}
}
use of org.graalvm.compiler.phases.common.util.HashSetNodeEventListener 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);
}
}
}
use of org.graalvm.compiler.phases.common.util.HashSetNodeEventListener 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.
*/
HashSetNodeEventListener listener = new HashSetNodeEventListener().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 HashSetNodeEventListener();
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);
}
}
use of org.graalvm.compiler.phases.common.util.HashSetNodeEventListener 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;
}
use of org.graalvm.compiler.phases.common.util.HashSetNodeEventListener in project graal by oracle.
the class LoopPartialUnrollPhase method run.
@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, PhaseContext context) {
if (graph.hasLoops()) {
HashSetNodeEventListener listener = new HashSetNodeEventListener();
boolean changed = true;
while (changed) {
changed = false;
try (Graph.NodeEventScope nes = graph.trackNodeEvents(listener)) {
LoopsData dataCounted = new LoopsData(graph);
dataCounted.detectedCountedLoops();
Graph.Mark mark = graph.getMark();
boolean prePostInserted = false;
for (LoopEx loop : dataCounted.countedLoops()) {
if (!LoopTransformations.isUnrollableLoop(loop)) {
continue;
}
if (getPolicies().shouldPartiallyUnroll(loop)) {
if (loop.loopBegin().isSimpleLoop()) {
// First perform the pre/post transformation and do the partial
// unroll when we come around again.
LoopTransformations.insertPrePostLoops(loop);
prePostInserted = true;
} else {
LoopTransformations.partialUnroll(loop);
}
changed = true;
}
}
dataCounted.deleteUnusedNodes();
if (!listener.getNodes().isEmpty()) {
canonicalizer.applyIncremental(graph, context, listener.getNodes());
listener.getNodes().clear();
}
assert !prePostInserted || checkCounted(graph, mark);
}
}
}
}
Aggregations