use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class GraphTest method getDebug.
protected DebugContext getDebug(OptionValues options) {
DebugContext cached = cachedDebug.get();
if (cached != null) {
if (cached.getOptions() == options) {
return cached;
}
throw new AssertionError("At most one " + DebugContext.class.getName() + " object should be created per test");
}
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
cachedDebug.set(debug);
return debug;
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class MatchContext method setResult.
/**
* Mark the interior nodes with INTERIOR_MATCH and set the Value of the root to be the result.
* During final LIR generation it will be evaluated to produce the actual LIR value.
*
* @param result
*/
public void setResult(ComplexMatchResult result) {
ComplexMatchValue value = new ComplexMatchValue(result);
DebugContext debug = root.getDebug();
if (debug.isLogEnabled()) {
debug.log("matched %s %s", rule.getName(), rule.getPattern());
debug.log("with nodes %s", rule.formatMatch(root));
}
if (consumed != null) {
for (Node node : consumed) {
// All the interior nodes should be skipped during the normal doRoot calls in
// NodeLIRBuilder so mark them as interior matches. The root of the match will get a
// closure which will be evaluated to produce the final LIR.
builder.setMatchResult(node, ComplexMatchValue.INTERIOR_MATCH);
}
}
builder.setMatchResult(root, value);
}
use of org.graalvm.compiler.debug.DebugContext 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.debug.DebugContext in project graal by oracle.
the class ReassociateInvariantPhase method run.
@SuppressWarnings("try")
@Override
protected void run(StructuredGraph graph) {
int iterations = 0;
DebugContext debug = graph.getDebug();
try (DebugContext.Scope s = debug.scope("ReassociateInvariants")) {
boolean changed = true;
while (changed) {
changed = false;
final LoopsData dataReassociate = new LoopsData(graph);
for (LoopEx loop : dataReassociate.loops()) {
changed |= loop.reassociateInvariants();
}
dataReassociate.deleteUnusedNodes();
iterations++;
debug.dump(DebugContext.VERBOSE_LEVEL, graph, "after iteration %d", iterations);
}
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class DefaultLoopPolicies method shouldUnswitch.
@Override
public boolean shouldUnswitch(LoopEx loop, List<ControlSplitNode> controlSplits) {
int phis = 0;
StructuredGraph graph = loop.loopBegin().graph();
DebugContext debug = graph.getDebug();
NodeBitMap branchNodes = graph.createNodeBitMap();
for (ControlSplitNode controlSplit : controlSplits) {
for (Node successor : controlSplit.successors()) {
AbstractBeginNode branch = (AbstractBeginNode) successor;
// this may count twice because of fall-through in switches
loop.nodesInLoopBranch(branchNodes, branch);
}
Block postDomBlock = loop.loopsData().getCFG().blockFor(controlSplit).getPostdominator();
if (postDomBlock != null) {
IsolatedInitialization.UNSWITCH_SPLIT_WITH_PHIS.increment(debug);
phis += ((MergeNode) postDomBlock.getBeginNode()).phis().count();
}
}
int inBranchTotal = branchNodes.count();
CountingClosure stateNodesCount = new CountingClosure();
double loopFrequency = loop.loopBegin().loopFrequency();
OptionValues options = loop.loopBegin().getOptions();
int maxDiff = Options.LoopUnswitchTrivial.getValue(options) + (int) (Options.LoopUnswitchFrequencyBoost.getValue(options) * (loopFrequency - 1.0 + phis));
maxDiff = Math.min(maxDiff, Options.LoopUnswitchMaxIncrease.getValue(options));
int remainingGraphSpace = MaximumDesiredSize.getValue(options) - graph.getNodeCount();
maxDiff = Math.min(maxDiff, remainingGraphSpace);
loop.loopBegin().stateAfter().applyToVirtual(stateNodesCount);
int loopTotal = loop.size() - loop.loopBegin().phis().count() - stateNodesCount.count - 1;
int actualDiff = (loopTotal - inBranchTotal);
ControlSplitNode firstSplit = controlSplits.get(0);
if (firstSplit instanceof TypeSwitchNode) {
int copies = firstSplit.successors().count() - 1;
for (Node succ : firstSplit.successors()) {
FixedNode current = (FixedNode) succ;
while (current instanceof FixedWithNextNode) {
current = ((FixedWithNextNode) current).next();
}
if (current instanceof DeoptimizeNode) {
copies--;
}
}
actualDiff = actualDiff * copies;
}
debug.log("shouldUnswitch(%s, %s) : delta=%d (%.2f%% inside of branches), max=%d, f=%.2f, phis=%d -> %b", loop, controlSplits, actualDiff, (double) (inBranchTotal) / loopTotal * 100, maxDiff, loopFrequency, phis, actualDiff <= maxDiff);
if (actualDiff <= maxDiff) {
// check whether we're allowed to unswitch this loop
return loop.canDuplicateLoop();
} else {
return false;
}
}
Aggregations