Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/ir/Phi.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/Phi.java@9ec15d6914ca |
children | 4a36a0bd6d18 |
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 com.sun.c1x.debug.*; | |
26 import com.sun.c1x.value.*; | |
27 import com.sun.cri.ci.*; | |
28 | |
29 /** | |
30 * The {@code Phi} instruction represents the merging of dataflow | |
31 * in the instruction graph. It refers to a join block and a variable. | |
32 * | |
33 * @author Ben L. Titzer | |
34 */ | |
35 public final class Phi extends Value { | |
36 | |
37 private final BlockBegin block; | |
38 private final int index; | |
39 | |
40 /** | |
41 * Create a new Phi for the specified join block and local variable (or operand stack) slot. | |
42 * @param kind the type of the variable | |
43 * @param block the join point | |
44 * @param index the index into the stack (if < 0) or local variables | |
45 */ | |
46 public Phi(CiKind kind, BlockBegin block, int index) { | |
47 super(kind); | |
48 this.block = block; | |
49 this.index = index; | |
50 } | |
51 | |
52 /** | |
53 * Get the join block for this phi. | |
54 * @return the join block of this phi | |
55 */ | |
56 @Override | |
57 public BlockBegin block() { | |
58 return block; | |
59 } | |
60 | |
61 /** | |
62 * Check whether this phi corresponds to a local variable. | |
63 * @return {@code true} if this phi refers to a local variable | |
64 */ | |
65 public boolean isLocal() { | |
66 return index >= 0; | |
67 } | |
68 | |
69 /** | |
70 * Check whether this phi corresponds to a stack location. | |
71 * @return {@code true} if this phi refers to a stack location | |
72 */ | |
73 public boolean isOnStack() { | |
74 return index < 0; | |
75 } | |
76 | |
77 /** | |
78 * Get the local index of this phi. | |
79 * @return the local index | |
80 */ | |
81 public int localIndex() { | |
82 assert isLocal(); | |
83 return index; | |
84 } | |
85 | |
86 /** | |
87 * Get the stack index of this phi. | |
88 * @return the stack index of this phi | |
89 */ | |
90 public int stackIndex() { | |
91 assert isOnStack(); | |
92 return -(index + 1); | |
93 } | |
94 | |
95 /** | |
96 * Get the instruction that produces the value associated with the i'th predecessor | |
97 * of the join block. | |
98 * @param i the index of the predecessor | |
99 * @return the instruction that produced the value in the i'th predecessor | |
100 */ | |
101 public Value inputAt(int i) { | |
102 FrameState state; | |
103 if (block.isExceptionEntry()) { | |
104 state = block.exceptionHandlerStates().get(i); | |
105 } else { | |
106 state = block.predecessors().get(i).end().stateAfter(); | |
107 } | |
108 return inputIn(state); | |
109 } | |
110 | |
111 /** | |
112 * Gets the instruction that produces the value for this phi in the specified state. | |
113 * @param state the state to access | |
114 * @return the instruction producing the value | |
115 */ | |
116 public Value inputIn(FrameState state) { | |
117 if (isLocal()) { | |
118 return state.localAt(localIndex()); | |
119 } else { | |
120 return state.stackAt(stackIndex()); | |
121 } | |
122 } | |
123 | |
124 /** | |
125 * Get the number of inputs to this phi (i.e. the number of predecessors to the join block). | |
126 * @return the number of inputs in this phi | |
127 */ | |
128 public int inputCount() { | |
129 if (block.isExceptionEntry()) { | |
130 return block.exceptionHandlerStates().size(); | |
131 } else { | |
132 return block.predecessors().size(); | |
133 } | |
134 } | |
135 | |
136 @Override | |
137 public void accept(ValueVisitor v) { | |
138 v.visitPhi(this); | |
139 } | |
140 | |
141 /** | |
142 * Make this phi illegal if types were not merged correctly. | |
143 */ | |
144 public void makeDead() { | |
145 setFlag(Flag.PhiCannotSimplify); | |
146 setFlag(Flag.PhiDead); | |
147 } | |
148 | |
149 @Override | |
150 public void print(LogStream out) { | |
151 out.print("phi function"); | |
152 } | |
153 } |