annotate graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/InferStamps.java @ 14978:e302df8bf51c

separate subclasses for value and guard phis and proxies
author Lukas Stadler <lukas.stadler@oracle.com>
date Fri, 04 Apr 2014 18:32:32 +0200
parents f2b300c6e621
children 5e4ae8709830
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
4 *
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
8 *
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
14 *
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
18 *
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
21 * questions.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
22 */
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.phases.graph;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
25 import com.oracle.graal.graph.*;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
26 import com.oracle.graal.nodes.*;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.nodes.spi.*;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.nodes.type.*;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
30 public class InferStamps {
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
31
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
32 /**
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
33 * Infer the stamps for all Object nodes in the graph, to make the stamps as precise as
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
34 * possible. For example, this propagates the word-type through phi functions. To handle phi
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
35 * functions at loop headers, the stamp inference is called until a fix point is reached.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
36 * <p>
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
37 * This method can be used when it is needed that stamps are inferred before the first run of
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
38 * the canonicalizer. For example, word type rewriting must run before the first run of the
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
39 * canonicalizer because many nodes are not prepared to see the word type during
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
40 * canonicalization.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
41 */
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
42 public static void inferStamps(StructuredGraph graph) {
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
43 /*
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
44 * We want to make the stamps more precise. For cyclic phi functions, this means we have to
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
45 * ignore the initial stamp because the imprecise stamp would always propagate around the
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
46 * cycle. We therefore set the stamp to an illegal stamp, which is automatically ignored
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
47 * when the phi function performs the "meet" operator on its input stamps.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
48 */
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
49 for (Node n : graph.getNodes()) {
14978
e302df8bf51c separate subclasses for value and guard phis and proxies
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13999
diff changeset
50 if (n instanceof ValuePhiNode || n instanceof ValueAndStampProxy) {
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
51 ValueNode node = (ValueNode) n;
13999
f2b300c6e621 Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents: 13941
diff changeset
52 if (ObjectStamp.isObject(node.stamp())) {
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
53 assert !(node.stamp() instanceof IllegalStamp) : "We assume all Phi and Proxy stamps are legal before the analysis";
13999
f2b300c6e621 Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents: 13941
diff changeset
54 node.setStamp(node.stamp().illegal());
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
55 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
56 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
57 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
58
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
59 boolean stampChanged;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
60 do {
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
61 stampChanged = false;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
62 /*
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
63 * We could use GraphOrder.forwardGraph() to process the nodes in a defined order and
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
64 * propagate long def-use chains in fewer iterations. However, measurements showed that
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
65 * we have few iterations anyway, and the overhead of computing the order is much higher
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
66 * than the benefit.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
67 */
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
68 for (Node n : graph.getNodes()) {
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
69 if (n instanceof ValueNode) {
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
70 ValueNode node = (ValueNode) n;
13999
f2b300c6e621 Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents: 13941
diff changeset
71 if (ObjectStamp.isObject(node.stamp())) {
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
72 stampChanged |= node.inferStamp();
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
73 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
74 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
75 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
76 } while (stampChanged);
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
77
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
78 /*
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
79 * Check that all the illegal stamps we introduced above are correctly replaced with real
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
80 * stamps again.
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
81 */
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
82 assert checkNoIllegalStamp(graph);
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
83 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
84
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
85 private static boolean checkNoIllegalStamp(StructuredGraph graph) {
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
86 for (Node n : graph.getNodes()) {
14978
e302df8bf51c separate subclasses for value and guard phis and proxies
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13999
diff changeset
87 if (n instanceof ValuePhiNode || n instanceof ValueAndStampProxy) {
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
88 ValueNode node = (ValueNode) n;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
89 assert !(node.stamp() instanceof IllegalStamp) : "Stamp is illegal after analysis. This is not necessarily an error, but a condition that we want to investigate (and then maybe relax or remove the assertion).";
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
90 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
91 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
92 return true;
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
93 }
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
94
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
95 }