Mercurial > hg > truffle
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java @ 11711:f12b418ebc74
Allow only single input for value anchors.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 19 Sep 2013 02:20:46 +0200 |
parents | 77d9f12797c5 |
children | 35bdfb9ac12f |
rev | line source |
---|---|
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
8988
02f57662b6c4
remove monitor limitation form TailDuplicationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
8558
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
6526
ee651c726397
split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents:
6525
diff
changeset
|
23 package com.oracle.graal.phases.common; |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9643
diff
changeset
|
25 import static com.oracle.graal.phases.GraalOptions.*; |
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9643
diff
changeset
|
26 |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
27 import java.util.*; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
28 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
29 import com.oracle.graal.debug.*; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.graph.Graph.DuplicationReplacement; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.graph.*; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.*; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
33 import com.oracle.graal.nodes.VirtualState.NodeClosure; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.extended.*; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
35 import com.oracle.graal.nodes.java.*; |
7536
1563a48b798d
don't tail duplicate allocations
Lukas Stadler <lukas.stadler@jku.at>
parents:
7255
diff
changeset
|
36 import com.oracle.graal.nodes.spi.*; |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
37 import com.oracle.graal.nodes.type.*; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
38 import com.oracle.graal.nodes.util.*; |
6525
2c913b643422
rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents:
6522
diff
changeset
|
39 import com.oracle.graal.phases.*; |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
40 import com.oracle.graal.phases.graph.*; |
9329
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
41 import com.oracle.graal.phases.tiers.*; |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
42 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
43 /** |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
44 * This class is a phase that looks for opportunities for tail duplication. The static method |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
45 * {@link #tailDuplicate(MergeNode, TailDuplicationDecision, List, PhaseContext, CanonicalizerPhase)} |
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
46 * can also be used to drive tail duplication from other places, e.g., inlining. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
47 */ |
9329
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
48 public class TailDuplicationPhase extends BasePhase<PhaseContext> { |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
49 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
50 /* |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
51 * Various metrics on the circumstances in which tail duplication was/wasn't performed. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
52 */ |
10533
2faa1e7ef4f3
enable TailDuplication for MergeNodes without stateAfter
Lukas Stadler <lukas.stadler@jku.at>
parents:
10009
diff
changeset
|
53 private static final DebugMetric metricDuplicationConsidered = Debug.metric("DuplicationConsidered"); |
2faa1e7ef4f3
enable TailDuplication for MergeNodes without stateAfter
Lukas Stadler <lukas.stadler@jku.at>
parents:
10009
diff
changeset
|
54 private static final DebugMetric metricDuplicationPerformed = Debug.metric("DuplicationPerformed"); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
55 |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
56 private final CanonicalizerPhase canonicalizer; |
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
57 |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
58 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
59 * This interface is used by tail duplication to let clients decide if tail duplication should |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
60 * be performed. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
61 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
62 public interface TailDuplicationDecision { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
63 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
64 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
65 * Queries if tail duplication should be performed at the given merge. If this method |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
66 * returns true then the tail duplication will be performed, because all other checks have |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
67 * happened before. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
68 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
69 * @param merge The merge at which tail duplication can be performed. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
70 * @param fixedNodeCount The size of the set of fixed nodes that forms the base for the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
71 * duplicated set of nodes. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
72 * @return true if the tail duplication should be performed, false otherwise. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
73 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
74 boolean doTransform(MergeNode merge, int fixedNodeCount); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
75 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
76 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
77 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
78 * A tail duplication decision closure that employs the default algorithm: Check if there are |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
79 * any phis on the merge whose stamps improve and that have usages within the duplicated set of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
80 * fixed nodes. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
81 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
82 public static final TailDuplicationDecision DEFAULT_DECISION = new TailDuplicationDecision() { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
83 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
84 public boolean doTransform(MergeNode merge, int fixedNodeCount) { |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9643
diff
changeset
|
85 if (fixedNodeCount < TailDuplicationTrivialSize.getValue()) { |
5792
fa6ed51ac198
more aggressive tail duplication
Lukas Stadler <lukas.stadler@jku.at>
parents:
5786
diff
changeset
|
86 return true; |
fa6ed51ac198
more aggressive tail duplication
Lukas Stadler <lukas.stadler@jku.at>
parents:
5786
diff
changeset
|
87 } |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
88 HashSet<PhiNode> improvements = new HashSet<>(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
89 for (PhiNode phi : merge.phis()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
90 Stamp phiStamp = phi.stamp(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
91 for (ValueNode input : phi.values()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
92 if (!input.stamp().equals(phiStamp)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
93 improvements.add(phi); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
94 break; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
95 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
96 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
97 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
98 if (improvements.isEmpty()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
99 return false; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
100 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
101 FixedNode current = merge; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
102 int opportunities = 0; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
103 while (current instanceof FixedWithNextNode) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
104 current = ((FixedWithNextNode) current).next(); |
7536
1563a48b798d
don't tail duplicate allocations
Lukas Stadler <lukas.stadler@jku.at>
parents:
7255
diff
changeset
|
105 if (current instanceof VirtualizableAllocation) { |
1563a48b798d
don't tail duplicate allocations
Lukas Stadler <lukas.stadler@jku.at>
parents:
7255
diff
changeset
|
106 return false; |
1563a48b798d
don't tail duplicate allocations
Lukas Stadler <lukas.stadler@jku.at>
parents:
7255
diff
changeset
|
107 } |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
108 for (PhiNode phi : improvements) { |
6433
4bd8711d824a
small fix to tail duplication heuristics
Lukas Stadler <lukas.stadler@jku.at>
parents:
6411
diff
changeset
|
109 for (Node input : current.inputs()) { |
4bd8711d824a
small fix to tail duplication heuristics
Lukas Stadler <lukas.stadler@jku.at>
parents:
6411
diff
changeset
|
110 if (input == phi) { |
4bd8711d824a
small fix to tail duplication heuristics
Lukas Stadler <lukas.stadler@jku.at>
parents:
6411
diff
changeset
|
111 opportunities++; |
4bd8711d824a
small fix to tail duplication heuristics
Lukas Stadler <lukas.stadler@jku.at>
parents:
6411
diff
changeset
|
112 } |
4bd8711d824a
small fix to tail duplication heuristics
Lukas Stadler <lukas.stadler@jku.at>
parents:
6411
diff
changeset
|
113 if (input.inputs().contains(phi)) { |
4bd8711d824a
small fix to tail duplication heuristics
Lukas Stadler <lukas.stadler@jku.at>
parents:
6411
diff
changeset
|
114 opportunities++; |
4bd8711d824a
small fix to tail duplication heuristics
Lukas Stadler <lukas.stadler@jku.at>
parents:
6411
diff
changeset
|
115 } |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
116 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
117 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
118 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
119 return opportunities > 0; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
120 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
121 }; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
122 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
123 /** |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
124 * A tail duplication decision closure that always returns true. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
125 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
126 public static final TailDuplicationDecision TRUE_DECISION = new TailDuplicationDecision() { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
127 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
128 @Override |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
129 public boolean doTransform(MergeNode merge, int fixedNodeCount) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
130 return true; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
131 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
132 }; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
133 |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
134 public TailDuplicationPhase(CanonicalizerPhase canonicalizer) { |
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
135 this.canonicalizer = canonicalizer; |
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
136 } |
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
137 |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
138 @Override |
9329
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
139 protected void run(StructuredGraph graph, PhaseContext phaseContext) { |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
140 NodesToDoubles nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); |
9234
b9cf7d0b598e
removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9051
diff
changeset
|
141 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
142 // A snapshot is taken here, so that new MergeNode instances aren't considered for tail |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
143 // duplication. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
144 for (MergeNode merge : graph.getNodes(MergeNode.class).snapshot()) { |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9643
diff
changeset
|
145 if (!(merge instanceof LoopBeginNode) && nodeProbabilities.get(merge) >= TailDuplicationProbability.getValue()) { |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
146 tailDuplicate(merge, DEFAULT_DECISION, null, phaseContext, canonicalizer); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
147 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
148 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
149 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
150 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
151 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
152 * This method attempts to duplicate the tail of the given merge. The merge must not be a |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
153 * {@link LoopBeginNode}. If the merge is eligible for duplication (at least one fixed node in |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
154 * its tail, no {@link MonitorEnterNode}/ {@link MonitorExitNode}, non-null |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
155 * {@link MergeNode#stateAfter()}) then the decision callback is used to determine whether the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
156 * tail duplication should actually be performed. If replacements is non-null, then this list of |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
157 * {@link PiNode}s is used to replace one value per merge end. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
158 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
159 * @param merge The merge whose tail should be duplicated. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
160 * @param decision A callback that can make the final decision if tail duplication should occur |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
161 * or not. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
162 * @param replacements A list of {@link PiNode}s, or null. If this list is non-null then its |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
163 * size needs to match the merge's end count. Each entry can either be null or a |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
164 * {@link PiNode}, and is used to replace {@link PiNode#object()} with the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
165 * {@link PiNode} in the duplicated branch that corresponds to the entry. |
9329
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
166 * @param phaseContext |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
167 */ |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
168 public static boolean tailDuplicate(MergeNode merge, TailDuplicationDecision decision, List<GuardedValueNode> replacements, PhaseContext phaseContext, CanonicalizerPhase canonicalizer) { |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
169 assert !(merge instanceof LoopBeginNode); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
170 assert replacements == null || replacements.size() == merge.forwardEndCount(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
171 FixedNode fixed = merge; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
172 int fixedCount = 0; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
173 while (fixed instanceof FixedWithNextNode) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
174 fixed = ((FixedWithNextNode) fixed).next(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
175 fixedCount++; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
176 } |
8988
02f57662b6c4
remove monitor limitation form TailDuplicationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
8558
diff
changeset
|
177 if (fixedCount > 1) { |
10533
2faa1e7ef4f3
enable TailDuplication for MergeNodes without stateAfter
Lukas Stadler <lukas.stadler@jku.at>
parents:
10009
diff
changeset
|
178 metricDuplicationConsidered.increment(); |
2faa1e7ef4f3
enable TailDuplication for MergeNodes without stateAfter
Lukas Stadler <lukas.stadler@jku.at>
parents:
10009
diff
changeset
|
179 if (decision.doTransform(merge, fixedCount)) { |
2faa1e7ef4f3
enable TailDuplication for MergeNodes without stateAfter
Lukas Stadler <lukas.stadler@jku.at>
parents:
10009
diff
changeset
|
180 metricDuplicationPerformed.increment(); |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
181 new DuplicationOperation(merge, replacements, canonicalizer).duplicate(phaseContext); |
10533
2faa1e7ef4f3
enable TailDuplication for MergeNodes without stateAfter
Lukas Stadler <lukas.stadler@jku.at>
parents:
10009
diff
changeset
|
182 return true; |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
183 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
184 } |
8558
43ab11ee5524
counters for LoopFullUnrollPhase and TailDuplicationPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
7539
diff
changeset
|
185 return false; |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
186 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
187 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
188 /** |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
189 * This class encapsulates one tail duplication operation on a specific {@link MergeNode}. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
190 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
191 private static class DuplicationOperation { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
192 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
193 private final MergeNode merge; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
194 private final StructuredGraph graph; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
195 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
196 private final HashMap<ValueNode, PhiNode> bottomPhis = new HashMap<>(); |
10706
8d961f93725c
Use GuardedValueNode in the inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10533
diff
changeset
|
197 private final List<GuardedValueNode> replacements; |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
198 |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
199 private final CanonicalizerPhase canonicalizer; |
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
200 |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
201 /** |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
202 * Initializes the tail duplication operation without actually performing any work. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
203 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
204 * @param merge The merge whose tail should be duplicated. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
205 * @param replacements A list of replacement {@link PiNode}s, or null. If this is non-null, |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
206 * then the size of the list needs to match the number of end nodes at the merge. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
207 */ |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
208 public DuplicationOperation(MergeNode merge, List<GuardedValueNode> replacements, CanonicalizerPhase canonicalizer) { |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
209 this.merge = merge; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
210 this.replacements = replacements; |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9436
diff
changeset
|
211 this.graph = merge.graph(); |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
212 this.canonicalizer = canonicalizer; |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
213 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
214 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
215 /** |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
216 * Performs the actual tail duplication: |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
217 * <ul> |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
218 * <li>Creates a new {@link ValueAnchorNode} at the beginning of the duplicated area, an |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
219 * transfers all dependencies from the merge to this anchor.</li> |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
220 * <li>Determines the set of fixed nodes to be duplicated.</li> |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
221 * <li>Creates the new merge at the bottom of the duplicated area.</li> |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
222 * <li>Determines the complete set of duplicated nodes.</li> |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
223 * <li>Performs the actual duplication.</li> |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
224 * </ul> |
9329
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
225 * |
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
226 * @param phaseContext |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
227 */ |
9329
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
228 private void duplicate(PhaseContext phaseContext) { |
9234
b9cf7d0b598e
removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9051
diff
changeset
|
229 Debug.log("tail duplication at merge %s in %s", merge, graph.method()); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
230 |
9329
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
231 int startMark = graph.getMark(); |
fa188fbfe3fe
Perform only targeted canonicalization after tail duplication.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
232 |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
233 ValueAnchorNode anchor = addValueAnchor(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
234 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
235 // determine the fixed nodes that should be duplicated (currently: all nodes up until |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
236 // the first control |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
237 // split, end node, deopt or return. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
238 ArrayList<FixedNode> fixedNodes = new ArrayList<>(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
239 FixedNode fixed = merge.next(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
240 FrameState stateAfter = merge.stateAfter(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
241 while (fixed instanceof FixedWithNextNode) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
242 fixedNodes.add(fixed); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
243 if (fixed instanceof StateSplit && ((StateSplit) fixed).stateAfter() != null) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
244 stateAfter = ((StateSplit) fixed).stateAfter(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
245 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
246 fixed = ((FixedWithNextNode) fixed).next(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
247 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
248 |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9329
diff
changeset
|
249 AbstractEndNode endAfter = createNewMerge(fixed, stateAfter); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
250 MergeNode mergeAfter = endAfter.merge(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
251 fixedNodes.add(endAfter); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
252 final HashSet<Node> duplicatedNodes = buildDuplicatedNodeSet(fixedNodes, stateAfter); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
253 mergeAfter.clearEnds(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
254 expandDuplicated(duplicatedNodes, mergeAfter); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
255 |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9329
diff
changeset
|
256 List<AbstractEndNode> endSnapshot = merge.forwardEnds().snapshot(); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
257 List<PhiNode> phiSnapshot = merge.phis().snapshot(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
258 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
259 int endIndex = 0; |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9329
diff
changeset
|
260 for (final AbstractEndNode forwardEnd : merge.forwardEnds()) { |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
261 Map<Node, Node> duplicates; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
262 if (replacements == null || replacements.get(endIndex) == null) { |
11675
77d9f12797c5
Use NodeMap in inlining utility when number of nodes is high.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11652
diff
changeset
|
263 duplicates = graph.addDuplicates(duplicatedNodes, graph, duplicatedNodes.size(), (DuplicationReplacement) null); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
264 } else { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
265 HashMap<Node, Node> replace = new HashMap<>(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
266 replace.put(replacements.get(endIndex).object(), replacements.get(endIndex)); |
11675
77d9f12797c5
Use NodeMap in inlining utility when number of nodes is high.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11652
diff
changeset
|
267 duplicates = graph.addDuplicates(duplicatedNodes, graph, duplicatedNodes.size(), replace); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
268 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
269 for (Map.Entry<ValueNode, PhiNode> phi : bottomPhis.entrySet()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
270 phi.getValue().initializeValueAt(merge.forwardEndIndex(forwardEnd), (ValueNode) duplicates.get(phi.getKey())); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
271 } |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9329
diff
changeset
|
272 mergeAfter.addForwardEnd((AbstractEndNode) duplicates.get(endAfter)); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
273 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
274 // re-wire the duplicated ValueAnchorNode to the predecessor of the corresponding |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
275 // EndNode |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
276 FixedNode anchorDuplicate = (FixedNode) duplicates.get(anchor); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
277 ((FixedWithNextNode) forwardEnd.predecessor()).setNext(anchorDuplicate); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
278 // move dependencies on the ValueAnchorNode to the previous BeginNode |
9436
ae815a4c112a
Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9434
diff
changeset
|
279 AbstractBeginNode prevBegin = AbstractBeginNode.prevBegin(anchorDuplicate); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
280 anchorDuplicate.replaceAtUsages(prevBegin); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
281 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
282 // re-wire the phi duplicates to the correct input |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
283 for (PhiNode phi : phiSnapshot) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
284 PhiNode phiDuplicate = (PhiNode) duplicates.get(phi); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
285 phiDuplicate.replaceAtUsages(phi.valueAt(forwardEnd)); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
286 phiDuplicate.safeDelete(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
287 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
288 endIndex++; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
289 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
290 GraphUtil.killCFG(merge); |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9329
diff
changeset
|
291 for (AbstractEndNode forwardEnd : endSnapshot) { |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
292 forwardEnd.safeDelete(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
293 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
294 for (PhiNode phi : phiSnapshot) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
295 // these phis should go away, but they still need to be anchored to a merge to be |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
296 // valid... |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
297 if (phi.isAlive()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
298 phi.setMerge(mergeAfter); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
299 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
300 } |
11573
8a3d99fc36cf
Pass canonicalizer into tail duplication.
Roland Schatz <roland.schatz@oracle.com>
parents:
10706
diff
changeset
|
301 canonicalizer.applyIncremental(graph, phaseContext, startMark); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
302 Debug.dump(graph, "After tail duplication at %s", merge); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
303 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
304 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
305 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
306 * Inserts a new ValueAnchorNode after the merge and transfers all dependency-usages (not |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
307 * phis) to this ValueAnchorNode. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
308 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
309 * @return The new {@link ValueAnchorNode} that was created. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
310 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
311 private ValueAnchorNode addValueAnchor() { |
11711
f12b418ebc74
Allow only single input for value anchors.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11675
diff
changeset
|
312 ValueAnchorNode anchor = graph.add(new ValueAnchorNode(null)); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
313 graph.addAfterFixed(merge, anchor); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
314 for (Node usage : merge.usages().snapshot()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
315 if (usage instanceof PhiNode && ((PhiNode) usage).merge() == merge) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
316 // nothing to do |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
317 } else { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
318 usage.replaceFirstInput(merge, anchor); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
319 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
320 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
321 return anchor; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
322 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
323 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
324 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
325 * Given a set of fixed nodes, this method determines the set of fixed and floating nodes |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
326 * that needs to be duplicated, i.e., all nodes that due to data flow and other dependencies |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
327 * needs to be duplicated. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
328 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
329 * @param fixedNodes The set of fixed nodes that should be duplicated. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
330 * @param stateAfter The frame state of the merge that follows the set of fixed nodes. All |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
331 * {@link ValueNode}s reachable from this state are considered to be reachable |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
332 * from within the duplicated set of nodes. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
333 * @return The set of nodes that need to be duplicated. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
334 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
335 private HashSet<Node> buildDuplicatedNodeSet(final ArrayList<FixedNode> fixedNodes, FrameState stateAfter) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
336 final NodeBitMap aboveBound = graph.createNodeBitMap(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
337 final NodeBitMap belowBound = graph.createNodeBitMap(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
338 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
339 final Deque<Node> worklist = new ArrayDeque<>(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
340 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
341 // Build the set of nodes that have (transitive) usages within the duplicatedNodes. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
342 // This is achieved by iterating all nodes that are reachable via inputs from the the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
343 // fixed nodes. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
344 aboveBound.markAll(fixedNodes); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
345 worklist.addAll(fixedNodes); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
346 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
347 // the phis at the original merge should always be duplicated |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
348 for (PhiNode phi : merge.phis()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
349 aboveBound.mark(phi); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
350 worklist.add(phi); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
351 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
352 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
353 NodeClosure<Node> aboveClosure = new NodeClosure<Node>() { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
354 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
355 @Override |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
356 public void apply(Node usage, Node node) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
357 if (node instanceof PhiNode && !fixedNodes.contains(((PhiNode) node).merge())) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
358 // stop iterating: phis belonging to outside merges are known to be outside. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
359 } else if (node instanceof FixedNode) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
360 // stop iterating: fixed nodes within the given set are traversal roots |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
361 // anyway, and all other |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
362 // fixed nodes are known to be outside. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
363 } else if (!aboveBound.isMarked(node)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
364 worklist.add(node); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
365 aboveBound.mark(node); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
366 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
367 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
368 }; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
369 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
370 if (stateAfter != null) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
371 stateAfter.applyToNonVirtual(aboveClosure); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
372 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
373 while (!worklist.isEmpty()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
374 Node current = worklist.remove(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
375 for (Node input : current.inputs()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
376 aboveClosure.apply(current, input); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
377 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
378 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
379 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
380 // Build the set of nodes that have (transitive) inputs within the duplicatedNodes. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
381 // This is achieved by iterating all nodes that are reachable via usages from the fixed |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
382 // nodes. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
383 belowBound.markAll(fixedNodes); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
384 worklist.addAll(fixedNodes); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
385 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
386 // the phis at the original merge should always be duplicated |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
387 for (PhiNode phi : merge.phis()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
388 belowBound.mark(phi); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
389 worklist.add(phi); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
390 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
391 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
392 while (!worklist.isEmpty()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
393 Node current = worklist.remove(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
394 for (Node usage : current.usages()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
395 if (usage instanceof PhiNode && !fixedNodes.contains(((PhiNode) usage).merge())) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
396 // stop iterating: phis belonging to outside merges are known to be outside. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
397 } else if (usage instanceof FixedNode) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
398 // stop iterating: fixed nodes within the given set are traversal roots |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
399 // anyway, and all other |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
400 // fixed nodes are known to be outside. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
401 } else if (!belowBound.isMarked(usage)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
402 worklist.add(usage); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
403 belowBound.mark(usage); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
404 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
405 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
406 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
407 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
408 // build the intersection |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
409 belowBound.intersect(aboveBound); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
410 HashSet<Node> result = new HashSet<>(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
411 for (Node node : belowBound) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
412 result.add(node); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
413 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
414 return result; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
415 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
416 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
417 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
418 * Creates a new merge and end node construct at the end of the duplicated area. While it is |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
419 * useless in itself (merge with only one end) it simplifies the later duplication step. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
420 * |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
421 * @param successor The successor of the duplicated set of nodes, i.e., the first node that |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
422 * should not be duplicated. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
423 * @param stateAfterMerge The frame state that should be used for the merge. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
424 * @return The newly created end node. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
425 */ |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9329
diff
changeset
|
426 private AbstractEndNode createNewMerge(FixedNode successor, FrameState stateAfterMerge) { |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
427 MergeNode newBottomMerge = graph.add(new MergeNode()); |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9329
diff
changeset
|
428 AbstractEndNode newBottomEnd = graph.add(new EndNode()); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
429 newBottomMerge.addForwardEnd(newBottomEnd); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
430 newBottomMerge.setStateAfter(stateAfterMerge); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
431 ((FixedWithNextNode) successor.predecessor()).setNext(newBottomEnd); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
432 newBottomMerge.setNext(successor); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
433 return newBottomEnd; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
434 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
435 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
436 /** |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
437 * Expands the set of nodes to be duplicated by looking at a number of conditions: |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
438 * <ul> |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
439 * <li>{@link ValueNode}s that have usages on the outside need to be replaced with phis for |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
440 * the outside usages.</li> |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
441 * <li>Non-{@link ValueNode} nodes that have outside usages (frame states, virtual object |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
442 * states, ...) need to be cloned immediately for the outside usages.</li> |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
443 * <li>Nodes that have a {@link StampFactory#extension()} or |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
444 * {@link StampFactory#condition()} stamp need to be cloned immediately for the outside |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
445 * usages.</li> |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
446 * <li>Dependencies into the duplicated nodes will be replaced with dependencies on the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
447 * merge.</li> |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
448 * <li>Outside non-{@link ValueNode}s with usages within the duplicated set of nodes need to |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
449 * also be duplicated.</li> |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
450 * <li>Outside {@link ValueNode}s with {@link StampFactory#extension()} or |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
451 * {@link StampFactory#condition()} stamps that have usages within the duplicated set of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
452 * nodes need to also be duplicated.</li> |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
453 * </ul> |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
454 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
455 * @param duplicatedNodes The set of duplicated nodes that will be modified (expanded). |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
456 * @param newBottomMerge The merge that follows the duplicated set of nodes. It will be used |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
457 * for newly created phis and to as a target for dependencies that pointed into |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
458 * the duplicated set of nodes. |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
459 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
460 private void expandDuplicated(HashSet<Node> duplicatedNodes, MergeNode newBottomMerge) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
461 Deque<Node> worklist = new ArrayDeque<>(duplicatedNodes); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
462 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
463 while (!worklist.isEmpty()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
464 Node duplicated = worklist.remove(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
465 if (hasUsagesOutside(duplicated, duplicatedNodes)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
466 boolean cloneForOutsideUsages = false; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
467 if (duplicated instanceof ValueNode) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
468 ValueNode node = (ValueNode) duplicated; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
469 if (node.stamp() == StampFactory.dependency()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
470 // re-route dependencies to the merge |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
471 replaceUsagesOutside(node, newBottomMerge, duplicatedNodes); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
472 // TODO(ls) maybe introduce phis for dependencies |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
473 } else if (node.stamp() == StampFactory.extension() || node.stamp() == StampFactory.condition()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
474 cloneForOutsideUsages = true; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
475 } else { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
476 // introduce a new phi |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
477 PhiNode newPhi = bottomPhis.get(node); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
478 if (newPhi == null) { |
11652
f091e0d6f4f3
Disallow add for global value numberable node types. Introduce addWithoutUnique.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11573
diff
changeset
|
479 newPhi = graph.addWithoutUnique(new PhiNode(node.kind(), newBottomMerge)); |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
480 bottomPhis.put(node, newPhi); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
481 newPhi.addInput(node); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
482 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
483 replaceUsagesOutside(node, newPhi, duplicatedNodes); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
484 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
485 } else { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
486 cloneForOutsideUsages = true; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
487 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
488 if (cloneForOutsideUsages) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
489 // clone the offending node to the outside |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
490 Node newOutsideClone = duplicated.copyWithInputs(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
491 replaceUsagesOutside(duplicated, newOutsideClone, duplicatedNodes); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
492 // this might cause other nodes to have outside usages, we need to look at |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
493 // those as well |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
494 for (Node input : newOutsideClone.inputs()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
495 if (duplicatedNodes.contains(input)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
496 worklist.add(input); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
497 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
498 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
499 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
500 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
501 // check if this node has an input that lies outside and cannot be shared |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
502 for (Node input : duplicated.inputs()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
503 if (!duplicatedNodes.contains(input)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
504 boolean duplicateInput = false; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
505 if (input instanceof VirtualState) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
506 duplicateInput = true; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
507 } else if (input instanceof ValueNode) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
508 Stamp inputStamp = ((ValueNode) input).stamp(); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
509 if (inputStamp == StampFactory.extension() || inputStamp == StampFactory.condition()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
510 duplicateInput = true; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
511 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
512 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
513 if (duplicateInput) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
514 duplicatedNodes.add(input); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
515 worklist.add(input); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
516 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
517 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
518 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
519 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
520 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
521 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
522 /** |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
523 * Checks if the given node has usages that are not within the given set of nodes. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
524 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
525 * @param node The node whose usages are checked. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
526 * @param nodeSet The set of nodes that are considered to be "within". |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
527 * @return true if the given node has usages on the outside, false otherwise. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
528 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
529 private static boolean hasUsagesOutside(Node node, HashSet<Node> nodeSet) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
530 for (Node usage : node.usages()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
531 if (!nodeSet.contains(usage)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
532 return true; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
533 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
534 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
535 return false; |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
536 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
537 |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
538 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
539 * Replaces the given node with the given replacement at all usages that are not within the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
540 * given set of nodes. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7255
diff
changeset
|
541 * |
5786
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
542 * @param node The node to be replaced at outside usages. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
543 * @param replacement The node that replaced the given node at outside usages. |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
544 * @param nodeSet The set of nodes that are considered to be "within". |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
545 */ |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
546 private static void replaceUsagesOutside(Node node, Node replacement, HashSet<Node> nodeSet) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
547 for (Node usage : node.usages().snapshot()) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
548 if (!nodeSet.contains(usage)) { |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
549 usage.replaceFirstInput(node, replacement); |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
550 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
551 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
552 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
553 } |
f69a406355b2
new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
554 } |