comparison 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
comparison
equal deleted inserted replaced
2940:bf15ed11c2bc 2941:cd4176d590e7
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.oracle.max.graal.compiler.phases;
24
25 import java.util.*;
26
27 import com.oracle.max.graal.compiler.*;
28 import com.oracle.max.graal.compiler.ir.*;
29 import com.oracle.max.graal.compiler.schedule.*;
30 import com.oracle.max.graal.graph.*;
31
32 public class LoweringPhase extends Phase {
33 @Override
34 protected void run(Graph graph) {
35 NodeMap<Node> javaBlockNodes = graph.createNodeMap();
36 NodeBitMap nodeBitMap = graph.createNodeBitMap();
37 for (Node n : graph.getNodes()) {
38 if (n instanceof FixedNode) {
39 LoweringOp op = n.lookup(LoweringOp.class);
40 if (op != null) {
41 Node javaBlockNode = getJavaBlockNode(javaBlockNodes, n, nodeBitMap);
42 }
43 }
44
45 }
46 }
47
48 private Node getJavaBlockNode(NodeMap<Node> javaBlockNodes, Node n, NodeBitMap nodeBitMap) {
49 assert n instanceof FixedNode;
50 if (javaBlockNodes.get(n) == null) {
51
52 Node truePred = null;
53 int count = 0;
54 for (Node pred : n.predecessors()) {
55 if (pred instanceof FixedNode) {
56 truePred = pred;
57 count++;
58 }
59 }
60
61 assert count > 0;
62 if (count == 1) {
63 if (Schedule.trueSuccessorCount(truePred) == 1) {
64 javaBlockNodes.set(n, getJavaBlockNode(javaBlockNodes, truePred, nodeBitMap));
65 } else {
66 // Single predecessor is a split => we are our own block node.
67 javaBlockNodes.set(n, n);
68 }
69 } else {
70 Node dominator = null;
71 for (Node pred : n.predecessors()) {
72 if (pred instanceof FixedNode) {
73 dominator = getCommonDominator(dominator, pred, nodeBitMap);
74 }
75 }
76 }
77 }
78
79 assert Schedule.truePredecessorCount(javaBlockNodes.get(n)) == 1;
80 return javaBlockNodes.get(n);
81 }
82
83 private Node getCommonDominator(Node a, Node b, NodeBitMap map) {
84 if (a == null) {
85 return b;
86 }
87
88 if (b == null) {
89 return a;
90 }
91
92
93 map.clearAll();
94 }
95
96 public interface LoweringOp extends Op {
97 Node lower(Node node);
98 }
99 }