annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/FlowSensitiveReduction.java @ 18191:839f97696479

Rename ResolvedJavaMethod.resolvedMethod() to resolveConcreteMethod() the reflect its actual behavior.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 29 Oct 2014 18:54:32 +0100
parents 86888df288ec
children fad37aaed6d2
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
17065
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
25 import static com.oracle.graal.api.meta.DeoptimizationAction.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
26 import static com.oracle.graal.api.meta.DeoptimizationReason.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
27 import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
28
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
29 import java.lang.reflect.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
30
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.api.meta.*;
17065
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
32 import com.oracle.graal.compiler.common.type.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
33 import com.oracle.graal.graph.*;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.nodes.*;
17065
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
35 import com.oracle.graal.nodes.calc.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
36 import com.oracle.graal.nodes.extended.*;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.java.*;
17065
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
38 import com.oracle.graal.nodes.type.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
39 import com.oracle.graal.nodes.util.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
40 import com.oracle.graal.phases.common.*;
37d6d174bc40 denote certain applications of DeadCodeEliminationPhase as optional and only run them if -G:-ReduceDCE
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
41 import com.oracle.graal.phases.tiers.*;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
42
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 * <p>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
45 * 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
46 * 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
47 * <ol>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
48 * <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
49 * 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
50 * 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
51 * path.</li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
52 * <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
53 * <ul>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
54 * <li>simplification of side-effects free expressions, via
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
55 * {@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
56 * <ul>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
57 * <li>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
58 * 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
59 * {@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
60 * <li>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
61 * including for devirtualization, see
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
62 * {@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
63 * </ul>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
64 * </li>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
65 * <li>simplification of control-flow:
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
66 * <ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
67 * <li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
68 * 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
69 * <li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
70 * 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
71 * "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
72 * due to:
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
73 * <ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
74 * <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
75 * remove the redundant one)</li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
76 * <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
77 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
78 * </li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
79 * </ul>
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
80 * </li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
81 * </ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
82 * </li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
83 * </ol>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
84 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
85 *
15498
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
86 * <p>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
87 * 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
88 * 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
89 * {@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
90 * {@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
91 * </p>
e30d7eaa290d [flow-sensitive] more metrics, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15483
diff changeset
92 *
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
93 * @see com.oracle.graal.phases.common.cfs.CheckCastReduction
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
94 * @see com.oracle.graal.phases.common.cfs.GuardingPiReduction
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
95 * @see com.oracle.graal.phases.common.cfs.FixedGuardReduction
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
96 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
97 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
98 public class FlowSensitiveReduction extends FixedGuardReduction {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
99
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
100 public FlowSensitiveReduction(StartNode start, State initialState, PhaseContext context) {
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
101 super(start, initialState, context);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
102 }
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 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
106 * This method performs two kinds of cleanup:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
107 * <ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
108 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
109 * marking as unreachable certain code-paths, as described in
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
110 * {@link com.oracle.graal.phases.common.cfs.BaseReduction.PostponedDeopt}</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
111 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
112 * 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
113 * </ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
114 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
115 *
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 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
118 * Methods like
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
119 * {@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
120 * 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
121 * {@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
122 * 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
123 * {@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
124 * before another invocation of
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
125 * {@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
126 * needs them. To recap,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
127 * {@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
128 * recursively visits the inputs of the its argument.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
129 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
130 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
131 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
132 * 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
133 * either:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
134 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
135 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
136 * {@link com.oracle.graal.nodes.calc.FloatingNode}, added by
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
137 * {@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
138 * ; or</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
139 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
140 * {@link com.oracle.graal.nodes.java.MethodCallTargetNode}, added by
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
141 * {@link #deverbosifyInputsCopyOnWrite(com.oracle.graal.nodes.java.MethodCallTargetNode)}</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
142 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
143 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
144 * 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
145 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
146 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
147 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
148 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
149 public void finished() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
150 if (!postponedDeopts.isEmpty()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
151 for (PostponedDeopt postponed : postponedDeopts) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
152 postponed.doRewrite(falseConstant);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
153 }
17094
86888df288ec fixed case of Optionality constants
Doug Simon <doug.simon@oracle.com>
parents: 17065
diff changeset
154 new DeadCodeEliminationPhase(Optional).apply(graph);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
155 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
156 for (MethodCallTargetNode mcn : graph.getNodes().filter(MethodCallTargetNode.class)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
157 if (mcn.isAlive() && FlowUtil.lacksUsages(mcn)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
158 mcn.safeDelete();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
159 }
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 for (Node n : graph.getNodes().filter(FloatingNode.class)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
162 GraphUtil.tryKillUnused(n);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
163 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
164 assert !isAliveWithoutUsages(trueConstant);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
165 assert !isAliveWithoutUsages(falseConstant);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
166 assert !isAliveWithoutUsages(nullConstant);
15588
9a63ccd66007 [single-pass-iter] additional documentation and assertions
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15585
diff changeset
167 super.finished();
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
168 }
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 private static boolean isAliveWithoutUsages(FloatingNode node) {
15444
be6685c6a831 [flow-sensitive] readability
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15442
diff changeset
171 return node.isAlive() && FlowUtil.lacksUsages(node);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
172 }
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 private void registerControlSplit(Node pred, BeginNode begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
175 assert pred != null && begin != null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
176 assert !state.isUnreachable;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
177
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
178 if (begin instanceof LoopExitNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
179 state.clear();
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
180 /*
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
181 * 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
182 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
183 }
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 if (pred instanceof IfNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
186 registerIfNode((IfNode) pred, begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
187 } else if (pred instanceof TypeSwitchNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
188 registerTypeSwitchNode((TypeSwitchNode) pred, begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
189 }
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 private void registerIfNode(IfNode ifNode, BeginNode begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
193 final boolean isThenBranch = (begin == ifNode.trueSuccessor());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
194
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
195 if (ifNode.condition() instanceof LogicConstantNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
196 final LogicConstantNode constCond = (LogicConstantNode) ifNode.condition();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
197 if (isThenBranch != constCond.getValue()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
198 state.impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
199 // let IfNode(constant) prune the dead-code control-path
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
200 }
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 if (state.isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
204 if (!(ifNode.condition() instanceof LogicConstantNode)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
205 // if condition constant, no need to add a Deopt node
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
206 postponedDeopts.addDeoptAfter(begin, UnreachedCode);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
207 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
208 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
209 state.addFact(isThenBranch, ifNode.condition(), begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
210 }
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 * 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
215 * 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
216 * 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
217 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
218 private void registerTypeSwitchNode(TypeSwitchNode typeSwitch, BeginNode begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
219 if (typeSwitch.value() instanceof LoadHubNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
220 LoadHubNode loadHub = (LoadHubNode) typeSwitch.value();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
221 ResolvedJavaType type = null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
222 for (int i = 0; i < typeSwitch.keyCount(); i++) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
223 if (typeSwitch.keySuccessor(i) == begin) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
224 if (type == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
225 type = typeSwitch.typeAt(i);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
226 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
227 type = FlowUtil.widen(type, typeSwitch.typeAt(i));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
228 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
229 }
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 if (type == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
232 // `begin` denotes the default case of the TypeSwitchNode
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
233 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
234 }
15445
bda013e0d8bb [flow-sensitive] bug fix, registerTypeSwitchNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15444
diff changeset
235 // 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
236 state.trackCC(loadHub.getValue(), type, begin);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
237 }
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 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
243 * 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
244 * "valid facts" only, without relying on any floating-guard-assumption).
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
245 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
246 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
247 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
248 * 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
249 * 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
250 * 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
251 * method.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
252 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
253 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
254 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
255 * <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
256 * performed for the parent node itself. </b>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
257 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
258 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
259 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
260 * 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
261 * hand,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
262 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
263 * <ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
264 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
265 * 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
266 * 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
267 * 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
268 * (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
269 * 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
270 * tree.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
271 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
272 * <li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
273 * 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
274 * 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
275 * (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
276 * should be invoked to reflect the updated inputs.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
277 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
278 * </ol>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
279 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
280 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
281 * @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
282 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
283 public boolean deverbosifyInputsInPlace(ValueNode parent) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
284 boolean changed = false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
285 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
286 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
287 ValueNode j = (ValueNode) reasoner.deverbosify(i);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
288 if (i != j) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
289 changed = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
290 FlowUtil.replaceInPlace(parent, i, j);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
291 }
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 if (changed) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
294 FlowUtil.inferStampAndCheck(parent);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
295 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
296 return changed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
297 }
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 * 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
301 * 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
302 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
303 * @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
304 * otherwise.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
305 *
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
306 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
307 private MethodCallTargetNode deverbosifyInputsCopyOnWrite(MethodCallTargetNode parent) {
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
308 final CallTargetNode.InvokeKind ik = parent.invokeKind();
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
309 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
310 boolean shouldDowncastReceiver = shouldTryDevirt;
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
311 MethodCallTargetNode changed = null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
312 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
313 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
314 if (shouldDowncastReceiver) {
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
315 shouldDowncastReceiver = false;
4f603d776ecc [flow-sensitive] too many type-refinements didn't improve performance
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15515
diff changeset
316 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
317 }
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
318 if (i != j) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
319 assert j != parent;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
320 if (changed == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
321 changed = (MethodCallTargetNode) parent.copyWithInputs();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
322 reasoner.added.add(changed);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
323 // copyWithInputs() implies graph.unique(changed)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
324 assert changed.isAlive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
325 assert FlowUtil.lacksUsages(changed);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
326 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
327 FlowUtil.replaceInPlace(changed, i, j);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
328 }
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 if (changed == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
331 return parent;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
332 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
333 FlowUtil.inferStampAndCheck(changed);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
334 /*
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
335 * 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
336 * 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
337 * substitutions we want for them). Not this case.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
338 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
339 return changed;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
340 }
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 * Precondition: This method assumes that either:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
344 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
345 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
346 * <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
347 * dataflow algorithm); or</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
348 * <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
349 * safe.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
350 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
351 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
352 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
353 * 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
354 * {@link com.oracle.graal.graph.spi.SimplifierTool SimplifierTool},
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
355 * {@link com.oracle.graal.phases.common.DeadCodeEliminationPhase DeadCodeEliminationPhase},
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
356 * 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
357 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
358 *
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 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
361 protected void node(FixedNode node) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
362
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
363 assert node.isAlive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
364
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 * 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
367 * 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
368 * rewriting anything while on an an unreachable path.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
369 *-------------------------------------------------------------------------------------
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 if (state.isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
372 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
373 }
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 * 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
377 * any associated guards.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
378 *-------------------------------------------------------------------------------------
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 if (node instanceof BeginNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
381 BeginNode begin = (BeginNode) node;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
382 Node pred = node.predecessor();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
383
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
384 if (pred != null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
385 registerControlSplit(pred, begin);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
386 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
387 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
388 }
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 * 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
392 *-------------------------------------------------------------------------------------
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 reasoner.updateState(state);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
395
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 * 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
398 * its inputs are reduced.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
399 *-------------------------------------------------------------------------------------
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 if (node instanceof AbstractEndNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
403 visitAbstractEndNode((AbstractEndNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
404 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
405 } else if (node instanceof Invoke) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
406 visitInvoke((Invoke) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
407 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
408 } else if (node instanceof CheckCastNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
409 // it's important not to call deverbosification for visitCheckCastNode()
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
410 visitCheckCastNode((CheckCastNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
411 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
412 } else if (node instanceof GuardingPiNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
413 visitGuardingPiNode((GuardingPiNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
414 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
415 } else if (node instanceof NullCheckNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
416 visitNullCheckNode((NullCheckNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
417 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
418 } else if (node instanceof FixedGuardNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
419 visitFixedGuardNode((FixedGuardNode) node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
420 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
421 } else if (node instanceof ConditionAnchorNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
422 // ConditionAnchorNode shouldn't occur during HighTier
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
423 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
424 }
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 * 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
428 * where the effort to reduce their inputs might pay off.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
429 *
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
430 * 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
431 * 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
432 * through simplification (and thus potentially have been reduced to a
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
433 * LogicConstantNode).
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
434 *-------------------------------------------------------------------------------------
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 boolean paysOffToReduce = false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
437 if (node instanceof ControlSplitNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
438 // desire to simplify control flow
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
439 paysOffToReduce = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
440 } else if (node instanceof ReturnNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
441 paysOffToReduce = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
442 } else if (node instanceof AccessFieldNode || node instanceof AccessArrayNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
443 // desire to remove null-checks
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
444 paysOffToReduce = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
445 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
446
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
447 // 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
448
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
449 // TODO UnsafeLoadNode takes a condition
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
450
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
451 if (paysOffToReduce) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
452 deverbosifyInputsInPlace(node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
453 }
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 * 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
457 * 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
458 *---------------------------------------------------------------------------------------
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 // 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
462 // 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
463
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 * In case the scrutinee:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
468 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
469 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
470 * <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
471 * <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
472 * <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
473 * anchor for state-tracking.</li>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
474 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
475 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
476 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
477 * Precondition: the input (ie, object) hasn't been deverbosified yet.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
478 * </p>
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
479 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
480 private void visitNullCheckNode(NullCheckNode ncn) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
481 ValueNode object = ncn.getObject();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
482 if (state.isNull(object)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
483 postponedDeopts.addDeoptBefore(ncn, NullCheckException);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
484 state.impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
485 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
486 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
487 if (state.isNonNull(object)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
488 /*
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
489 * Redundant NullCheckNode. Unlike GuardingPiNode or FixedGuardNode, NullCheckNode-s
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
490 * 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
491 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
492 assert FlowUtil.lacksUsages(ncn);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
493 graph.removeFixed(ncn);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
494 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
495 }
15442
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
496 /*
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
497 * 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
498 * 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
499 * 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
500 */
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
501 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
502 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
503 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
504 graph.replaceFixedWithFixed(ncn, nullCheck);
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
505
0f919919fd63 [flow-sensitive] NullCheckNode turned into equivalent FixedGuardNode
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15393
diff changeset
506 state.trackNN(object, nullCheck);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
507 }
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 * 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
511 * 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
512 * {@link EquationalReasoner#deverbosify(com.oracle.graal.graph.Node)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
513 * EquationalReasoner#deverbosify} those values.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
514 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
515 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
516 * Precondition: inputs haven't been deverbosified yet.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
517 * </p>
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
518 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
519 private void visitAbstractEndNode(AbstractEndNode endNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
520 MergeNode merge = endNode.merge();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
521 for (PhiNode phi : merge.phis()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
522 if (phi instanceof ValuePhiNode && phi.getKind() == Kind.Object) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
523 assert phi.verify();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
524 int index = merge.phiPredecessorIndex(endNode);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
525 ValueNode original = phi.valueAt(index);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
526 ValueNode reduced = (ValueNode) reasoner.deverbosify(original);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
527 if (reduced != original) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
528 phi.setValueAt(index, reduced);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
529 // `original` if unused will be removed in finished()
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
530 }
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 /**
15483
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
536 * <p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
537 * 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
538 * 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
539 * {@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
540 * 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
541 * </p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
542 *
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
543 * <p>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
544 * 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
545 * 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
546 * <ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
547 * <li>
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
548 * 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
549 * {@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
550 * 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
551 * <li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
552 * (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
553 * 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
554 * arguments).</li>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
555 *
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
556 * </ul>
01a8820c1228 [flow-sensitive] minor refactorings for readability, documentation
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15445
diff changeset
557 * </p>
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
558 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
559 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
560 * Precondition: inputs haven't been deverbosified yet.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
561 * </p>
15393
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
562 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
563 private void visitInvoke(Invoke invoke) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
564 if (invoke.asNode().stamp() instanceof IllegalStamp) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
565 return; // just to be safe
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
566 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
567 boolean isMethodCallTarget = invoke.callTarget() instanceof MethodCallTargetNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
568 if (!isMethodCallTarget) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
569 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
570 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
571 FlowUtil.replaceInPlace(invoke.asNode(), invoke.callTarget(), deverbosifyInputsCopyOnWrite((MethodCallTargetNode) invoke.callTarget()));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
572 MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
573 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
574 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
575 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
576 ValueNode receiver = callTarget.receiver();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
577 if (receiver == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
578 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
579 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
580 if (!FlowUtil.hasLegalObjectStamp(receiver)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
581 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
582 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
583 Witness w = state.typeInfo(receiver);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
584 ResolvedJavaType type;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
585 ResolvedJavaType stampType = StampTool.typeOrNull(receiver);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
586 if (w == null || w.cluelessAboutType()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
587 // 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
588 type = stampType;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
589 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
590 type = FlowUtil.tighten(w.type(), stampType);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
591 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
592 if (type == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
593 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
594 }
18191
839f97696479 Rename ResolvedJavaMethod.resolvedMethod() to resolveConcreteMethod() the reflect its actual behavior.
Josef Eisl <josef.eisl@jku.at>
parents: 17094
diff changeset
595 ResolvedJavaMethod method = type.resolveConcreteMethod(callTarget.targetMethod(), invoke.getContextType());
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
596 if (method == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
597 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
598 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
599 if (method.canBeStaticallyBound() || Modifier.isFinal(type.getModifiers())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
600 metricMethodResolved.increment();
16563
1e63cb55f61d Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16219
diff changeset
601 callTarget.setInvokeKind(CallTargetNode.InvokeKind.Special);
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
602 callTarget.setTargetMethod(method);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
603 }
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 }