Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapePhase.java @ 11437:58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Tue, 27 Aug 2013 10:14:06 +0200 |
parents | 8a46f9081ea3 |
children | 5bbc028f4507 |
rev | line source |
---|---|
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.virtual.phases.ea; |
ea38da80dd29
refactor PEA into separate classes
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:
9809
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:
9809
diff
changeset
|
26 |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
27 import java.util.*; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
28 |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
29 import com.oracle.graal.graph.*; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.nodes.*; |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
31 import com.oracle.graal.nodes.java.*; |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
32 import com.oracle.graal.nodes.spi.*; |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
33 import com.oracle.graal.nodes.util.*; |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
34 import com.oracle.graal.nodes.virtual.*; |
10724
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
35 import com.oracle.graal.options.*; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
36 import com.oracle.graal.phases.graph.*; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
37 import com.oracle.graal.phases.schedule.*; |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
38 import com.oracle.graal.phases.tiers.*; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
39 |
9944
eef9281ec13b
pull basic algorithm of PartialEscapeAnalysisPhase into new base class EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
9916
diff
changeset
|
40 public class PartialEscapePhase extends EffectsPhase<PhaseContext> { |
9809
a8a5d5832def
first step towards extensibility of the escape analysis phase
Lukas Stadler <lukas.stadler@jku.at>
parents:
9755
diff
changeset
|
41 |
10724
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
42 //@formatter:off |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
43 @Option(help = "") |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
44 public static final OptionValue<Boolean> OptEarlyReadElimination = new OptionValue<>(true); |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
45 //@formatter:on |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
46 |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
47 private final boolean readElimination; |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
48 |
11437
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
10782
diff
changeset
|
49 public PartialEscapePhase(boolean iterative) { |
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
10782
diff
changeset
|
50 this(iterative, OptEarlyReadElimination.getValue()); |
10724
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
51 } |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
52 |
11437
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
10782
diff
changeset
|
53 public PartialEscapePhase(boolean iterative, boolean readElimination) { |
58b72cc17109
incremental canonicalization for PartialEscapePhase / EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
10782
diff
changeset
|
54 super(iterative ? EscapeAnalysisIterations.getValue() : 1); |
10724
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
55 this.readElimination = readElimination; |
6655
b01f9c391e17
first part of PEA refactoring
Lukas Stadler <lukas.stadler@jku.at>
parents:
6654
diff
changeset
|
56 } |
b01f9c391e17
first part of PEA refactoring
Lukas Stadler <lukas.stadler@jku.at>
parents:
6654
diff
changeset
|
57 |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
58 @Override |
9876
975cc822632a
PEA phase only needs PhaseContext
Lukas Stadler <lukas.stadler@jku.at>
parents:
9864
diff
changeset
|
59 protected void run(StructuredGraph graph, PhaseContext context) { |
9944
eef9281ec13b
pull basic algorithm of PartialEscapeAnalysisPhase into new base class EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
9916
diff
changeset
|
60 if (VirtualUtil.matches(graph, EscapeAnalyzeOnly.getValue())) { |
10724
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
61 if (readElimination || graph.getNodes().filterInterface(VirtualizableAllocation.class).isNotEmpty()) { |
9944
eef9281ec13b
pull basic algorithm of PartialEscapeAnalysisPhase into new base class EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
9916
diff
changeset
|
62 runAnalysis(graph, context); |
8556
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
63 } |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
64 } |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
65 } |
6655
b01f9c391e17
first part of PEA refactoring
Lukas Stadler <lukas.stadler@jku.at>
parents:
6654
diff
changeset
|
66 |
9944
eef9281ec13b
pull basic algorithm of PartialEscapeAnalysisPhase into new base class EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
9916
diff
changeset
|
67 @Override |
eef9281ec13b
pull basic algorithm of PartialEscapeAnalysisPhase into new base class EffectsPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
9916
diff
changeset
|
68 protected Closure<?> createEffectsClosure(PhaseContext context, SchedulePhase schedule) { |
10724
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
69 if (readElimination) { |
10782
8a46f9081ea3
rename ReadEliminationPE... to PEReadElimination...
Lukas Stadler <lukas.stadler@jku.at>
parents:
10724
diff
changeset
|
70 return new PEReadEliminationClosure(schedule, context.getRuntime(), context.getAssumptions()); |
10724
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
71 } else { |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
72 return new PartialEscapeClosure.Final(schedule, context.getRuntime(), context.getAssumptions()); |
0e671d5268d1
re-introduce early read elimination as part of escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9944
diff
changeset
|
73 } |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
74 } |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
75 |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
76 public static Map<Invoke, Double> getHints(StructuredGraph graph) { |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
77 NodesToDoubles probabilities = new ComputeProbabilityClosure(graph).apply(); |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
78 Map<Invoke, Double> hints = null; |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
79 for (CommitAllocationNode commit : graph.getNodes(CommitAllocationNode.class)) { |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
80 double sum = 0; |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
81 double invokeSum = 0; |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
82 for (Node commitUsage : commit.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
83 for (Node usage : commitUsage.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
84 if (usage instanceof FixedNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
85 sum += probabilities.get((FixedNode) usage); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
86 } else { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
87 if (usage instanceof MethodCallTargetNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
88 invokeSum += probabilities.get(((MethodCallTargetNode) usage).invoke().asNode()); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
89 } |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
90 for (Node secondLevelUage : usage.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
91 if (secondLevelUage instanceof FixedNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
92 sum += probabilities.get(((FixedNode) secondLevelUage)); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
93 } |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
94 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
95 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
96 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
97 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
98 // TODO(lstadler) get rid of this magic number |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
99 if (sum > 100 && invokeSum > 0) { |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
100 for (Node commitUsage : commit.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
101 for (Node usage : commitUsage.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
102 if (usage instanceof MethodCallTargetNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
103 if (hints == null) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
104 hints = new HashMap<>(); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
105 } |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
106 Invoke invoke = ((MethodCallTargetNode) usage).invoke(); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
107 hints.put(invoke, sum / invokeSum); |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
108 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
109 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
110 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
111 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
112 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
113 return hints; |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
114 } |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
115 } |