Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.lir/src/com/oracle/max/graal/lir/cfg/Block.java @ 4525:681e969888a7
Separate LIR and new register allocator into separate projects
author | Christian Wimmer <Christian.Wimmer@Oracle.com> |
---|---|
date | Wed, 08 Feb 2012 19:25:29 -0800 |
parents | graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/cfg/Block.java@cf13124efdd9 |
children | f55914bc1d67 |
comparison
equal
deleted
inserted
replaced
4524:dcc8f5c6f394 | 4525:681e969888a7 |
---|---|
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.max.graal.lir.cfg; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.oracle.max.graal.graph.*; | |
28 import com.oracle.max.graal.lir.*; | |
29 import com.oracle.max.graal.nodes.*; | |
30 import com.oracle.max.graal.nodes.java.*; | |
31 | |
32 public class Block { | |
33 protected int id; | |
34 | |
35 protected BeginNode beginNode; | |
36 protected Node endNode; | |
37 protected Loop loop; | |
38 protected double probability; | |
39 | |
40 protected List<Block> predecessors; | |
41 protected List<Block> successors; | |
42 | |
43 protected Block dominator; | |
44 protected List<Block> dominated; | |
45 protected Block postdominator; | |
46 | |
47 // Fields that still need to be worked on, try to remove them later. | |
48 public List<LIRInstruction> lir; | |
49 public boolean align; | |
50 public int linearScanNumber; | |
51 | |
52 public Block() { | |
53 id = ControlFlowGraph.BLOCK_ID_INITIAL; | |
54 } | |
55 | |
56 public int getId() { | |
57 assert id >= 0; | |
58 return id; | |
59 } | |
60 | |
61 public BeginNode getBeginNode() { | |
62 return beginNode; | |
63 } | |
64 | |
65 public Node getEndNode() { | |
66 return endNode; | |
67 } | |
68 | |
69 public Loop getLoop() { | |
70 return loop; | |
71 } | |
72 | |
73 public int getLoopDepth() { | |
74 return loop == null ? 0 : loop.depth; | |
75 } | |
76 | |
77 public boolean isLoopHeader() { | |
78 return getBeginNode() instanceof LoopBeginNode; | |
79 } | |
80 | |
81 public boolean isLoopEnd() { | |
82 return getEndNode() instanceof LoopEndNode; | |
83 } | |
84 | |
85 public boolean isExceptionEntry() { | |
86 return getBeginNode().next() instanceof ExceptionObjectNode; | |
87 } | |
88 | |
89 public List<Block> getPredecessors() { | |
90 return predecessors; | |
91 } | |
92 | |
93 public List<Block> getSuccessors() { | |
94 return successors; | |
95 } | |
96 | |
97 public Block getDominator() { | |
98 return dominator; | |
99 } | |
100 | |
101 public List<Block> getDominated() { | |
102 if (dominated == null) { | |
103 return Collections.emptyList(); | |
104 } | |
105 return dominated; | |
106 } | |
107 | |
108 public Block getPostdominator() { | |
109 return postdominator; | |
110 } | |
111 | |
112 private class NodeIterator implements Iterator<Node> { | |
113 private Node cur; | |
114 | |
115 public NodeIterator() { | |
116 cur = getBeginNode(); | |
117 } | |
118 | |
119 @Override | |
120 public boolean hasNext() { | |
121 return cur != null; | |
122 } | |
123 | |
124 @Override | |
125 public Node next() { | |
126 Node result = cur; | |
127 if (cur == getEndNode()) { | |
128 cur = null; | |
129 } else { | |
130 cur = ((FixedWithNextNode) cur).next(); | |
131 } | |
132 assert !(cur instanceof BeginNode); | |
133 return result; | |
134 } | |
135 | |
136 @Override | |
137 public void remove() { | |
138 throw new UnsupportedOperationException(); | |
139 } | |
140 } | |
141 | |
142 public Iterable<Node> getNodes() { | |
143 return new Iterable<Node>() { | |
144 @Override | |
145 public Iterator<Node> iterator() { | |
146 return new NodeIterator(); | |
147 } | |
148 }; | |
149 } | |
150 | |
151 public int getFirstLirInstructionId() { | |
152 int result = lir.get(0).id(); | |
153 assert result >= 0; | |
154 return result; | |
155 } | |
156 | |
157 public int getLastLirInstructionId() { | |
158 int result = lir.get(lir.size() - 1).id(); | |
159 assert result >= 0; | |
160 return result; | |
161 } | |
162 | |
163 @Override | |
164 public String toString() { | |
165 return "B" + id; | |
166 } | |
167 | |
168 | |
169 // to be inlined later on | |
170 public int numberOfPreds() { | |
171 return getPredecessors().size(); | |
172 } | |
173 | |
174 public int numberOfSux() { | |
175 return getSuccessors().size(); | |
176 } | |
177 | |
178 public Block predAt(int i) { | |
179 return getPredecessors().get(i); | |
180 } | |
181 | |
182 public Block suxAt(int i) { | |
183 return getSuccessors().get(i); | |
184 } | |
185 // end to be inlined later on | |
186 } |