src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/CanonicalizerPhase.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/CanonicalizerPhase.java Fri Jul 7 09:31:28 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/CanonicalizerPhase.java Fri Jul 7 09:31:28 2017
*** 21,33 ****
--- 21,33 ----
* questions.
*/
package org.graalvm.compiler.phases.common;
import org.graalvm.compiler.core.common.spi.ConstantFieldProvider;
! import org.graalvm.compiler.debug.Debug;
! import org.graalvm.compiler.debug.CounterKey;
import org.graalvm.compiler.debug.DebugCloseable;
! import org.graalvm.compiler.debug.DebugCounter;
! import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.graph.GraalGraphError;
import org.graalvm.compiler.graph.Graph;
import org.graalvm.compiler.graph.Graph.Mark;
import org.graalvm.compiler.graph.Graph.NodeEventListener;
import org.graalvm.compiler.graph.Graph.NodeEventScope;
*** 60,76 ****
--- 60,76 ----
import jdk.vm.ci.meta.MetaAccessProvider;
public class CanonicalizerPhase extends BasePhase<PhaseContext> {
private static final int MAX_ITERATION_PER_NODE = 10;
! private static final DebugCounter COUNTER_CANONICALIZED_NODES = Debug.counter("CanonicalizedNodes");
! private static final DebugCounter COUNTER_PROCESSED_NODES = Debug.counter("ProcessedNodes");
! private static final DebugCounter COUNTER_CANONICALIZATION_CONSIDERED_NODES = Debug.counter("CanonicalizationConsideredNodes");
! private static final DebugCounter COUNTER_INFER_STAMP_CALLED = Debug.counter("InferStampCalled");
! private static final DebugCounter COUNTER_STAMP_CHANGED = Debug.counter("StampChanged");
! private static final DebugCounter COUNTER_SIMPLIFICATION_CONSIDERED_NODES = Debug.counter("SimplificationConsideredNodes");
! private static final DebugCounter COUNTER_GLOBAL_VALUE_NUMBERING_HITS = Debug.counter("GlobalValueNumberingHits");
! private static final CounterKey COUNTER_CANONICALIZED_NODES = DebugContext.counter("CanonicalizedNodes");
! private static final CounterKey COUNTER_PROCESSED_NODES = DebugContext.counter("ProcessedNodes");
! private static final CounterKey COUNTER_CANONICALIZATION_CONSIDERED_NODES = DebugContext.counter("CanonicalizationConsideredNodes");
! private static final CounterKey COUNTER_INFER_STAMP_CALLED = DebugContext.counter("InferStampCalled");
! private static final CounterKey COUNTER_STAMP_CHANGED = DebugContext.counter("StampChanged");
! private static final CounterKey COUNTER_SIMPLIFICATION_CONSIDERED_NODES = DebugContext.counter("SimplificationConsideredNodes");
! private static final CounterKey COUNTER_GLOBAL_VALUE_NUMBERING_HITS = DebugContext.counter("GlobalValueNumberingHits");
private boolean globalValueNumber = true;
private boolean canonicalizeReads = true;
private boolean simplify = true;
private final CustomCanonicalizer customCanonicalizer;
*** 159,168 ****
--- 159,169 ----
private final PhaseContext context;
private final Iterable<? extends Node> initWorkingSet;
private NodeWorkList workList;
private Tool tool;
+ private DebugContext debug;
private Instance(PhaseContext context) {
this(context, null, null);
}
*** 185,194 ****
--- 186,196 ----
return false;
}
@Override
protected void run(StructuredGraph graph) {
+ this.debug = graph.getDebug();
boolean wholeGraph = newNodesMark == null || newNodesMark.isStart();
if (initWorkingSet == null) {
workList = graph.createIterativeNodeWorkList(wholeGraph, MAX_ITERATION_PER_NODE);
} else {
workList = graph.createIterativeNodeWorkList(false, MAX_ITERATION_PER_NODE);
*** 227,238 ****
--- 229,240 ----
};
try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
for (Node n : workList) {
boolean changed = processNode(n);
! if (changed && Debug.isDumpEnabled(Debug.DETAILED_LEVEL)) {
! Debug.dump(Debug.DETAILED_LEVEL, graph, "CanonicalizerPhase %s", n);
! if (changed && debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
! debug.dump(DebugContext.DETAILED_LEVEL, graph, "CanonicalizerPhase %s", n);
}
}
}
}
*** 241,251 ****
--- 243,253 ----
*/
private boolean processNode(Node node) {
if (!node.isAlive()) {
return false;
}
! COUNTER_PROCESSED_NODES.increment(debug);
if (GraphUtil.tryKillUnused(node)) {
return true;
}
NodeClass<?> nodeClass = node.getNodeClass();
StructuredGraph graph = (StructuredGraph) node.graph();
*** 259,269 ****
--- 261,271 ----
ValueNode valueNode = (ValueNode) node;
boolean improvedStamp = tryInferStamp(valueNode);
Constant constant = valueNode.stamp().asConstant();
if (constant != null && !(node instanceof ConstantNode)) {
ConstantNode stampConstant = ConstantNode.forConstant(valueNode.stamp(), constant, context.getMetaAccess(), graph);
! Debug.log("Canonicalizer: constant stamp replaces %1s with %1s", valueNode, stampConstant);
! debug.log("Canonicalizer: constant stamp replaces %1s with %1s", valueNode, stampConstant);
valueNode.replaceAtUsages(InputType.Value, stampConstant);
GraphUtil.tryKillUnused(valueNode);
return true;
} else if (improvedStamp) {
// the improved stamp may enable additional canonicalization
*** 280,291 ****
--- 282,293 ----
if (nodeClass.valueNumberable()) {
Node newNode = node.graph().findDuplicate(node);
if (newNode != null) {
assert !(node instanceof FixedNode || newNode instanceof FixedNode);
node.replaceAtUsagesAndDelete(newNode);
! COUNTER_GLOBAL_VALUE_NUMBERING_HITS.increment(debug);
! Debug.log("GVN applied and new node is %1s", newNode);
! debug.log("GVN applied and new node is %1s", newNode);
return true;
}
}
return false;
}
*** 317,327 ****
--- 319,329 ----
return true;
}
}
}
if (nodeClass.isCanonicalizable()) {
! COUNTER_CANONICALIZATION_CONSIDERED_NODES.increment(debug);
Node canonical;
try (AutoCloseable verify = getCanonicalizeableContractAssertion(node)) {
canonical = ((Canonicalizable) node).canonical(tool);
if (canonical == node && nodeClass.isCommutative()) {
canonical = ((BinaryCommutative<?>) node).maybeCommuteInputs();
*** 333,344 ****
--- 335,346 ----
return true;
}
}
if (nodeClass.isSimplifiable() && simplify) {
! Debug.log(Debug.VERBOSE_LEVEL, "Canonicalizer: simplifying %s", node);
! COUNTER_SIMPLIFICATION_CONSIDERED_NODES.increment();
! debug.log(DebugContext.VERBOSE_LEVEL, "Canonicalizer: simplifying %s", node);
! COUNTER_SIMPLIFICATION_CONSIDERED_NODES.increment(debug);
node.simplify(tool);
return node.isDeleted();
}
return false;
}
*** 360,375 ****
--- 362,377 ----
// --------------------------------------------
// X: must not happen (checked with assertions)
// @formatter:on
private boolean performReplacement(final Node node, Node newCanonical) {
if (newCanonical == node) {
! Debug.log(Debug.VERBOSE_LEVEL, "Canonicalizer: work on %1s", node);
! debug.log(DebugContext.VERBOSE_LEVEL, "Canonicalizer: work on %1s", node);
return false;
} else {
Node canonical = newCanonical;
! Debug.log("Canonicalizer: replacing %1s with %1s", node, canonical);
! COUNTER_CANONICALIZED_NODES.increment();
! debug.log("Canonicalizer: replacing %1s with %1s", node, canonical);
! COUNTER_CANONICALIZED_NODES.increment(debug);
StructuredGraph graph = (StructuredGraph) node.graph();
if (canonical != null && !canonical.isAlive()) {
assert !canonical.isDeleted();
canonical = graph.addOrUniqueWithInputs(canonical);
}
*** 426,438 ****
--- 428,440 ----
* this method also checks if the stamp now describes a constant integer value, in which
* case the node is replaced with a constant.
*/
private boolean tryInferStamp(ValueNode node) {
if (node.isAlive()) {
! COUNTER_INFER_STAMP_CALLED.increment(debug);
if (node.inferStamp()) {
! COUNTER_STAMP_CHANGED.increment(debug);
for (Node usage : node.usages()) {
workList.add(usage);
}
return true;
}
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/CanonicalizerPhase.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File