Mercurial > hg > truffle
annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java @ 2910:7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 08 Jun 2011 14:30:27 +0200 |
parents | 7f584bf507ed |
children | 241798fa9d34 |
rev | line source |
---|---|
2867 | 1 /* |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
2879
7f584bf507ed
Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2874
diff
changeset
|
23 package com.oracle.max.graal.compiler.phases; |
2867 | 24 |
2874
d90bf514d647
Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2872
diff
changeset
|
25 import com.oracle.max.graal.compiler.*; |
d90bf514d647
Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2872
diff
changeset
|
26 import com.oracle.max.graal.compiler.gen.*; |
d90bf514d647
Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2872
diff
changeset
|
27 import com.oracle.max.graal.compiler.ir.*; |
d90bf514d647
Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2872
diff
changeset
|
28 import com.oracle.max.graal.graph.*; |
2867 | 29 |
30 | |
2879
7f584bf507ed
Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2874
diff
changeset
|
31 public class DeadCodeEliminationPhase extends Phase { |
2867 | 32 |
33 private NodeBitMap alive; | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
34 private NodeFlood flood; |
2867 | 35 private Graph graph; |
36 | |
37 public int deletedNodeCount; | |
38 | |
39 @Override | |
40 protected void run(Graph graph) { | |
41 this.graph = graph; | |
42 this.alive = graph.createNodeBitMap(); | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
43 this.flood = graph.createNodeFlood(); |
2867 | 44 |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
45 flood.add(graph.start()); |
2867 | 46 |
47 iterateSuccessors(); | |
48 disconnectCFGNodes(); | |
49 | |
50 iterateInputs(); | |
51 disconnectNonCFGNodes(); | |
52 | |
53 deleteCFGNodes(); | |
54 deleteNonCFGNodes(); | |
55 | |
56 new PhiSimplifier(graph); | |
57 | |
58 if (C1XOptions.TraceDeadCodeElimination) { | |
59 System.out.printf("dead code elimination: deleted %d nodes\n", deletedNodeCount); | |
60 } | |
61 } | |
62 | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
63 private static boolean isCFG(Node n) { |
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
64 return n != null && ((n instanceof Instruction) || n == n.graph().start()); |
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
65 } |
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
66 |
2867 | 67 private void iterateSuccessors() { |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
68 for (Node current : flood) { |
2867 | 69 for (Node successor : current.successors()) { |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
70 flood.add(successor); |
2867 | 71 } |
72 } | |
73 } | |
74 | |
75 private void disconnectCFGNodes() { | |
76 for (Node node : graph.getNodes()) { | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
77 if (node != Node.Null && !flood.isMarked(node) && isCFG(node)) { |
2867 | 78 // iterate backwards so that the predecessor indexes in removePhiPredecessor are correct |
79 for (int i = node.successors().size() - 1; i >= 0; i--) { | |
80 Node successor = node.successors().get(i); | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
81 if (successor != Node.Null && flood.isMarked(successor)) { |
2867 | 82 if (successor instanceof Merge) { |
83 ((Merge) successor).removePhiPredecessor(node); | |
84 } | |
85 } | |
86 } | |
87 node.successors().clearAll(); | |
88 node.inputs().clearAll(); | |
89 } | |
90 } | |
91 } | |
92 | |
93 private void deleteCFGNodes() { | |
94 for (Node node : graph.getNodes()) { | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
95 if (node != Node.Null && !flood.isMarked(node) && isCFG(node)) { |
2867 | 96 node.delete(); |
97 deletedNodeCount++; | |
98 } | |
99 } | |
100 } | |
101 | |
102 private void iterateInputs() { | |
103 for (Node node : graph.getNodes()) { | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
104 if (node != Node.Null && flood.isMarked(node)) { |
2867 | 105 for (Node input : node.inputs()) { |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
106 flood.add(input); |
2867 | 107 } |
108 } | |
109 } | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
110 for (Node current : flood) { |
2867 | 111 for (Node input : current.inputs()) { |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
112 flood.add(input); |
2867 | 113 } |
114 } | |
115 } | |
116 | |
117 private void disconnectNonCFGNodes() { | |
118 for (Node node : graph.getNodes()) { | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
119 if (node != Node.Null && !flood.isMarked(node) && !isCFG(node)) { |
2867 | 120 node.inputs().clearAll(); |
121 } | |
122 } | |
123 } | |
124 | |
125 private void deleteNonCFGNodes() { | |
126 for (Node node : graph.getNodes()) { | |
2910
7eec76f3e39e
adjust monitor index while inlining, renamed NodeWorklist to NodeFlood
Lukas Stadler <lukas.stadler@jku.at>
parents:
2879
diff
changeset
|
127 if (node != Node.Null && !flood.isMarked(node) && !isCFG(node)) { |
2867 | 128 node.delete(); |
129 deletedNodeCount++; | |
130 } | |
131 } | |
132 } | |
133 } |