comparison graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java @ 2509:16b9a8b5ad39

Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:50:44 +0200
parents graal/Compiler/src/com/sun/c1x/ir/BlockEnd.java@9ec15d6914ca
children e1ba5a93e997
comparison
equal deleted inserted replaced
2508:fea94949e0a2 2509:16b9a8b5ad39
1 /*
2 * Copyright (c) 2009, 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.ir;
24
25 import java.util.*;
26
27 import com.sun.c1x.util.*;
28 import com.sun.c1x.value.*;
29 import com.sun.cri.ci.*;
30
31 /**
32 * The {@code BlockEnd} instruction is a base class for all instructions that end a basic
33 * block, including branches, switches, throws, and goto's.
34 *
35 * @author Ben L. Titzer
36 */
37 public abstract class BlockEnd extends Instruction {
38
39 BlockBegin begin;
40 final List<BlockBegin> successors;
41 FrameState stateAfter;
42
43 /**
44 * Constructs a new block end with the specified value type.
45 * @param kind the type of the value produced by this instruction
46 * @param stateAfter the frame state at the end of this block
47 * @param isSafepoint {@code true} if this instruction is a safepoint instruction
48 * @param successors the list of successor blocks. If {@code null}, a new one will be created.
49 */
50 public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, List<BlockBegin> successors) {
51 super(kind);
52 this.successors = successors == null ? new ArrayList<BlockBegin>(2) : successors;
53 setStateAfter(stateAfter);
54 if (isSafepoint) {
55 setFlag(Value.Flag.IsSafepoint);
56 }
57 }
58
59 public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint) {
60 this(kind, stateAfter, isSafepoint, null);
61 }
62
63 /**
64 * Gets the state after the end of this block.
65 */
66 @Override
67 public FrameState stateAfter() {
68 return stateAfter;
69 }
70
71 public void setStateAfter(FrameState state) {
72 stateAfter = state;
73 }
74
75 /**
76 * Checks whether this instruction is a safepoint.
77 * @return {@code true} if this instruction is a safepoint
78 */
79 public boolean isSafepoint() {
80 return checkFlag(Value.Flag.IsSafepoint);
81 }
82
83 /**
84 * Gets the block begin associated with this block end.
85 * @return the beginning of this basic block
86 */
87 public BlockBegin begin() {
88 return begin;
89 }
90
91 /**
92 * Sets the basic block beginning for this block end. This should only
93 * be called from {@link BlockBegin}.
94 *
95 * @param block the beginning of this basic block
96 */
97 void setBegin(BlockBegin block) {
98 begin = block;
99 }
100
101 /**
102 * Substitutes a successor block in this block end's successor list. Note that
103 * this method updates all occurrences in the list.
104 * @param oldSucc the old successor to replace
105 * @param newSucc the new successor
106 */
107 public void substituteSuccessor(BlockBegin oldSucc, BlockBegin newSucc) {
108 assert newSucc != null;
109 Util.replaceAllInList(oldSucc, newSucc, successors);
110 }
111
112 /**
113 * Gets the successor corresponding to the default (fall through) case.
114 * @return the default successor
115 */
116 public BlockBegin defaultSuccessor() {
117 return successors.get(successors.size() - 1);
118 }
119
120 /**
121 * Searches for the specified successor and returns its index into the
122 * successor list if found.
123 * @param b the block to search for in the successor list
124 * @return the index of the block in the list if found; <code>-1</code> otherwise
125 */
126 public int successorIndex(BlockBegin b) {
127 final int max = successors.size();
128 for (int i = 0; i < max; i++) {
129 if (successors.get(i) == b) {
130 return i;
131 }
132 }
133 return -1;
134 }
135
136 /**
137 * Gets this block end's list of successors.
138 * @return the successor list
139 */
140 public List<BlockBegin> successors() {
141 return successors;
142 }
143
144 /**
145 * Gets the successor at a specified index.
146 * @param index the index of the successor
147 * @return the successor
148 */
149 public BlockBegin suxAt(int index) {
150 return successors.get(index);
151 }
152 }