Skip to content

Commit 2f56860

Browse files
committed
[GR-36638] [GR-36658] PE: Avoid running redundant phases; fix call tree names; dump graph after PE.
PullRequest: graal/10921
2 parents 1c9e6f1 + b26be80 commit 2f56860

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
114114
"org.graalvm.compiler.phases.BasePhase.dumpAfter",
115115
"org.graalvm.compiler.phases.BasePhase.dumpBefore",
116116
"org.graalvm.compiler.core.GraalCompiler.emitFrontEnd",
117-
"org.graalvm.compiler.truffle.compiler.PartialEvaluator.inliningGraphPE",
118117
"org.graalvm.compiler.truffle.compiler.PerformanceInformationHandler.reportPerformanceWarnings",
119118
"org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl.compilePEGraph",
120119
"org.graalvm.compiler.core.test.VerifyDebugUsageTest$ValidDumpUsagePhase.run",

compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/PartialEvaluator.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,13 @@ public final StructuredGraph evaluate(Request request) {
345345
try (PerformanceInformationHandler handler = PerformanceInformationHandler.install(request.options)) {
346346
try (DebugContext.Scope s = request.debug.scope("CreateGraph", request.graph);
347347
Indent indent = request.debug.logAndIndent("evaluate %s", request.graph);) {
348-
inliningGraphPE(request);
348+
boolean inlined = inliningGraphPE(request);
349349
assert GraphOrder.assertSchedulableGraph(request.graph) : "PE result must be schedulable in order to apply subsequent phases";
350-
truffleTier(request);
350+
// If no inlining has happened, we can skip the final Truffle tier round
351+
// since these phases have already been run during PE of the root.
352+
if (inlined) {
353+
truffleTier(request);
354+
}
351355
applyInstrumentationPhases(request);
352356
handler.reportPerformanceWarnings(request.compilable, request.graph);
353357
if (request.task.isCancelled()) {
@@ -638,12 +642,15 @@ protected InvocationPlugins createDecodingInvocationPlugins(PartialEvaluatorConf
638642
}
639643

640644
@SuppressWarnings({"unused", "try"})
641-
private void inliningGraphPE(Request request) {
645+
private boolean inliningGraphPE(Request request) {
646+
boolean inlined;
642647
try (DebugCloseable a = PartialEvaluationTimer.start(request.debug)) {
643-
new AgnosticInliningPhase(this, request).apply(request.graph, providers);
648+
AgnosticInliningPhase inliningPhase = new AgnosticInliningPhase(this, request);
649+
inliningPhase.apply(request.graph, providers);
650+
inlined = inliningPhase.hasInlined();
644651
}
645-
request.debug.dump(DebugContext.BASIC_LEVEL, request.graph, "After Partial Evaluation");
646652
request.graph.maybeCompress();
653+
return inlined;
647654
}
648655

649656
protected void applyInstrumentationPhases(Request request) {

compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/AgnosticInliningPhase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public final class AgnosticInliningPhase extends BasePhase<CoreProviders> {
5151

5252
private final PartialEvaluator partialEvaluator;
5353
private final PartialEvaluator.Request request;
54+
private int inlined;
5455

5556
public AgnosticInliningPhase(PartialEvaluator partialEvaluator, PartialEvaluator.Request request) {
5657
this.partialEvaluator = partialEvaluator;
@@ -88,6 +89,7 @@ protected void run(StructuredGraph graph, CoreProviders coreProviders) {
8889
}
8990
tree.finalizeGraph();
9091
tree.trace();
92+
inlined = tree.getInlinedCount();
9193
}
9294

9395
private boolean optionsAllowInlining() {
@@ -100,4 +102,7 @@ public boolean checkContract() {
100102
return false;
101103
}
102104

105+
public boolean hasInlined() {
106+
return inlined > 1;
107+
}
103108
}

compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import org.graalvm.compiler.truffle.compiler.PerformanceInformationHandler;
5353
import org.graalvm.compiler.truffle.options.PolyglotCompilerOptions;
5454

55-
@NodeInfo(nameTemplate = "{p#truffleAST}", cycles = NodeCycles.CYCLES_IGNORED, size = NodeSize.SIZE_IGNORED)
55+
@NodeInfo(nameTemplate = "{p#directCallTarget}", cycles = NodeCycles.CYCLES_IGNORED, size = NodeSize.SIZE_IGNORED)
5656
public final class CallNode extends Node implements Comparable<CallNode> {
5757

5858
private static final NodeClass<CallNode> TYPE = NodeClass.create(CallNode.class);
@@ -75,6 +75,8 @@ public final class CallNode extends Node implements Comparable<CallNode> {
7575
// Effectively final, cannot be initialized in the constructor because needs getParent() to
7676
// calculate
7777
private int recursionDepth;
78+
// Effectively final, populated only as part of expanded if debug dump level >= info
79+
@SuppressWarnings("unused") private StructuredGraph irAfterPE;
7880
// Effectively final, populated only as part of expanded
7981
private StructuredGraph ir;
8082
// Effectively final, populated only as part of expanded (unless root, root does not have
@@ -107,6 +109,7 @@ static CallNode makeRoot(CallTree callTree, PartialEvaluator.Request request) {
107109
root.ir = request.graph;
108110
root.policyData = callTree.getPolicy().newCallNodeData(root);
109111
final GraphManager.Entry entry = callTree.getGraphManager().peRoot();
112+
root.irAfterPE = entry.graphAfterPEForDebugDump;
110113
EconomicMap<Invoke, TruffleCallNode> invokeToTruffleCallNode = entry.invokeToTruffleCallNode;
111114
root.verifyTrivial(entry);
112115
addChildren(root, invokeToTruffleCallNode);
@@ -232,6 +235,7 @@ public void expand() {
232235
}
233236
verifyTrivial(entry);
234237
ir = copyGraphAndAddChildren(entry);
238+
irAfterPE = entry.graphAfterPEForDebugDump;
235239
addIndirectChildren(entry);
236240
getPolicy().afterExpand(this);
237241
}

compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/GraphManager.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.graalvm.collections.EconomicMap;
3030
import org.graalvm.collections.UnmodifiableEconomicMap;
31+
import org.graalvm.compiler.debug.DebugContext;
3132
import org.graalvm.compiler.graph.Node;
3233
import org.graalvm.compiler.nodes.EncodedGraph;
3334
import org.graalvm.compiler.nodes.Invoke;
@@ -66,8 +67,9 @@ Entry pe(CompilableTruffleAST truffleAST) {
6667
final PartialEvaluator.Request request = newRequest(truffleAST, false);
6768
request.graph.getAssumptions().record(new TruffleAssumption(truffleAST.getNodeRewritingAssumptionConstant()));
6869
partialEvaluator.doGraphPE(request, plugin, graphCacheForInlining);
70+
StructuredGraph graphAfterPE = copyGraphForDebugDump(request);
6971
partialEvaluator.truffleTier(request);
70-
entry = new Entry(request.graph, plugin);
72+
entry = new Entry(request.graph, plugin, graphAfterPE);
7173
irCache.put(truffleAST, entry);
7274
}
7375
return entry;
@@ -91,8 +93,9 @@ private PEAgnosticInlineInvokePlugin newPlugin() {
9193
Entry peRoot() {
9294
final PEAgnosticInlineInvokePlugin plugin = newPlugin();
9395
partialEvaluator.doGraphPE(rootRequest, plugin, graphCacheForInlining);
96+
StructuredGraph graphAfterPE = copyGraphForDebugDump(rootRequest);
9497
partialEvaluator.truffleTier(rootRequest);
95-
return new Entry(rootRequest.graph, plugin);
98+
return new Entry(rootRequest.graph, plugin, graphAfterPE);
9699
}
97100

98101
UnmodifiableEconomicMap<Node, Node> doInline(Invoke invoke, StructuredGraph ir, CompilableTruffleAST truffleAST, InliningUtil.InlineeReturnAction returnAction) {
@@ -111,20 +114,30 @@ public InlineInfo shouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod m
111114
InliningUtil.inline(invoke, request.graph, true, partialEvaluator.getCallInlined(), "finalization", AgnosticInliningPhase.class.getName());
112115
}
113116

114-
static class Entry {
117+
private static StructuredGraph copyGraphForDebugDump(PartialEvaluator.Request request) {
118+
if (request.debug.isDumpEnabled(DebugContext.INFO_LEVEL)) {
119+
return (StructuredGraph) request.graph.copy(request.debug);
120+
}
121+
return null;
122+
}
123+
124+
static final class Entry {
115125
final StructuredGraph graph;
116126
final EconomicMap<Invoke, TruffleCallNode> invokeToTruffleCallNode;
117127
final List<Invoke> indirectInvokes;
118128
final boolean trivial;
129+
// Populated only when debug dump is enabled with debug dump level >= info.
130+
final StructuredGraph graphAfterPEForDebugDump;
119131

120-
Entry(StructuredGraph graph, PEAgnosticInlineInvokePlugin plugin) {
132+
Entry(StructuredGraph graph, PEAgnosticInlineInvokePlugin plugin, StructuredGraph graphAfterPEForDebugDump) {
121133
this.graph = graph;
122134
this.invokeToTruffleCallNode = plugin.getInvokeToTruffleCallNode();
123135
this.indirectInvokes = plugin.getIndirectInvokes();
124136
this.trivial = invokeToTruffleCallNode.isEmpty() &&
125137
indirectInvokes.isEmpty() &&
126138
graph.getNodes(LoopBeginNode.TYPE).count() == 0 &&
127139
graph.getNodeCount() < TRIVIAL_NODE_COUNT_LIMIT;
140+
this.graphAfterPEForDebugDump = graphAfterPEForDebugDump;
128141
}
129142
}
130143

0 commit comments

Comments
 (0)