Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java @ 16494:d8d90184ec66
Merge.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 11 Jul 2014 14:21:57 +0200 |
parents | 1f1ac8857d92 000a1a014bd4 |
children | c667378e4699 |
rev | line source |
---|---|
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.truffle; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
15259
d90e5c22ba55
Move GraalOptions to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15254
diff
changeset
|
25 import static com.oracle.graal.compiler.common.GraalOptions.*; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 import static com.oracle.graal.truffle.TruffleCompilerOptions.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 import java.util.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.code.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.api.meta.*; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
32 import com.oracle.graal.api.replacements.*; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
33 import com.oracle.graal.api.runtime.*; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.debug.*; |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
35 import com.oracle.graal.debug.Debug.Scope; |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
11496
diff
changeset
|
36 import com.oracle.graal.debug.internal.*; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 import com.oracle.graal.graph.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 import com.oracle.graal.graph.Node; |
11881
da9db8331658
moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11801
diff
changeset
|
39 import com.oracle.graal.graph.spi.*; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 import com.oracle.graal.loop.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 import com.oracle.graal.nodes.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 import com.oracle.graal.nodes.java.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 import com.oracle.graal.nodes.spi.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 import com.oracle.graal.nodes.util.*; |
11496
b36028c30a81
Allow escape analysis to ignore object identity correctness for types marked via the CompilerDirectives.ValueType annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11437
diff
changeset
|
46 import com.oracle.graal.nodes.virtual.*; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 import com.oracle.graal.phases.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 import com.oracle.graal.phases.common.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer; |
15470
c55f44b3c5e5
remove NodesToDoubles, refactoring of node probability and inlining relevance computation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15311
diff
changeset
|
50 import com.oracle.graal.phases.common.inlining.*; |
15964
9d7b2134c4ce
less canonicalization during Truffle partial evaluation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15641
diff
changeset
|
51 import com.oracle.graal.phases.common.inlining.info.*; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 import com.oracle.graal.phases.tiers.*; |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
53 import com.oracle.graal.phases.util.*; |
11312
f0c8303cf88e
Restructure Truffle API node intrinsics and introduce new intrinsics for type system modelling.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11208
diff
changeset
|
54 import com.oracle.graal.truffle.nodes.asserts.*; |
f0c8303cf88e
Restructure Truffle API node intrinsics and introduce new intrinsics for type system modelling.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11208
diff
changeset
|
55 import com.oracle.graal.truffle.nodes.frame.*; |
f0c8303cf88e
Restructure Truffle API node intrinsics and introduce new intrinsics for type system modelling.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11208
diff
changeset
|
56 import com.oracle.graal.truffle.nodes.frame.NewFrameNode.VirtualOnlyInstanceNode; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 import com.oracle.graal.truffle.phases.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 import com.oracle.graal.virtual.phases.ea.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 import com.oracle.truffle.api.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 import com.oracle.truffle.api.nodes.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 /** |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 * Class performing the partial evaluation starting from the root node of an AST. |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 */ |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 public class PartialEvaluator { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
67 private final Providers providers; |
11567
c69df2e602f4
Use CanonicalizerPhase.applyIncremental in InliningPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11551
diff
changeset
|
68 private final CanonicalizerPhase canonicalizer; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 private Set<Constant> constantReceivers; |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10529
diff
changeset
|
70 private final TruffleCache truffleCache; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
71 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
72 public PartialEvaluator(Providers providers, TruffleCache truffleCache) { |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
73 this.providers = providers; |
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
74 CustomCanonicalizer customCanonicalizer = new PartialEvaluatorCanonicalizer(providers.getMetaAccess(), providers.getConstantReflection()); |
13378
16d99e9d77ad
Options: rename flag (AOTCompilation -> ImmutableCode)
Bernhard Urban <bernhard.urban@jku.at>
parents:
13209
diff
changeset
|
75 this.canonicalizer = new CanonicalizerPhase(!ImmutableCode.getValue(), customCanonicalizer); |
10611
1546866ebb8d
First draft of Truffle graph caching.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10529
diff
changeset
|
76 this.truffleCache = truffleCache; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 |
13207
9500ac5269ff
add truffle tree dump handler in order to make tree dumping respect the method filter.
Andreas Woess <andreas.woess@jku.at>
parents:
13197
diff
changeset
|
79 public StructuredGraph createGraph(final OptimizedCallTarget callTarget, final Assumptions assumptions) { |
9500ac5269ff
add truffle tree dump handler in order to make tree dumping respect the method filter.
Andreas Woess <andreas.woess@jku.at>
parents:
13197
diff
changeset
|
80 try (Scope s = Debug.scope("TruffleTree")) { |
9500ac5269ff
add truffle tree dump handler in order to make tree dumping respect the method filter.
Andreas Woess <andreas.woess@jku.at>
parents:
13197
diff
changeset
|
81 Debug.dump(callTarget, "truffle tree"); |
9500ac5269ff
add truffle tree dump handler in order to make tree dumping respect the method filter.
Andreas Woess <andreas.woess@jku.at>
parents:
13197
diff
changeset
|
82 } catch (Throwable e) { |
9500ac5269ff
add truffle tree dump handler in order to make tree dumping respect the method filter.
Andreas Woess <andreas.woess@jku.at>
parents:
13197
diff
changeset
|
83 throw Debug.handle(e); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 |
15072
7b3175685d19
PartialEvaluator: fix compilation tracing
Andreas Woess <andreas.woess@jku.at>
parents:
15018
diff
changeset
|
86 if (TraceTruffleCompilationHistogram.getValue() || TraceTruffleCompilationDetails.getValue()) { |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 constantReceivers = new HashSet<>(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 |
15287
e3b5fdeb304a
pass CallTarget name to Truffle-generated StructuredGraphs
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15259
diff
changeset
|
90 final StructuredGraph graph = truffleCache.createRootGraph(callTarget.toString()); |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
91 assert graph != null : "no graph for root method"; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
93 try (Scope s = Debug.scope("CreateGraph", graph); Indent indent = Debug.logAndIndent("createGraph %s", graph.method())) { |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
94 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
95 // Replace thisNode with constant. |
13614
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13597
diff
changeset
|
96 ParameterNode thisNode = graph.getParameter(0); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
97 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
98 /* |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
99 * Converting the call target to a Constant using the SnippetReflectionProvider is a |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
100 * workaround, we should think about a better solution. Since object constants are |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
101 * VM-specific, only the hosting VM knows how to do the conversion. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
102 */ |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
103 SnippetReflectionProvider snippetReflection = Graal.getRequiredCapability(SnippetReflectionProvider.class); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
104 thisNode.replaceAndDelete(ConstantNode.forConstant(snippetReflection.forObject(callTarget), providers.getMetaAccess(), graph)); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
105 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
106 // Canonicalize / constant propagate. |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
107 PhaseContext baseContext = new PhaseContext(providers, assumptions); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
108 canonicalizer.apply(graph, baseContext); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
109 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
110 // Intrinsify methods. |
15641
e500d6900328
cleanup after ReplaceIntrinsicsPhase
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15534
diff
changeset
|
111 new IncrementalCanonicalizerPhase<>(canonicalizer, new ReplaceIntrinsicsPhase(providers.getReplacements())).apply(graph, baseContext); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
112 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
113 Debug.dump(graph, "Before inlining"); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
114 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
115 // Make sure frame does not escape. |
15089
448338c9ce96
Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents:
15082
diff
changeset
|
116 expandTree(graph, assumptions); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
117 |
14983
a31d807757ee
Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents:
14866
diff
changeset
|
118 if (Thread.currentThread().isInterrupted()) { |
a31d807757ee
Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents:
14866
diff
changeset
|
119 return null; |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
120 } |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12432
diff
changeset
|
121 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
122 new VerifyFrameDoesNotEscapePhase().apply(graph, false); |
11646
8f8f6afeb97a
New caching mechanism in TruffleCache for better compilation performance. Clean up of partial evaluator phases.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11615
diff
changeset
|
123 |
13996
c7ac129e17e9
Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents:
13916
diff
changeset
|
124 if (TraceTruffleCompilationHistogram.getValue() && constantReceivers != null) { |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
125 DebugHistogram histogram = Debug.createHistogram("Expanded Truffle Nodes"); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
126 for (Constant c : constantReceivers) { |
16478
1f1ac8857d92
moved toJavaName(JavaType type, boolean qualified) from MetaUtil to be a default method in JavaType
Doug Simon <doug.simon@oracle.com>
parents:
16469
diff
changeset
|
127 String javaName = providers.getMetaAccess().lookupJavaType(c).toJavaName(false); |
15254
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
128 |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
129 // The DSL uses nested classes with redundant names - only show the inner class |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
130 int index = javaName.indexOf('$'); |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
131 if (index != -1) { |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
132 javaName = javaName.substring(index + 1); |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
133 } |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
134 |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
135 histogram.add(javaName); |
a83af3413927
Show shorter class names in the Truffle compilation histogram.
Chris Seaton <chris.seaton@oracle.com>
parents:
15239
diff
changeset
|
136 |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
137 } |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
138 new DebugHistogramAsciiPrinter(TTY.out().out()).print(histogram); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
139 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
140 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
141 canonicalizer.apply(graph, baseContext); |
14172
cd22c8dbda4f
Made graph caching compilation local
Doug Simon <doug.simon@oracle.com>
parents:
14170
diff
changeset
|
142 Map<ResolvedJavaMethod, StructuredGraph> graphCache = null; |
cd22c8dbda4f
Made graph caching compilation local
Doug Simon <doug.simon@oracle.com>
parents:
14170
diff
changeset
|
143 if (CacheGraphs.getValue()) { |
cd22c8dbda4f
Made graph caching compilation local
Doug Simon <doug.simon@oracle.com>
parents:
14170
diff
changeset
|
144 graphCache = new HashMap<>(); |
cd22c8dbda4f
Made graph caching compilation local
Doug Simon <doug.simon@oracle.com>
parents:
14170
diff
changeset
|
145 } |
cd22c8dbda4f
Made graph caching compilation local
Doug Simon <doug.simon@oracle.com>
parents:
14170
diff
changeset
|
146 HighTierContext tierContext = new HighTierContext(providers, assumptions, graphCache, new PhaseSuite<HighTierContext>(), OptimisticOptimizations.NONE); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
147 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
148 for (NeverPartOfCompilationNode neverPartOfCompilationNode : graph.getNodes(NeverPartOfCompilationNode.class)) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
149 Throwable exception = new VerificationError(neverPartOfCompilationNode.getMessage()); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
150 throw GraphUtil.approxSourceException(neverPartOfCompilationNode, exception); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
151 } |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
152 |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
153 // EA frame and clean up. |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
154 new PartialEscapePhase(true, canonicalizer).apply(graph, tierContext); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
155 new VerifyNoIntrinsicsLeftPhase().apply(graph, false); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
156 for (MaterializeFrameNode materializeNode : graph.getNodes(MaterializeFrameNode.class).snapshot()) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
157 materializeNode.replaceAtUsages(materializeNode.getFrame()); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
158 graph.removeFixed(materializeNode); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
159 } |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
160 for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.class)) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
161 if (virtualObjectNode instanceof VirtualOnlyInstanceNode) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
162 VirtualOnlyInstanceNode virtualOnlyInstanceNode = (VirtualOnlyInstanceNode) virtualObjectNode; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
163 virtualOnlyInstanceNode.setAllowMaterialization(true); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
164 } else if (virtualObjectNode instanceof VirtualInstanceNode) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
165 VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
166 ResolvedJavaType type = virtualInstanceNode.type(); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
167 if (type.getAnnotation(CompilerDirectives.ValueType.class) != null) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
168 virtualInstanceNode.setIdentity(false); |
11496
b36028c30a81
Allow escape analysis to ignore object identity correctness for types marked via the CompilerDirectives.ValueType annotation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11437
diff
changeset
|
169 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
170 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
171 } |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
172 } catch (Throwable e) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
173 throw Debug.handle(e); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
174 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
175 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
176 return graph; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
177 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
178 |
15089
448338c9ce96
Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents:
15082
diff
changeset
|
179 private void expandTree(StructuredGraph graph, Assumptions assumptions) { |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
180 PhaseContext phaseContext = new PhaseContext(providers, assumptions); |
13203
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
181 TruffleExpansionLogger expansionLogger = null; |
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
182 if (TraceTruffleExpansion.getValue()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14991
diff
changeset
|
183 expansionLogger = new TruffleExpansionLogger(providers, graph); |
13203
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
184 } |
10528
5fb4a450b7a7
PartialEvaluator: iterative version of expandTree
Andreas Woess <andreas.woess@jku.at>
parents:
10487
diff
changeset
|
185 boolean changed; |
5fb4a450b7a7
PartialEvaluator: iterative version of expandTree
Andreas Woess <andreas.woess@jku.at>
parents:
10487
diff
changeset
|
186 do { |
5fb4a450b7a7
PartialEvaluator: iterative version of expandTree
Andreas Woess <andreas.woess@jku.at>
parents:
10487
diff
changeset
|
187 changed = false; |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
188 for (MethodCallTargetNode methodCallTargetNode : graph.getNodes(MethodCallTargetNode.class)) { |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
189 InvokeKind kind = methodCallTargetNode.invokeKind(); |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
190 try (Indent id1 = Debug.logAndIndent("try inlining %s, kind = %s", methodCallTargetNode.targetMethod(), kind)) { |
15239
00abd0611776
Truffle: extend partial evaluation scope to all invokespecial, regardless of receiver
Andreas Woess <andreas.woess@jku.at>
parents:
15216
diff
changeset
|
191 if (kind == InvokeKind.Static || kind == InvokeKind.Special) { |
15072
7b3175685d19
PartialEvaluator: fix compilation tracing
Andreas Woess <andreas.woess@jku.at>
parents:
15018
diff
changeset
|
192 if ((TraceTruffleCompilationHistogram.getValue() || TraceTruffleCompilationDetails.getValue()) && kind == InvokeKind.Special && methodCallTargetNode.receiver().isConstant()) { |
7b3175685d19
PartialEvaluator: fix compilation tracing
Andreas Woess <andreas.woess@jku.at>
parents:
15018
diff
changeset
|
193 constantReceivers.add(methodCallTargetNode.receiver().asConstant()); |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
194 } |
15072
7b3175685d19
PartialEvaluator: fix compilation tracing
Andreas Woess <andreas.woess@jku.at>
parents:
15018
diff
changeset
|
195 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
196 Replacements replacements = providers.getReplacements(); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
197 Class<? extends FixedWithNextNode> macroSubstitution = replacements.getMacroSubstitution(methodCallTargetNode.targetMethod()); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
198 if (macroSubstitution != null) { |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
199 InliningUtil.inlineMacroNode(methodCallTargetNode.invoke(), methodCallTargetNode.targetMethod(), macroSubstitution); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
200 changed = true; |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
201 continue; |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
202 } |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
203 |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
204 StructuredGraph inlineGraph = replacements.getMethodSubstitution(methodCallTargetNode.targetMethod()); |
16474
000a1a014bd4
Backed out changeset: cec5a97ba1e4
Andreas Woess <andreas.woess@jku.at>
parents:
16469
diff
changeset
|
205 if (inlineGraph == null && !methodCallTargetNode.targetMethod().isNative() && methodCallTargetNode.targetMethod().canBeInlined()) { |
14984
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14983
diff
changeset
|
206 inlineGraph = parseGraph(methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), assumptions, phaseContext, false); |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
207 } |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
208 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
209 if (inlineGraph != null) { |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
210 try (Indent indent = Debug.logAndIndent("inline graph %s", methodCallTargetNode.targetMethod())) { |
15089
448338c9ce96
Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents:
15082
diff
changeset
|
211 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
212 int nodeCountBefore = graph.getNodeCount(); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
213 if (TraceTruffleExpansion.getValue()) { |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
214 expansionLogger.preExpand(methodCallTargetNode, inlineGraph); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
215 } |
15964
9d7b2134c4ce
less canonicalization during Truffle partial evaluation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15641
diff
changeset
|
216 List<Node> canonicalizedNodes = methodCallTargetNode.invoke().asNode().usages().snapshot(); |
16176
5785eca138b0
improve tracking of nodes to canonicalize after inlining
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15964
diff
changeset
|
217 Map<Node, Node> inlined = InliningUtil.inline(methodCallTargetNode.invoke(), inlineGraph, false, canonicalizedNodes); |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
218 if (TraceTruffleExpansion.getValue()) { |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
219 expansionLogger.postExpand(inlined); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
220 } |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
221 if (Debug.isDumpEnabled()) { |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
222 int nodeCountAfter = graph.getNodeCount(); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
223 Debug.dump(graph, "After inlining %s %+d (%d)", methodCallTargetNode.targetMethod().toString(), nodeCountAfter - nodeCountBefore, nodeCountAfter); |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
224 } |
15964
9d7b2134c4ce
less canonicalization during Truffle partial evaluation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15641
diff
changeset
|
225 AbstractInlineInfo.getInlinedParameterUsages(canonicalizedNodes, inlineGraph, inlined); |
9d7b2134c4ce
less canonicalization during Truffle partial evaluation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15641
diff
changeset
|
226 canonicalizer.applyIncremental(graph, phaseContext, canonicalizedNodes); |
14984
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14983
diff
changeset
|
227 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
228 changed = true; |
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
229 } |
13203
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
230 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
231 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
232 } |
10677
3bbe14e492fb
Introduce TruffleGraphMaxNodes option with default value 10000.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10676
diff
changeset
|
233 |
3bbe14e492fb
Introduce TruffleGraphMaxNodes option with default value 10000.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10676
diff
changeset
|
234 if (graph.getNodeCount() > TruffleCompilerOptions.TruffleGraphMaxNodes.getValue()) { |
3bbe14e492fb
Introduce TruffleGraphMaxNodes option with default value 10000.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10676
diff
changeset
|
235 throw new BailoutException("Truffle compilation is exceeding maximum node count: " + graph.getNodeCount()); |
3bbe14e492fb
Introduce TruffleGraphMaxNodes option with default value 10000.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10676
diff
changeset
|
236 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
237 } |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
238 } while (changed); |
13203
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
239 |
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
240 if (TraceTruffleExpansion.getValue()) { |
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
241 expansionLogger.print(); |
401e1473c546
Truffle: Implemented basic tracing of truffle compiler tree expansion (-G:+TraceTruffleExpansion, -G:+TraceTruffleExpansionSource)
Christian Humer <christian.humer@gmail.com>
parents:
13197
diff
changeset
|
242 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
243 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
244 |
14984
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14983
diff
changeset
|
245 private StructuredGraph parseGraph(final ResolvedJavaMethod targetMethod, final NodeInputList<ValueNode> arguments, final Assumptions assumptions, final PhaseContext phaseContext, |
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14983
diff
changeset
|
246 boolean ignoreSlowPath) { |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
247 |
14984
a5bebb69dc78
Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents:
14983
diff
changeset
|
248 StructuredGraph graph = truffleCache.lookup(targetMethod, arguments, assumptions, canonicalizer, ignoreSlowPath); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
249 |
14866
a0185cd77565
Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents:
14620
diff
changeset
|
250 if (graph != null && targetMethod.getAnnotation(ExplodeLoop.class) != null) { |
14612
3c8de2692867
TruffleCompiler: print hint if hitting the assertion
Bernhard Urban <bernhard.urban@jku.at>
parents:
14172
diff
changeset
|
251 assert graph.hasLoops() : graph + " does not contain a loop"; |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
252 final StructuredGraph graphCopy = graph.copy(); |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
253 final List<Node> modifiedNodes = new ArrayList<>(); |
13614
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13597
diff
changeset
|
254 for (ParameterNode param : graphCopy.getNodes(ParameterNode.class)) { |
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13597
diff
changeset
|
255 ValueNode arg = arguments.get(param.index()); |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
256 if (arg.isConstant()) { |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
257 Constant constant = arg.asConstant(); |
13614
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13597
diff
changeset
|
258 for (Node usage : param.usages()) { |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
259 if (usage instanceof Canonicalizable) { |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
260 modifiedNodes.add(usage); |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
261 } |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
262 } |
13614
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13597
diff
changeset
|
263 param.replaceAndDelete(ConstantNode.forConstant(constant, phaseContext.getMetaAccess(), graphCopy)); |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
264 } |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
265 } |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
266 try (Scope s = Debug.scope("TruffleUnrollLoop", targetMethod)) { |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
267 |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
268 canonicalizer.applyIncremental(graphCopy, phaseContext, modifiedNodes); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
269 boolean unrolled; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
270 do { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
271 unrolled = false; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
272 LoopsData loopsData = new LoopsData(graphCopy); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
273 loopsData.detectedCountedLoops(); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
274 for (LoopEx ex : innerLoopsFirst(loopsData.countedLoops())) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
275 if (ex.counted().isConstantMaxTripCount()) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
276 long constant = ex.counted().constantMaxTripCount(); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
277 LoopTransformations.fullUnroll(ex, phaseContext, canonicalizer); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
278 Debug.dump(graphCopy, "After loop unrolling %d times", constant); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
279 unrolled = true; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
280 break; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
281 } |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
282 } |
16194
7fb828b4c32b
made LoopsData clients clean up dead nodes created during loop analysis
Doug Simon <doug.simon@oracle.com>
parents:
16191
diff
changeset
|
283 loopsData.deleteUnusedNodes(); |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
284 } while (unrolled); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
285 } catch (Throwable e) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
286 throw Debug.handle(e); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
287 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
288 |
11680
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
289 return graphCopy; |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
290 } else { |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
291 return graph; |
524d0a0a47b8
New algorithm for Truffle tree expansion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11646
diff
changeset
|
292 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
293 } |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
294 |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
295 private static List<LoopEx> innerLoopsFirst(Collection<LoopEx> loops) { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
296 ArrayList<LoopEx> sortedLoops = new ArrayList<>(loops); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
297 Collections.sort(sortedLoops, new Comparator<LoopEx>() { |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
298 |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
299 @Override |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
300 public int compare(LoopEx o1, LoopEx o2) { |
16191
3e3578bc8f9b
rename: lirLoop* -> loop*
Doug Simon <doug.simon@oracle.com>
parents:
15964
diff
changeset
|
301 return o2.loop().getDepth() - o1.loop().getDepth(); |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
302 } |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
303 }); |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
304 return sortedLoops; |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
305 } |
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
12686
diff
changeset
|
306 |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
307 } |