Mercurial > hg > truffle
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java @ 11626:340e67bf1758
Rename GuardsPhase to GuardsStage to avoid confusion with existing Phases
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 13 Sep 2013 14:47:04 +0200 |
parents | ae619d70bf4b |
children | 1ca5e39d0433 |
rev | line source |
---|---|
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved. |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
4 * |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
8 * |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
14 * |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
18 * |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
21 * questions. |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
22 */ |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.phases.common; |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.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:
9646
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:
9646
diff
changeset
|
26 |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
27 import java.util.*; |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
28 import java.util.Map.Entry; |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
29 |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.graph.*; |
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.*; |
11626
340e67bf1758
Rename GuardsPhase to GuardsStage to avoid confusion with existing Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11579
diff
changeset
|
32 import com.oracle.graal.nodes.StructuredGraph.GuardsStage; |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
33 import com.oracle.graal.nodes.calc.*; |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.cfg.*; |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
35 import com.oracle.graal.nodes.extended.*; |
8299
22cab6e509a3
Remove orphaned condition in implicit null check detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8296
diff
changeset
|
36 import com.oracle.graal.nodes.util.*; |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 import com.oracle.graal.phases.*; |
10081
20fd8760cb34
pull ScheduledNodeIterator into separate class
Lukas Stadler <lukas.stadler@jku.at>
parents:
9864
diff
changeset
|
38 import com.oracle.graal.phases.graph.*; |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
39 import com.oracle.graal.phases.schedule.*; |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
40 import com.oracle.graal.phases.tiers.*; |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
41 |
11396
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
42 /** |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
43 * This phase lowers {@link GuardNode GuardNodes} into corresponding control-flow structure and |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
44 * {@link DeoptimizeNode DeoptimizeNodes}. |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
45 * |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
46 * This allow to enter a phase of the compiler where all node that may cause deoptimization are |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
47 * fixed. |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
48 * |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
49 * It first makes a schedule in order to know where the control flow should be placed. Then, for |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
50 * each block, it applies two passes. The first one tries to replace null-check guards with implicit |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
51 * null checks performed by access to the objects that need to be null checked. The second phase |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
52 * does the actual control-flow expansion of the remaining {@link GuardNode GuardNodes}. |
a268b0de65d6
Add some javadoc for GuardLoweringPhase, ConvertDeoptimizeToGuardPhase and DeoptimizeNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10081
diff
changeset
|
53 */ |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
54 public class GuardLoweringPhase extends BasePhase<MidTierContext> { |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
55 |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
56 private static class UseImplicitNullChecks extends ScheduledNodeIterator { |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
57 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
58 private final IdentityHashMap<ValueNode, GuardNode> nullGuarded = new IdentityHashMap<>(); |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
59 private final int implicitNullCheckLimit; |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
60 |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
61 UseImplicitNullChecks(int implicitNullCheckLimit) { |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
62 this.implicitNullCheckLimit = implicitNullCheckLimit; |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
63 } |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
64 |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
65 @Override |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
66 protected void processNode(Node node) { |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
67 if (node instanceof GuardNode) { |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
68 processGuard(node); |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
69 } else if (node instanceof Access) { |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
70 processAccess((Access) node); |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
71 } |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
72 if (node instanceof StateSplit && ((StateSplit) node).stateAfter() != null) { |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
73 nullGuarded.clear(); |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
74 } else { |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
75 Iterator<Entry<ValueNode, GuardNode>> it = nullGuarded.entrySet().iterator(); |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
76 while (it.hasNext()) { |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
77 Entry<ValueNode, GuardNode> entry = it.next(); |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
78 GuardNode guard = entry.getValue(); |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
79 if (guard.usages().contains(node)) { |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
80 it.remove(); |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
81 } |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
82 } |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
83 } |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
84 } |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
85 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
86 private void processAccess(Access access) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
87 GuardNode guard = nullGuarded.get(access.object()); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
88 if (guard != null && isImplicitNullCheck(access.nullCheckLocation())) { |
9646
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
89 access.setGuard(guard.getGuard()); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
90 Access fixedAccess = access; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
91 if (access instanceof FloatingAccessNode) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
92 fixedAccess = ((FloatingAccessNode) access).asFixedNode(); |
9089
5ab06146e985
Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8404
diff
changeset
|
93 replaceCurrent((FixedWithNextNode) fixedAccess.asNode()); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
94 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
95 assert fixedAccess instanceof FixedNode; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
96 fixedAccess.setNullCheck(true); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
97 LogicNode condition = guard.condition(); |
9089
5ab06146e985
Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8404
diff
changeset
|
98 guard.replaceAndDelete(fixedAccess.asNode()); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
99 if (condition.usages().isEmpty()) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
100 GraphUtil.killWithUnusedFloatingInputs(condition); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
101 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
102 nullGuarded.remove(fixedAccess.object()); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
103 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
104 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
105 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
106 private void processGuard(Node node) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
107 GuardNode guard = (GuardNode) node; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
108 if (guard.negated() && guard.condition() instanceof IsNullNode) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
109 ValueNode obj = ((IsNullNode) guard.condition()).object(); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
110 nullGuarded.put(obj, guard); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
111 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
112 } |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
113 |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
114 private boolean isImplicitNullCheck(LocationNode location) { |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
115 if (location instanceof ConstantLocationNode) { |
9525
038fa65cbd8d
Consistent naming of accessor methods in the LocationNode class hierarchy
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9512
diff
changeset
|
116 return ((ConstantLocationNode) location).getDisplacement() < implicitNullCheckLimit; |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
117 } else { |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
118 return false; |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
119 } |
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
120 } |
8295
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
121 } |
60f90b4b6a12
Implement implicit null check on HIR during guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8221
diff
changeset
|
122 |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
123 private static class LowerGuards extends ScheduledNodeIterator { |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
124 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
125 private final Block block; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
126 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
127 public LowerGuards(Block block) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
128 this.block = block; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
129 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
130 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
131 @Override |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
132 protected void processNode(Node node) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
133 if (node instanceof GuardNode) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
134 GuardNode guard = (GuardNode) node; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
135 if (guard.negated() && guard.condition() instanceof IsNullNode) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
136 lowerToNullCheck(guard); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
137 } else { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
138 lowerToIf(guard); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
139 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
140 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
141 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
142 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
143 private void lowerToIf(GuardNode guard) { |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9525
diff
changeset
|
144 StructuredGraph graph = guard.graph(); |
9436
ae815a4c112a
Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9268
diff
changeset
|
145 AbstractBeginNode fastPath = graph.add(new BeginNode()); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
146 DeoptimizeNode deopt = graph.add(new DeoptimizeNode(guard.action(), guard.reason())); |
9436
ae815a4c112a
Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9268
diff
changeset
|
147 AbstractBeginNode deoptBranch = AbstractBeginNode.begin(deopt); |
ae815a4c112a
Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9268
diff
changeset
|
148 AbstractBeginNode trueSuccessor; |
ae815a4c112a
Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9268
diff
changeset
|
149 AbstractBeginNode falseSuccessor; |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
150 insertLoopExits(deopt); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
151 if (guard.negated()) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
152 trueSuccessor = deoptBranch; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
153 falseSuccessor = fastPath; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
154 } else { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
155 trueSuccessor = fastPath; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
156 falseSuccessor = deoptBranch; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
157 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
158 IfNode ifNode = graph.add(new IfNode(guard.condition(), trueSuccessor, falseSuccessor, trueSuccessor == fastPath ? 1 : 0)); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
159 guard.replaceAndDelete(fastPath); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
160 insert(ifNode, fastPath); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
161 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
162 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
163 private void lowerToNullCheck(GuardNode guard) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
164 IsNullNode isNull = (IsNullNode) guard.condition(); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
165 NullCheckNode nullCheck = guard.graph().add(new NullCheckNode(isNull.object())); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
166 replaceCurrent(nullCheck); |
9512
05b8a812b487
Remove dead IsNull nodes in Guard lowering phase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9436
diff
changeset
|
167 if (isNull.usages().isEmpty()) { |
05b8a812b487
Remove dead IsNull nodes in Guard lowering phase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9436
diff
changeset
|
168 isNull.safeDelete(); |
05b8a812b487
Remove dead IsNull nodes in Guard lowering phase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9436
diff
changeset
|
169 } |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
170 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
171 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
172 private void insertLoopExits(DeoptimizeNode deopt) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
173 Loop loop = block.getLoop(); |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9525
diff
changeset
|
174 StructuredGraph graph = deopt.graph(); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
175 while (loop != null) { |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
176 LoopExitNode exit = graph.add(new LoopExitNode(loop.loopBegin())); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
177 graph.addBeforeFixed(deopt, exit); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
178 loop = loop.parent; |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
179 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
180 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
181 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
182 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
183 @Override |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
184 protected void run(StructuredGraph graph, MidTierContext context) { |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
185 SchedulePhase schedule = new SchedulePhase(); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
186 schedule.apply(graph); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
187 |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
188 for (Block block : schedule.getCFG().getBlocks()) { |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
189 processBlock(block, schedule, context.getTarget().implicitNullCheckLimit); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
190 } |
11579
ae619d70bf4b
Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11396
diff
changeset
|
191 |
11626
340e67bf1758
Rename GuardsPhase to GuardsStage to avoid confusion with existing Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11579
diff
changeset
|
192 graph.setGuardsPhase(GuardsStage.FIXED_DEOPTS); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
193 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
194 |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
195 private static void processBlock(Block block, SchedulePhase schedule, int implicitNullCheckLimit) { |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
196 List<ScheduledNode> nodes = schedule.nodesFor(block); |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9646
diff
changeset
|
197 if (OptImplicitNullChecks.getValue() && implicitNullCheckLimit > 0) { |
9268
2d80e5f17bf8
Make GuardLoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9203
diff
changeset
|
198 new UseImplicitNullChecks(implicitNullCheckLimit).processNodes(nodes, block.getBeginNode()); |
8404
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
199 } |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
200 new LowerGuards(block).processNodes(nodes, block.getBeginNode()); |
24ddd568aa0c
Refactor GuardLoweringPhase: use the same iterator code for implict null checks and guard lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8403
diff
changeset
|
201 } |
8207
ed880b9992b4
Add GuardLoweringPhase which transforms floating guards into fixed if+deopt
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
202 } |