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);
}
}
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());
}
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");
}
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);
}
}
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());
}
}
Aggregations