Mercurial > hg > truffle
annotate graal/GraalCompiler/src/com/sun/c1x/graph/DeadCodeElimination.java @ 2868:6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Tue, 07 Jun 2011 19:19:14 +0200 |
parents | 5c545fef2c81 |
children |
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 */ | |
23 package com.sun.c1x.graph; | |
24 | |
25 import com.oracle.graal.graph.*; | |
26 import com.sun.c1x.*; | |
27 import com.sun.c1x.gen.*; | |
28 import com.sun.c1x.ir.*; | |
29 | |
30 | |
31 public class DeadCodeElimination extends Phase { | |
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 public int deletedNodeCount; | |
38 | |
39 @Override | |
40 protected void run(Graph graph) { | |
41 this.graph = graph; | |
42 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
|
43 this.worklist = graph.createNodeWorklist(); |
2867 | 44 |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
45 worklist.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() { |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
68 for (Node current : worklist) { |
2867 | 69 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
|
70 worklist.add(successor); |
2867 | 71 } |
72 } | |
73 } | |
74 | |
75 private void disconnectCFGNodes() { | |
76 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
|
77 if (node != Node.Null && !worklist.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); | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
81 if (successor != Node.Null && worklist.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()) { | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
95 if (node != Node.Null && !worklist.isMarked(node) && isCFG(node)) { |
2867 | 96 node.delete(); |
97 deletedNodeCount++; | |
98 } | |
99 } | |
100 } | |
101 | |
102 private void iterateInputs() { | |
103 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
|
104 if (node != Node.Null && worklist.isMarked(node)) { |
2867 | 105 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
|
106 worklist.add(input); |
2867 | 107 } |
108 } | |
109 } | |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2867
diff
changeset
|
110 for (Node current : worklist) { |
2867 | 111 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
|
112 worklist.add(input); |
2867 | 113 } |
114 } | |
115 } | |
116 | |
117 private void disconnectNonCFGNodes() { | |
118 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
|
119 if (node != Node.Null && !worklist.isMarked(node) && !isCFG(node)) { |
2867 | 120 node.inputs().clearAll(); |
121 } | |
122 } | |
123 } | |
124 | |
125 private void deleteNonCFGNodes() { | |
126 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
|
127 if (node != Node.Null && !worklist.isMarked(node) && !isCFG(node)) { |
2867 | 128 node.delete(); |
129 deletedNodeCount++; | |
130 } | |
131 } | |
132 } | |
133 } |