annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/BaseReduction.java @ 16895:06c15e88d383

added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
author Doug Simon <doug.simon@oracle.com>
date Mon, 18 Aug 2014 14:04:21 +0200
parents 0815ca9d7747
children f57d86eb036f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
1 /*
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
4 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
8 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
13 * accompanied this code).
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
14 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
18 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
21 * questions.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
22 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.phases.common.cfs;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
24
16246
0815ca9d7747 move removeIfUnused from CanonicalizerTool to SimplifierTool
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16239
diff changeset
25 import java.util.*;
0815ca9d7747 move removeIfUnused from CanonicalizerTool to SimplifierTool
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16239
diff changeset
26
0815ca9d7747 move removeIfUnused from CanonicalizerTool to SimplifierTool
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16239
diff changeset
27 import com.oracle.graal.api.code.*;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.api.meta.*;
16246
0815ca9d7747 move removeIfUnused from CanonicalizerTool to SimplifierTool
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16239
diff changeset
29 import com.oracle.graal.compiler.common.type.*;
0815ca9d7747 move removeIfUnused from CanonicalizerTool to SimplifierTool
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16239
diff changeset
30 import com.oracle.graal.debug.*;
16239
de84713267fa use default methods to select Canonicalizable behavior
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15585
diff changeset
31 import com.oracle.graal.graph.spi.*;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.nodes.*;
16246
0815ca9d7747 move removeIfUnused from CanonicalizerTool to SimplifierTool
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16239
diff changeset
33 import com.oracle.graal.phases.graph.*;
0815ca9d7747 move removeIfUnused from CanonicalizerTool to SimplifierTool
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16239
diff changeset
34 import com.oracle.graal.phases.tiers.*;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
35
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
36 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
37 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
38 * For readability purposes the code realizing control-flow-sensitive reductions is chopped into
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
39 * several classes in an inheritance hierarchy, this class being their common ancestor. That way,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
40 * many dependencies can be ruled out immediately (e.g., private members of a class aren't needed by
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
41 * other classes). The whole thing is reminiscent of trait-based patterns, minus their
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
42 * disadvantages.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
43 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
44 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
45 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
46 * This class makes available little more than a few fields and a few utility methods used
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
47 * throughout the remaining components making up control-flow sensitive reductions.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
48 * </p>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
49 *
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
50 * <p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
51 * The laundry-list of all flow-sensitive reductions is summarized in
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
52 * {@link com.oracle.graal.phases.common.cfs.FlowSensitiveReduction}
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
53 * </p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
54 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
55 */
15583
d331b7c3d7c4 [single-pass-iter] start of evolution towards a node iterator less memory-hungry
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15498
diff changeset
56 public abstract class BaseReduction extends SinglePassNodeIterator<State> {
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
57
15498
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
58 protected static final DebugMetric metricCheckCastRemoved = Debug.metric("FSR-CheckCastRemoved");
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
59 protected static final DebugMetric metricGuardingPiNodeRemoved = Debug.metric("FSR-GuardingPiNodeRemoved");
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
60 protected static final DebugMetric metricFixedGuardNodeRemoved = Debug.metric("FSR-FixedGuardNodeRemoved");
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
61 protected static final DebugMetric metricMethodResolved = Debug.metric("FSR-MethodResolved");
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
62 protected static final DebugMetric metricUnconditionalDeoptInserted = Debug.metric("FSR-UnconditionalDeoptInserted");
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
63
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
64 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
65 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
66 * Upon visiting a {@link com.oracle.graal.nodes.FixedNode FixedNode} in
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
67 * {@link #node(com.oracle.graal.nodes.FixedNode)}, an impossible path may be detected. We'd
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
68 * like to insert an unconditional deoptimizing node as a hint for Dead Code Elimination to kill
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
69 * that branch. However that can't be made on the go (a
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
70 * {@link com.oracle.graal.nodes.ControlSinkNode} can't have successors). Thus their insertion
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
71 * is postponed till the end of a round of
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
72 * {@link com.oracle.graal.phases.common.cfs.FlowSensitiveReduction}.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
73 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
74 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
75 * @see State#impossiblePath()
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
76 * @see com.oracle.graal.phases.common.cfs.FlowSensitiveReduction#finished()
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
77 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
78 public static class PostponedDeopt {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
79
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
80 private final boolean goesBeforeFixed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
81 private final FixedWithNextNode fixed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
82 private final DeoptimizationReason deoptReason;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
83
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
84 public PostponedDeopt(boolean goesBeforeFixed, FixedWithNextNode fixed, DeoptimizationReason deoptReason) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
85 this.goesBeforeFixed = goesBeforeFixed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
86 this.fixed = fixed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
87 this.deoptReason = deoptReason;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
88 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
89
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
90 /*
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
91 * TODO Actually, we want to emit instructions to signal "should-not-reach-here". An
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
92 * imperfect substitute (as done here) is emitting FixedGuard(false).
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
93 * "should-not-reach-here" would be better for the runtime error it raises, thus pointing to
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
94 * a bug in FlowSensitiveReduction (the code was reachable, after all).
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15440
diff changeset
95 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
96 public void doRewrite(LogicNode falseConstant) {
15498
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
97 metricUnconditionalDeoptInserted.increment();
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
98 StructuredGraph graph = fixed.graph();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
99 // have to insert a FixedNode other than a ControlSinkNode
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16246
diff changeset
100 FixedGuardNode buckStopsHere = graph.add(FixedGuardNode.create(falseConstant, deoptReason, DeoptimizationAction.None));
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
101 if (goesBeforeFixed) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
102 fixed.replaceAtPredecessor(buckStopsHere);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
103 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
104 graph.addAfterFixed(fixed, buckStopsHere);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
105 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
106 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
107
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
108 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
109
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
110 protected static class PostponedDeopts extends ArrayList<PostponedDeopt> {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
111
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
112 private static final long serialVersionUID = 7188324432387121238L;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
113
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
114 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
115 * Enqueue adding a {@link com.oracle.graal.nodes.DeoptimizeNode} right before the fixed
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
116 * argument, will be done once we're done traversing the graph.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
117 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
118 * @see #finished()
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
119 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
120 void addDeoptBefore(FixedWithNextNode fixed, DeoptimizationReason deoptReason) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
121 add(new PostponedDeopt(true, fixed, deoptReason));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
122 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
123
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
124 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
125 * Enqueue adding a {@link com.oracle.graal.nodes.DeoptimizeNode} right after the fixed
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
126 * argument, will be done once we're done traversing the graph.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
127 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
128 * @see #finished()
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
129 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
130 void addDeoptAfter(FixedWithNextNode fixed, DeoptimizationReason deoptReason) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
131 add(new PostponedDeopt(false, fixed, deoptReason));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
132 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
133
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
134 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
135
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
136 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
137 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
138 * One of the promises of
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
139 * {@link com.oracle.graal.phases.common.cfs.EquationalReasoner#deverbosify(com.oracle.graal.graph.Node)}
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
140 * is that a "maximally reduced" node is returned. That is achieved in part by leveraging
16239
de84713267fa use default methods to select Canonicalizable behavior
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15585
diff changeset
141 * {@link Canonicalizable#canonical(com.oracle.graal.graph.spi.CanonicalizerTool)}. Doing so, in
de84713267fa use default methods to select Canonicalizable behavior
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15585
diff changeset
142 * turn, requires this subclass of {@link com.oracle.graal.graph.spi.CanonicalizerTool}.
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
143 * </p>
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
144 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
145 public final class Tool implements CanonicalizerTool {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
146
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
147 private final PhaseContext context;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
148
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
149 public Tool(PhaseContext context) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
150 this.context = context;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
151 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
152
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
153 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
154 public Assumptions assumptions() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
155 return context.getAssumptions();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
156 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
157
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
158 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
159 public MetaAccessProvider getMetaAccess() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
160 return context.getMetaAccess();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
161 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
162
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
163 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
164 public ConstantReflectionProvider getConstantReflection() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
165 return context.getConstantReflection();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
166 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
167
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
168 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
169 public boolean canonicalizeReads() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
170 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
171 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
172 } // end of class FlowSensitiveReduction.Tool
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
173
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
174 protected final LogicConstantNode trueConstant;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
175 protected final LogicConstantNode falseConstant;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
176 protected final ConstantNode nullConstant;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
177
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
178 protected final CanonicalizerTool tool;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
179 protected final StructuredGraph graph;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
180
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
181 protected EquationalReasoner reasoner;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
182
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
183 protected final PostponedDeopts postponedDeopts = new PostponedDeopts();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
184
15585
4d5b1e7a4d93 [single-pass-iter] early pruning of state map, visit a whole method
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15583
diff changeset
185 protected BaseReduction(StartNode start, State initialState, PhaseContext context) {
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
186 super(start, initialState);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
187 graph = start.graph();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
188 trueConstant = LogicConstantNode.tautology(graph);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
189 falseConstant = LogicConstantNode.contradiction(graph);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
190 nullConstant = ConstantNode.defaultForKind(Kind.Object, graph); // ConstantNode.forObject(null,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
191 // metaAccess, graph);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
192 tool = new Tool(context);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
193 reasoner = new EquationalReasoner(graph, tool, trueConstant, falseConstant, nullConstant);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
194 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
195
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
196 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
197 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
198 * Test whether the output's stamp is an upcast of that of the input. For example, upon
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
199 * replacing a CheckCastNode in
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
200 * {@link com.oracle.graal.phases.common.cfs.FlowSensitiveReduction#lowerCheckCastAnchorFriendlyWay(com.oracle.graal.nodes.java.CheckCastNode, com.oracle.graal.nodes.ValueNode)}
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
201 * we don't want to be left with an upcast, as it loses precision.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
202 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
203 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
204 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
205 * As usual with object stamps, they can be compared along different dimensions (alwaysNull,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
206 * etc.) It's enough for one such dimension to show precision loss for the end result to be
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
207 * reported as such.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
208 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
209 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
210 */
15440
10274c654f75 [flow-sensitive] no-precision-loss check in downcast
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
211 public static boolean precisionLoss(ValueNode input, ValueNode output) {
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
212 ObjectStamp inputStamp = (ObjectStamp) input.stamp();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
213 ObjectStamp outputStamp = (ObjectStamp) output.stamp();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
214 if (FlowUtil.isMorePrecise(inputStamp.type(), outputStamp.type())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
215 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
216 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
217 if (lessThan(outputStamp.alwaysNull(), inputStamp.alwaysNull())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
218 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
219 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
220 if (lessThan(outputStamp.nonNull(), inputStamp.nonNull())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
221 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
222 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
223 if (lessThan(outputStamp.isExactType(), inputStamp.isExactType())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
224 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
225 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
226 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
227 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
228
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
229 private static boolean lessThan(boolean a, boolean b) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
230 return a == false && b == true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
231 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
232
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
233 }