comparison graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/cfg/Block.java @ 6529:2e96dc4eb8e2

renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
author Doug Simon <doug.simon@oracle.com>
date Mon, 08 Oct 2012 17:30:11 +0200
parents graal/com.oracle.graal.nodes/src/com/oracle/graal/lir/cfg/Block.java@c5afcc2ebd3d
children b5280041f59e
comparison
equal deleted inserted replaced
6528:436a24c36abe 6529:2e96dc4eb8e2
1 /*
2 * Copyright (c) 2009, 2012, 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.graal.nodes.cfg;
24
25 import java.util.*;
26
27 import com.oracle.graal.nodes.*;
28 import com.oracle.graal.nodes.java.*;
29
30 public class Block {
31
32 protected int id;
33
34 protected BeginNode beginNode;
35 protected FixedNode endNode;
36 protected Loop loop;
37 protected double probability;
38
39 protected List<Block> predecessors;
40 protected List<Block> successors;
41
42 protected Block dominator;
43 protected List<Block> dominated;
44 protected Block postdominator;
45
46 // Fields that still need to be worked on, try to remove them later.
47 public boolean align;
48 public int linearScanNumber;
49
50 protected Block() {
51 id = ControlFlowGraph.BLOCK_ID_INITIAL;
52 }
53
54 public int getId() {
55 return id;
56 }
57
58 public BeginNode getBeginNode() {
59 return beginNode;
60 }
61
62 public FixedNode getEndNode() {
63 return endNode;
64 }
65
66 public Loop getLoop() {
67 return loop;
68 }
69
70 public int getLoopDepth() {
71 return loop == null ? 0 : loop.depth;
72 }
73
74 public boolean isLoopHeader() {
75 return getBeginNode() instanceof LoopBeginNode;
76 }
77
78 public boolean isLoopEnd() {
79 return getEndNode() instanceof LoopEndNode;
80 }
81
82 public boolean isExceptionEntry() {
83 return getBeginNode().next() instanceof ExceptionObjectNode;
84 }
85
86 public List<Block> getPredecessors() {
87 return predecessors;
88 }
89
90 public List<Block> getSuccessors() {
91 return successors;
92 }
93
94 public Block getDominator() {
95 return dominator;
96 }
97
98 public Block getEarliestPostDominated() {
99 Block b = this;
100 while (true) {
101 Block dom = b.getDominator();
102 if (dom != null && dom.getPostdominator() == b) {
103 b = dom;
104 } else {
105 break;
106 }
107 }
108 return b;
109 }
110
111 public List<Block> getDominated() {
112 if (dominated == null) {
113 return Collections.emptyList();
114 }
115 return dominated;
116 }
117
118 public Block getPostdominator() {
119 return postdominator;
120 }
121
122 private class NodeIterator implements Iterator<FixedNode> {
123 private FixedNode cur;
124
125 public NodeIterator() {
126 cur = getBeginNode();
127 }
128
129 @Override
130 public boolean hasNext() {
131 return cur != null;
132 }
133
134 @Override
135 public FixedNode next() {
136 FixedNode result = cur;
137 if (cur == getEndNode()) {
138 cur = null;
139 } else {
140 cur = ((FixedWithNextNode) cur).next();
141 }
142 assert !(cur instanceof BeginNode);
143 return result;
144 }
145
146 @Override
147 public void remove() {
148 throw new UnsupportedOperationException();
149 }
150 }
151
152 public Iterable<FixedNode> getNodes() {
153 return new Iterable<FixedNode>() {
154 @Override
155 public Iterator<FixedNode> iterator() {
156 return new NodeIterator();
157 }
158
159 @Override
160 public String toString() {
161 StringBuilder str = new StringBuilder().append('[');
162 for (FixedNode node : this) {
163 str.append(node).append(", ");
164 }
165 if (str.length() > 1) {
166 str.setLength(str.length() - 2);
167 }
168 return str.append(']').toString();
169 }
170 };
171 }
172
173 @Override
174 public String toString() {
175 return "B" + id;
176 }
177
178
179 // to be inlined later on
180 public int numberOfPreds() {
181 return getPredecessors().size();
182 }
183
184 public int numberOfSux() {
185 return getSuccessors().size();
186 }
187
188 public Block predAt(int i) {
189 return getPredecessors().get(i);
190 }
191
192 public Block suxAt(int i) {
193 return getSuccessors().get(i);
194 }
195 // end to be inlined later on
196
197 public boolean dominates(Block block) {
198 return block.isDominatedBy(this);
199 }
200
201 public boolean isDominatedBy(Block block) {
202 if (block == this) {
203 return true;
204 }
205 if (dominator == null) {
206 return false;
207 }
208 return dominator.isDominatedBy(block);
209 }
210 }