Mercurial > hg > truffle
annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java @ 2941:cd4176d590e7
Towards lowering phase.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Thu, 09 Jun 2011 17:28:56 +0200 |
parents | |
children | 3891afa020da |
rev | line source |
---|---|
2941
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
1 /* |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
4 * |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
8 * |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
13 * accompanied this code). |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
14 * |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
18 * |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
21 * questions. |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
22 */ |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
23 package com.oracle.max.graal.compiler.phases; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
24 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
25 import java.util.*; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 import com.oracle.max.graal.compiler.*; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 import com.oracle.max.graal.compiler.ir.*; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
29 import com.oracle.max.graal.compiler.schedule.*; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
30 import com.oracle.max.graal.graph.*; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 public class LoweringPhase extends Phase { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 @Override |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 protected void run(Graph graph) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 NodeMap<Node> javaBlockNodes = graph.createNodeMap(); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
36 NodeBitMap nodeBitMap = graph.createNodeBitMap(); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
37 for (Node n : graph.getNodes()) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
38 if (n instanceof FixedNode) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
39 LoweringOp op = n.lookup(LoweringOp.class); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
40 if (op != null) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
41 Node javaBlockNode = getJavaBlockNode(javaBlockNodes, n, nodeBitMap); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
42 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
43 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
44 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
45 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
46 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
47 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
48 private Node getJavaBlockNode(NodeMap<Node> javaBlockNodes, Node n, NodeBitMap nodeBitMap) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
49 assert n instanceof FixedNode; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
50 if (javaBlockNodes.get(n) == null) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
51 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
52 Node truePred = null; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
53 int count = 0; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
54 for (Node pred : n.predecessors()) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
55 if (pred instanceof FixedNode) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
56 truePred = pred; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
57 count++; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
58 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
59 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
60 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
61 assert count > 0; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
62 if (count == 1) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 if (Schedule.trueSuccessorCount(truePred) == 1) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 javaBlockNodes.set(n, getJavaBlockNode(javaBlockNodes, truePred, nodeBitMap)); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
65 } else { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 // Single predecessor is a split => we are our own block node. |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
67 javaBlockNodes.set(n, n); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 } else { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
70 Node dominator = null; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 for (Node pred : n.predecessors()) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
72 if (pred instanceof FixedNode) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 dominator = getCommonDominator(dominator, pred, nodeBitMap); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
74 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
75 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
77 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
78 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 assert Schedule.truePredecessorCount(javaBlockNodes.get(n)) == 1; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 return javaBlockNodes.get(n); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
81 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
82 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 private Node getCommonDominator(Node a, Node b, NodeBitMap map) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 if (a == null) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
85 return b; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
86 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
87 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 if (b == null) { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 return a; |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
90 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
91 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
92 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
93 map.clearAll(); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
94 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
95 |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 public interface LoweringOp extends Op { |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 Node lower(Node node); |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
98 } |
cd4176d590e7
Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 } |