annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/ReadEliminationPhase.java @ 6311:9b017f213df8

Remove bogus assertion
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 03 Sep 2012 15:20:39 +0200
parents d7f67808f970
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.compiler.phases;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
25 import java.util.*;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
26
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
27 import com.oracle.graal.debug.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
28 import com.oracle.graal.graph.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.nodes.*;
6307
d7f67808f970 Create ValueProxy nodes where necessary during ReadElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5847
diff changeset
30 import com.oracle.graal.nodes.PhiNode.PhiType;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.nodes.extended.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 public class ReadEliminationPhase extends Phase {
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
34 private Queue<PhiNode> newPhis;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 protected void run(StructuredGraph graph) {
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
38 newPhis = new LinkedList<>();
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 3733
diff changeset
39 for (FloatingReadNode n : graph.getNodes(FloatingReadNode.class)) {
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
40 if (isReadEliminable(n)) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
41 NodeMap<ValueNode> nodeMap = n.graph().createNodeMap();
5830
f28115ee6108 Do without the Top stamp for now, too little benefits
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5820
diff changeset
42 ValueNode value = getValue(n, n.lastLocationAccess(), nodeMap);
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
43 Debug.log("Eliminated memory read %1.1s and replaced with node %s", n, value);
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
44 graph.replaceFloating(n, value);
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
45 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
46 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 }
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
48
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
49 private boolean isReadEliminable(FloatingReadNode n) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
50 return isWrites(n, n.lastLocationAccess(), n.graph().createNodeBitMap());
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
51 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
52
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
53 private boolean isWrites(FloatingReadNode n, Node lastLocationAccess, NodeBitMap visited) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
54 if (lastLocationAccess == null) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
55 return false;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
56 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
57 if (visited.isMarked(lastLocationAccess)) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
58 return true; // dataflow loops must come from Phis assume them ok until proven wrong
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
59 }
5847
d6257bd5e7f2 Make ReadEliminationPhase Value proxy aware now that FLoatingRead keeps loop closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5830
diff changeset
60 if (lastLocationAccess instanceof ValueProxyNode) {
d6257bd5e7f2 Make ReadEliminationPhase Value proxy aware now that FLoatingRead keeps loop closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5830
diff changeset
61 return isWrites(n, ((ValueProxyNode) lastLocationAccess).value(), visited);
d6257bd5e7f2 Make ReadEliminationPhase Value proxy aware now that FLoatingRead keeps loop closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5830
diff changeset
62 }
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
63 if (lastLocationAccess instanceof WriteNode) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
64 WriteNode other = (WriteNode) lastLocationAccess;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
65 return other.object() == n.object() && other.location() == n.location();
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
66 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
67 if (lastLocationAccess instanceof PhiNode) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
68 visited.mark(lastLocationAccess);
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
69 for (ValueNode value : ((PhiNode) lastLocationAccess).values()) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
70 if (!isWrites(n, value, visited)) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
71 return false;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
72 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
73 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
74 return true;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
75 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
76 return false;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
77 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
78
5830
f28115ee6108 Do without the Top stamp for now, too little benefits
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5820
diff changeset
79 private ValueNode getValue(FloatingReadNode n, Node lastLocationAccess, NodeMap<ValueNode> nodeMap) {
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
80 ValueNode exisiting = nodeMap.get(lastLocationAccess);
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
81 if (exisiting != null) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
82 return exisiting;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
83 }
5847
d6257bd5e7f2 Make ReadEliminationPhase Value proxy aware now that FLoatingRead keeps loop closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5830
diff changeset
84 if (lastLocationAccess instanceof ValueProxyNode) {
6307
d7f67808f970 Create ValueProxy nodes where necessary during ReadElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5847
diff changeset
85 ValueProxyNode proxy = (ValueProxyNode) lastLocationAccess;
d7f67808f970 Create ValueProxy nodes where necessary during ReadElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5847
diff changeset
86 ValueNode value = getValue(n, proxy.value(), nodeMap);
d7f67808f970 Create ValueProxy nodes where necessary during ReadElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5847
diff changeset
87 return lastLocationAccess.graph().add(new ValueProxyNode(value, proxy.proxyPoint(), PhiType.Value));
5847
d6257bd5e7f2 Make ReadEliminationPhase Value proxy aware now that FLoatingRead keeps loop closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5830
diff changeset
88 }
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
89 if (lastLocationAccess instanceof WriteNode) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
90 return ((WriteNode) lastLocationAccess).value();
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
91 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
92 if (lastLocationAccess instanceof PhiNode) {
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
93 PhiNode phi = (PhiNode) lastLocationAccess;
5830
f28115ee6108 Do without the Top stamp for now, too little benefits
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5820
diff changeset
94 PhiNode newPhi = phi.graph().add(new PhiNode(n.kind(), phi.merge()));
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
95 nodeMap.set(lastLocationAccess, newPhi);
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
96 for (ValueNode value : phi.values()) {
5830
f28115ee6108 Do without the Top stamp for now, too little benefits
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5820
diff changeset
97 newPhi.addInput(getValue(n, value, nodeMap));
5820
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
98 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
99 newPhis.add(newPhi);
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
100 return newPhi;
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
101 }
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
102 throw GraalInternalError.shouldNotReachHere();
547587296886 Make ReadEliminationPhase support phis (eliminates read when the last access is a memeory phi of writes, recursively)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5387
diff changeset
103 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 }