annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/FlowSensitiveReduction.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 1e63cb55f61d
children 37d6d174bc40
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
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
25 import com.oracle.graal.api.meta.*;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
26 import com.oracle.graal.graph.Node;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.nodes.*;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.nodes.calc.FloatingNode;
15442
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
29 import com.oracle.graal.nodes.calc.IsNullNode;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.nodes.extended.LoadHubNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.extended.NullCheckNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.nodes.java.*;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.compiler.common.type.IllegalStamp;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.nodes.type.StampTool;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.nodes.util.GraphUtil;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.phases.common.DeadCodeEliminationPhase;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.phases.tiers.PhaseContext;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
38
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
39 import java.lang.reflect.Modifier;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
40
15442
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
41 import static com.oracle.graal.api.meta.DeoptimizationAction.InvalidateReprofile;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
42 import static com.oracle.graal.api.meta.DeoptimizationReason.*;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
43
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>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
46 * In a nutshell, {@link com.oracle.graal.phases.common.cfs.FlowSensitiveReductionPhase} makes a
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
47 * single pass in dominator-based order over the graph:
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
48 * <ol>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
49 * <li>collecting properties of interest at control-splits; as well as for check-casts,
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
50 * guarding-pis, null-checks, and fixed-guards. Such flow-sensitive information is tracked via a
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
51 * dedicated {@link com.oracle.graal.phases.common.cfs.State state instance} for each control-flow
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
52 * path.</li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
53 * <li>performing rewritings that are safe at specific program-points. This comprises:
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
54 * <ul>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
55 * <li>simplification of side-effects free expressions, via
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
56 * {@link com.oracle.graal.phases.common.cfs.EquationalReasoner#deverbosify(com.oracle.graal.graph.Node)}
15498
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
57 * <ul>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
58 * <li>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
59 * at certain {@link com.oracle.graal.nodes.FixedNode}, see
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
60 * {@link #deverbosifyInputsInPlace(com.oracle.graal.nodes.ValueNode)}</li>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
61 * <li>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
62 * including for devirtualization, see
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
63 * {@link #deverbosifyInputsCopyOnWrite(com.oracle.graal.nodes.java.MethodCallTargetNode)}</li>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
64 * </ul>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
65 * </li>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
66 * <li>simplification of control-flow:
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
67 * <ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
68 * <li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
69 * by simplifying the input-condition to an {@link com.oracle.graal.nodes.IfNode}</li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
70 * <li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
71 * by eliminating redundant check-casts, guarding-pis, null-checks, and fixed-guards; where
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
72 * "redundancy" is determined using flow-sensitive information. In these cases, redundancy can be
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
73 * due to:
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
74 * <ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
75 * <li>an equivalent, existing, guarding node is already in scope (thus, use it as replacement and
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
76 * remove the redundant one)</li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
77 * <li>"always fails" (thus, replace the node in question with <code>FixedGuardNode(false)</code>)</li>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
78 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
79 * </li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
80 * </ul>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
81 * </li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
82 * </ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
83 * </li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
84 * </ol>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
85 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
86 *
15498
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
87 * <p>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
88 * Metrics for this phase are displayed starting with <code>FSR-</code>prefix, their counters are
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
89 * hosted in {@link com.oracle.graal.phases.common.cfs.BaseReduction},
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
90 * {@link com.oracle.graal.phases.common.cfs.EquationalReasoner} and
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
91 * {@link com.oracle.graal.phases.common.cfs.State}.
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
92 * </p>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
93 *
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
94 * @see com.oracle.graal.phases.common.cfs.CheckCastReduction
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
95 * @see com.oracle.graal.phases.common.cfs.GuardingPiReduction
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
96 * @see com.oracle.graal.phases.common.cfs.FixedGuardReduction
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
97 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
98 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
99 public class FlowSensitiveReduction extends FixedGuardReduction {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
100
15585
4d5b1e7a4d93 [single-pass-iter] early pruning of state map, visit a whole method
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15517
diff changeset
101 public FlowSensitiveReduction(StartNode start, State initialState, PhaseContext context) {
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
102 super(start, initialState, context);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
103 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
104
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 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
107 * This method performs two kinds of cleanup:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
108 * <ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
109 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
110 * marking as unreachable certain code-paths, as described in
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
111 * {@link com.oracle.graal.phases.common.cfs.BaseReduction.PostponedDeopt}</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
112 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
113 * Removing nodes not in use that were added during this phase, as described next.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
114 * </ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
115 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
116 *
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 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
119 * Methods like
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
120 * {@link com.oracle.graal.phases.common.cfs.FlowUtil#replaceInPlace(com.oracle.graal.graph.Node, com.oracle.graal.graph.Node, com.oracle.graal.graph.Node)}
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
121 * may result in old inputs becoming disconnected from the graph. It's not advisable to
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
122 * {@link com.oracle.graal.nodes.util.GraphUtil#tryKillUnused(com.oracle.graal.graph.Node)} at
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
123 * that moment, because one of the inputs that might get killed is one of {@link #nullConstant},
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
124 * {@link #falseConstant}, or {@link #trueConstant}; which thus could get killed too early,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
125 * before another invocation of
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
126 * {@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
127 * needs them. To recap,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
128 * {@link com.oracle.graal.nodes.util.GraphUtil#tryKillUnused(com.oracle.graal.graph.Node)} also
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
129 * recursively visits the inputs of the its argument.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
130 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
131 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
132 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
133 * This method goes over all of the nodes that deverbosification might have added, which are
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
134 * either:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
135 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
136 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
137 * {@link com.oracle.graal.nodes.calc.FloatingNode}, added by
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
138 * {@link com.oracle.graal.phases.common.cfs.EquationalReasoner#deverbosifyFloatingNode(com.oracle.graal.nodes.calc.FloatingNode)}
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
139 * ; or</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
140 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
141 * {@link com.oracle.graal.nodes.java.MethodCallTargetNode}, added by
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
142 * {@link #deverbosifyInputsCopyOnWrite(com.oracle.graal.nodes.java.MethodCallTargetNode)}</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
143 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
144 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
145 * Checking if they aren't in use, proceeding to remove them in that case.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
146 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
147 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
148 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
149 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
150 public void finished() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
151 if (!postponedDeopts.isEmpty()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
152 for (PostponedDeopt postponed : postponedDeopts) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
153 postponed.doRewrite(falseConstant);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
154 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
155 new DeadCodeEliminationPhase().apply(graph);
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 for (MethodCallTargetNode mcn : graph.getNodes().filter(MethodCallTargetNode.class)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
158 if (mcn.isAlive() && FlowUtil.lacksUsages(mcn)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
159 mcn.safeDelete();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
160 }
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 for (Node n : graph.getNodes().filter(FloatingNode.class)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
163 GraphUtil.tryKillUnused(n);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
164 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
165 assert !isAliveWithoutUsages(trueConstant);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
166 assert !isAliveWithoutUsages(falseConstant);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
167 assert !isAliveWithoutUsages(nullConstant);
15588
9a63ccd66007 [single-pass-iter] additional documentation and assertions
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15585
diff changeset
168 super.finished();
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
169 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
170
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
171 private static boolean isAliveWithoutUsages(FloatingNode node) {
15444
be6685c6a831 [flow-sensitive] readability
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15442
diff changeset
172 return node.isAlive() && FlowUtil.lacksUsages(node);
15388
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
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
175 private void registerControlSplit(Node pred, BeginNode begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
176 assert pred != null && begin != null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
177 assert !state.isUnreachable;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
178
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
179 if (begin instanceof LoopExitNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
180 state.clear();
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
181 /*
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
182 * TODO return or not? (by not returning we agree it's ok to update the state as below)
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
183 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
184 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
185
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
186 if (pred instanceof IfNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
187 registerIfNode((IfNode) pred, begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
188 } else if (pred instanceof TypeSwitchNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
189 registerTypeSwitchNode((TypeSwitchNode) pred, begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
190 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
191 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
192
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
193 private void registerIfNode(IfNode ifNode, BeginNode begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
194 final boolean isThenBranch = (begin == ifNode.trueSuccessor());
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 if (ifNode.condition() instanceof LogicConstantNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
197 final LogicConstantNode constCond = (LogicConstantNode) ifNode.condition();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
198 if (isThenBranch != constCond.getValue()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
199 state.impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
200 // let IfNode(constant) prune the dead-code control-path
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
201 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
202 }
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 if (state.isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
205 if (!(ifNode.condition() instanceof LogicConstantNode)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
206 // if condition constant, no need to add a Deopt node
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
207 postponedDeopts.addDeoptAfter(begin, UnreachedCode);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
208 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
209 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
210 state.addFact(isThenBranch, ifNode.condition(), begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
211 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
212 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
213
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
214 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
215 * TODO When tracking integer-stamps, the state at each successor of a TypeSwitchNode should
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
216 * track an integer-stamp for the LoadHubNode (meet over the constants leading to that
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
217 * successor). However, are LoadHubNode-s shared frequently enough?
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
218 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
219 private void registerTypeSwitchNode(TypeSwitchNode typeSwitch, BeginNode begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
220 if (typeSwitch.value() instanceof LoadHubNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
221 LoadHubNode loadHub = (LoadHubNode) typeSwitch.value();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
222 ResolvedJavaType type = null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
223 for (int i = 0; i < typeSwitch.keyCount(); i++) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
224 if (typeSwitch.keySuccessor(i) == begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
225 if (type == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
226 type = typeSwitch.typeAt(i);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
227 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
228 type = FlowUtil.widen(type, typeSwitch.typeAt(i));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
229 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
230 }
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 if (type == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
233 // `begin` denotes the default case of the TypeSwitchNode
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
234 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
235 }
15445
bda013e0d8bb [flow-sensitive] bug fix, registerTypeSwitchNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15444
diff changeset
236 // it's unwarranted to assume loadHub.object() to be non-null
16219
24c30ecf930f rename object() to getValue() in LoadHubNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15722
diff changeset
237 state.trackCC(loadHub.getValue(), type, begin);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
238 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
239 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
240
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
241 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
242 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
243 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
244 * Reduce input nodes based on the state at the program point for the argument (ie, based on
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
245 * "valid facts" only, without relying on any floating-guard-assumption).
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
246 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
247 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
248 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
249 * For each (direct or indirect) child, a copy-on-write version is made in case any of its
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
250 * children changed, with the copy accommodating the updated children. If the parent was shared,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
251 * copy-on-write prevents the updates from becoming visible to anyone but the invoker of this
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
252 * method.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
253 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
254 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
255 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
256 * <b> Please note the parent node is mutated upon any descendant changing. No copy-on-write is
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
257 * performed for the parent node itself. </b>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
258 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
259 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
260 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
261 * In more detail, for each direct {@link com.oracle.graal.nodes.ValueNode} input of the node at
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
262 * hand,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
263 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
264 * <ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
265 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
266 * Obtain a lazy-copied version (via spanning tree) of the DAG rooted at the input-usage in
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
267 * question. Lazy-copying is done by walking a spanning tree of the original DAG, stopping at
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
268 * non-FloatingNodes but transitively walking FloatingNodes and their inputs. Upon arriving at a
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
269 * (floating) node N, the state's facts are checked to determine whether a constant C can be
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
270 * used instead in the resulting lazy-copied DAG. A NodeBitMap is used to realize the spanning
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
271 * tree.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
272 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
273 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
274 * Provided one or more N-to-C node replacements took place, the resulting lazy-copied DAG has a
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
275 * parent different from the original (ie different object identity) which indicates the
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
276 * (copied, updated) DAG should replace the original via replaceFirstInput(), and inferStamp()
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
277 * should be invoked to reflect the updated inputs.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
278 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
279 * </ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
280 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
281 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
282 * @return whether any reduction was performed on the inputs of the arguments.
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
283 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
284 public boolean deverbosifyInputsInPlace(ValueNode parent) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
285 boolean changed = false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
286 for (ValueNode i : FlowUtil.distinctValueAndConditionInputs(parent)) {
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
287 assert !(i instanceof GuardNode) : "This phase not intended to run during MidTier";
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
288 ValueNode j = (ValueNode) reasoner.deverbosify(i);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
289 if (i != j) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
290 changed = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
291 FlowUtil.replaceInPlace(parent, i, j);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
292 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
293 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
294 if (changed) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
295 FlowUtil.inferStampAndCheck(parent);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
296 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
297 return changed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
298 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
299
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
300 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
301 * Similar to {@link #deverbosifyInputsInPlace(com.oracle.graal.nodes.ValueNode)}, except that
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
302 * not the parent but a fresh clone is updated upon any of its children changing.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
303 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
304 * @return the original parent if no updated took place, a copy-on-write version of it
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
305 * otherwise.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
306 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
307 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
308 private MethodCallTargetNode deverbosifyInputsCopyOnWrite(MethodCallTargetNode parent) {
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
309 final CallTargetNode.InvokeKind ik = parent.invokeKind();
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
310 final boolean shouldTryDevirt = (ik == CallTargetNode.InvokeKind.Interface || ik == CallTargetNode.InvokeKind.Virtual);
15517
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
311 boolean shouldDowncastReceiver = shouldTryDevirt;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
312 MethodCallTargetNode changed = null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
313 for (ValueNode i : FlowUtil.distinctValueAndConditionInputs(parent)) {
15517
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
314 ValueNode j = (ValueNode) reasoner.deverbosify(i);
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
315 if (shouldDowncastReceiver) {
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
316 shouldDowncastReceiver = false;
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
317 j = reasoner.downcast(j);
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
318 }
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
319 if (i != j) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
320 assert j != parent;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
321 if (changed == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
322 changed = (MethodCallTargetNode) parent.copyWithInputs();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
323 reasoner.added.add(changed);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
324 // copyWithInputs() implies graph.unique(changed)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
325 assert changed.isAlive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
326 assert FlowUtil.lacksUsages(changed);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
327 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
328 FlowUtil.replaceInPlace(changed, i, j);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
329 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
330 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
331 if (changed == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
332 return parent;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
333 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
334 FlowUtil.inferStampAndCheck(changed);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
335 /*
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
336 * No need to rememberSubstitution() because not called from deverbosify(). In detail, it's
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
337 * only deverbosify() that skips visited nodes (thus we'd better have recorded any
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
338 * substitutions we want for them). Not this case.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
339 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
340 return changed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
341 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
342
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
343 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
344 * Precondition: This method assumes that either:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
345 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
346 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
347 * <li>the state has already stabilized (ie no more pending iterations in the "iterative"
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
348 * dataflow algorithm); or</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
349 * <li>any rewritings made based on the state in its current form are conservative enough to be
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
350 * safe.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
351 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
352 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
353 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
354 * The overarching goal is to perform just enough rewriting to trigger other phases (
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
355 * {@link com.oracle.graal.graph.spi.SimplifierTool SimplifierTool},
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
356 * {@link com.oracle.graal.phases.common.DeadCodeEliminationPhase DeadCodeEliminationPhase},
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
357 * etc) to perform the bulk of rewriting, thus lowering the maintenance burden.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
358 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
359 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
360 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
361 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
362 protected void node(FixedNode node) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
363
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
364 assert node.isAlive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
365
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
366 /*-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
367 * Step 1: Unreachable paths are still visited (PostOrderNodeIterator requires all ends
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
368 * of a merge to have been visited), but time is saved by neither updating the state nor
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
369 * rewriting anything while on an an unreachable path.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
370 *-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
371 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
372 if (state.isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
373 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
374 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
375
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
376 /*-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
377 * Step 2: For an AbstractBeginNode, determine whether this path is reachable, register
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
378 * any associated guards.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
379 *-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
380 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
381 if (node instanceof BeginNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
382 BeginNode begin = (BeginNode) node;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
383 Node pred = node.predecessor();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
384
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
385 if (pred != null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
386 registerControlSplit(pred, begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
387 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
388 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
389 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
390
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
391 /*-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
392 * Step 3: Check whether EquationalReasoner caches should be cleared upon state updates.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
393 *-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
394 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
395 reasoner.updateState(state);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
396
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
397 /*-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
398 * Step 4: Whatever special-case handling makes sense for the FixedNode at hand before
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
399 * its inputs are reduced.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
400 *-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
401 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
402
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
403 if (node instanceof AbstractEndNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
404 visitAbstractEndNode((AbstractEndNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
405 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
406 } else if (node instanceof Invoke) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
407 visitInvoke((Invoke) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
408 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
409 } else if (node instanceof CheckCastNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
410 // it's important not to call deverbosification for visitCheckCastNode()
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
411 visitCheckCastNode((CheckCastNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
412 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
413 } else if (node instanceof GuardingPiNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
414 visitGuardingPiNode((GuardingPiNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
415 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
416 } else if (node instanceof NullCheckNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
417 visitNullCheckNode((NullCheckNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
418 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
419 } else if (node instanceof FixedGuardNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
420 visitFixedGuardNode((FixedGuardNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
421 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
422 } else if (node instanceof ConditionAnchorNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
423 // ConditionAnchorNode shouldn't occur during HighTier
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
424 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
425 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
426
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
427 /*-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
428 * Step 5: After special-case handling, we do our best for those FixedNode-s
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
429 * where the effort to reduce their inputs might pay off.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
430 *
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
431 * Why is this useful? For example, by the time the BeginNode for an If-branch
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
432 * is visited (in general a ControlSplitNode), the If-condition will have gone already
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
433 * through simplification (and thus potentially have been reduced to a
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
434 * LogicConstantNode).
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
435 *-------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
436 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
437 boolean paysOffToReduce = false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
438 if (node instanceof ControlSplitNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
439 // desire to simplify control flow
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
440 paysOffToReduce = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
441 } else if (node instanceof ReturnNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
442 paysOffToReduce = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
443 } else if (node instanceof AccessFieldNode || node instanceof AccessArrayNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
444 // desire to remove null-checks
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
445 paysOffToReduce = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
446 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
447
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
448 // TODO comb remaining FixedWithNextNode subclasses, pick those with chances of paying-off
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
449
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
450 // TODO UnsafeLoadNode takes a condition
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
451
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
452 if (paysOffToReduce) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
453 deverbosifyInputsInPlace(node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
454 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
455
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
456 /*---------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
457 * Step 6: Any additional special-case handling, this time after having inputs reduced.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
458 * For example, leverage anchors provided by the FixedNode, to add facts to the factbase.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
459 *---------------------------------------------------------------------------------------
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
460 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
461
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
462 // TODO some nodes are GuardingNodes (eg, FixedAccessNode) we could use them to track state
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
463 // TODO other nodes are guarded (eg JavaReadNode), thus *their* guards could be replaced.
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
464
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
465 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
466
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
467 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
468 * In case the scrutinee:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
469 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
470 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
471 * <li>is known to be null, an unconditional deopt is added.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
472 * <li>is known to be non-null, the NullCheckNode is removed.</li>
15442
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
473 * <li>otherwise, the NullCheckNode is lowered to a FixedGuardNode which then allows using it as
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
474 * anchor for state-tracking.</li>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
475 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
476 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
477 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
478 * Precondition: the input (ie, object) hasn't been deverbosified yet.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
479 * </p>
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
480 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
481 private void visitNullCheckNode(NullCheckNode ncn) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
482 ValueNode object = ncn.getObject();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
483 if (state.isNull(object)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
484 postponedDeopts.addDeoptBefore(ncn, NullCheckException);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
485 state.impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
486 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
487 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
488 if (state.isNonNull(object)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
489 /*
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
490 * Redundant NullCheckNode. Unlike GuardingPiNode or FixedGuardNode, NullCheckNode-s
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
491 * aren't used as GuardingNode-s, thus in this case can be removed without further ado.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
492 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
493 assert FlowUtil.lacksUsages(ncn);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
494 graph.removeFixed(ncn);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
495 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
496 }
15442
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
497 /*
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
498 * Lower the NullCheckNode to a FixedGuardNode which then allows using it as anchor for
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
499 * state-tracking. TODO the assumption here is that the code emitted for the resulting
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
500 * FixedGuardNode is as efficient as for NullCheckNode.
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
501 */
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: 16563
diff changeset
502 IsNullNode isNN = graph.unique(IsNullNode.create(object));
15442
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
503 reasoner.added.add(isNN);
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: 16563
diff changeset
504 FixedGuardNode nullCheck = graph.add(FixedGuardNode.create(isNN, UnreachedCode, InvalidateReprofile, true));
15442
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
505 graph.replaceFixedWithFixed(ncn, nullCheck);
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
506
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
507 state.trackNN(object, nullCheck);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
508 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
509
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
510 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
511 * The {@link com.oracle.graal.nodes.AbstractEndNode} at the end of the current code path
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
512 * contributes values to {@link com.oracle.graal.nodes.PhiNode}s. Now is a good time to
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
513 * {@link EquationalReasoner#deverbosify(com.oracle.graal.graph.Node)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
514 * EquationalReasoner#deverbosify} those values.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
515 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
516 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
517 * Precondition: inputs haven't been deverbosified yet.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
518 * </p>
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
519 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
520 private void visitAbstractEndNode(AbstractEndNode endNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
521 MergeNode merge = endNode.merge();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
522 for (PhiNode phi : merge.phis()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
523 if (phi instanceof ValuePhiNode && phi.getKind() == Kind.Object) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
524 assert phi.verify();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
525 int index = merge.phiPredecessorIndex(endNode);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
526 ValueNode original = phi.valueAt(index);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
527 ValueNode reduced = (ValueNode) reasoner.deverbosify(original);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
528 if (reduced != original) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
529 phi.setValueAt(index, reduced);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
530 // `original` if unused will be removed in finished()
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
531 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
532 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
533 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
534 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
535
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
536 /**
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
537 * <p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
538 * For one or more `invoke` arguments, flow-sensitive information may suggest their narrowing or
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
539 * simplification. In those cases, a new
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
540 * {@link com.oracle.graal.nodes.java.MethodCallTargetNode MethodCallTargetNode} is prepared
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
541 * just for this callsite, consuming reduced arguments.
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
542 * </p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
543 *
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
544 * <p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
545 * Specializing the {@link com.oracle.graal.nodes.java.MethodCallTargetNode
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
546 * MethodCallTargetNode} as described above may enable two optimizations:
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
547 * <ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
548 * <li>
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
549 * devirtualization of an {@link com.oracle.graal.nodes.CallTargetNode.InvokeKind#Interface} or
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
550 * {@link com.oracle.graal.nodes.CallTargetNode.InvokeKind#Virtual} callsite (devirtualization
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
551 * made possible after narrowing the type of the receiver)</li>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
552 * <li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
553 * (future work) actual-argument-aware inlining, ie, to specialize callees on the types of
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
554 * arguments other than the receiver (examples: multi-methods, the inlining problem, lambdas as
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
555 * arguments).</li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
556 *
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
557 * </ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
558 * </p>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
559 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
560 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
561 * Precondition: inputs haven't been deverbosified yet.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
562 * </p>
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
563 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
564 private void visitInvoke(Invoke invoke) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
565 if (invoke.asNode().stamp() instanceof IllegalStamp) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
566 return; // just to be safe
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
567 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
568 boolean isMethodCallTarget = invoke.callTarget() instanceof MethodCallTargetNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
569 if (!isMethodCallTarget) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
570 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
571 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
572 FlowUtil.replaceInPlace(invoke.asNode(), invoke.callTarget(), deverbosifyInputsCopyOnWrite((MethodCallTargetNode) invoke.callTarget()));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
573 MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
574 if (callTarget.invokeKind() != CallTargetNode.InvokeKind.Interface && callTarget.invokeKind() != CallTargetNode.InvokeKind.Virtual) {
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
575 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
576 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
577 ValueNode receiver = callTarget.receiver();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
578 if (receiver == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
579 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
580 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
581 if (!FlowUtil.hasLegalObjectStamp(receiver)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
582 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
583 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
584 Witness w = state.typeInfo(receiver);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
585 ResolvedJavaType type;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
586 ResolvedJavaType stampType = StampTool.typeOrNull(receiver);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
587 if (w == null || w.cluelessAboutType()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
588 // can't improve on stamp but wil try to devirtualize anyway
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
589 type = stampType;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
590 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
591 type = FlowUtil.tighten(w.type(), stampType);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
592 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
593 if (type == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
594 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
595 }
15722
c583759bbcfd ResolvedJavaType.resolveMethod now takes a callerType that is used to check access rules. Make it work for default methods.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15588
diff changeset
596 ResolvedJavaMethod method = type.resolveMethod(callTarget.targetMethod(), invoke.getContextType());
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
597 if (method == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
598 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
599 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
600 if (method.canBeStaticallyBound() || Modifier.isFinal(type.getModifiers())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
601 metricMethodResolved.increment();
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
602 callTarget.setInvokeKind(CallTargetNode.InvokeKind.Special);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
603 callTarget.setTargetMethod(method);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
604 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
605 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
606
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
607 }