Mercurial > hg > truffle
annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java @ 2886:c3b8968233fa
Removed counting of deleted nodes for each phase.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 12:10:57 +0200 |
parents | 7f584bf507ed |
children | 224412c24426 |
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; | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
34 private NodeWorklist worklist; |
2867 | 35 private Graph graph; |
36 | |
37 @Override | |
38 protected void run(Graph graph) { | |
39 this.graph = graph; | |
40 this.alive = graph.createNodeBitMap(); | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
41 this.worklist = graph.createNodeWorklist(); |
2867 | 42 |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
43 worklist.add(graph.start()); |
2867 | 44 |
45 iterateSuccessors(); | |
46 disconnectCFGNodes(); | |
47 | |
48 iterateInputs(); | |
49 disconnectNonCFGNodes(); | |
50 | |
51 deleteCFGNodes(); | |
52 deleteNonCFGNodes(); | |
53 | |
54 new PhiSimplifier(graph); | |
55 | |
56 if (C1XOptions.TraceDeadCodeElimination) { | |
2886
c3b8968233fa
Removed counting of deleted nodes for each phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2879
diff
changeset
|
57 System.out.printf("dead code elimination finished\n"); |
2867 | 58 } |
59 } | |
60 | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
61 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
|
62 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
|
63 } |
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
64 |
2867 | 65 private void iterateSuccessors() { |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
66 for (Node current : worklist) { |
2867 | 67 for (Node successor : current.successors()) { |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
68 worklist.add(successor); |
2867 | 69 } |
70 } | |
71 } | |
72 | |
73 private void disconnectCFGNodes() { | |
74 for (Node node : graph.getNodes()) { | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
75 if (node != Node.Null && !worklist.isMarked(node) && isCFG(node)) { |
2867 | 76 // iterate backwards so that the predecessor indexes in removePhiPredecessor are correct |
77 for (int i = node.successors().size() - 1; i >= 0; i--) { | |
78 Node successor = node.successors().get(i); | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
79 if (successor != Node.Null && worklist.isMarked(successor)) { |
2867 | 80 if (successor instanceof Merge) { |
81 ((Merge) successor).removePhiPredecessor(node); | |
82 } | |
83 } | |
84 } | |
85 node.successors().clearAll(); | |
86 node.inputs().clearAll(); | |
87 } | |
88 } | |
89 } | |
90 | |
91 private void deleteCFGNodes() { | |
92 for (Node node : graph.getNodes()) { | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
93 if (node != Node.Null && !worklist.isMarked(node) && isCFG(node)) { |
2867 | 94 node.delete(); |
95 } | |
96 } | |
97 } | |
98 | |
99 private void iterateInputs() { | |
100 for (Node node : graph.getNodes()) { | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
101 if (node != Node.Null && worklist.isMarked(node)) { |
2867 | 102 for (Node input : node.inputs()) { |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
103 worklist.add(input); |
2867 | 104 } |
105 } | |
106 } | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
107 for (Node current : worklist) { |
2867 | 108 for (Node input : current.inputs()) { |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
109 worklist.add(input); |
2867 | 110 } |
111 } | |
112 } | |
113 | |
114 private void disconnectNonCFGNodes() { | |
115 for (Node node : graph.getNodes()) { | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
116 if (node != Node.Null && !worklist.isMarked(node) && !isCFG(node)) { |
2867 | 117 node.inputs().clearAll(); |
118 } | |
119 } | |
120 } | |
121 | |
122 private void deleteNonCFGNodes() { | |
123 for (Node node : graph.getNodes()) { | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
124 if (node != Node.Null && !worklist.isMarked(node) && !isCFG(node)) { |
2867 | 125 node.delete(); |
126 } | |
127 } | |
128 } | |
129 } |