Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java @ 2874:d90bf514d647
Renamed packages.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 08:59:54 +0200 |
parents | graal/com.oracle.max.graal.compiler/src/com/sun/c1x/ir/Phi.java@0341b6424579 |
children | 81dab15b45e5 |
comparison
equal
deleted
inserted
replaced
2873:810e2d253e00 | 2874:d90bf514d647 |
---|---|
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.oracle.max.graal.compiler.ir; | |
24 | |
25 import com.oracle.max.graal.compiler.debug.*; | |
26 import com.oracle.max.graal.graph.*; | |
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 public final class Phi extends FixedNode { | |
34 | |
35 private static final int DEFAULT_MAX_VALUES = 2; | |
36 | |
37 private static final int INPUT_COUNT = 1; | |
38 private static final int INPUT_BLOCK = 0; | |
39 | |
40 private final int maxValues; | |
41 | |
42 private static final int SUCCESSOR_COUNT = 0; | |
43 | |
44 private int usedInputCount; | |
45 private boolean isDead; | |
46 | |
47 @Override | |
48 protected int inputCount() { | |
49 return super.inputCount() + INPUT_COUNT + maxValues; | |
50 } | |
51 | |
52 @Override | |
53 protected int successorCount() { | |
54 return super.successorCount() + SUCCESSOR_COUNT; | |
55 } | |
56 | |
57 /** | |
58 * The join block for this phi. | |
59 */ | |
60 public Merge block() { | |
61 return (Merge) inputs().get(super.inputCount() + INPUT_BLOCK); | |
62 } | |
63 | |
64 public Value setBlock(Value n) { | |
65 return (Merge) inputs().set(super.inputCount() + INPUT_BLOCK, n); | |
66 } | |
67 | |
68 /** | |
69 * Create a new Phi for the specified join block and local variable (or operand stack) slot. | |
70 * @param kind the type of the variable | |
71 * @param block the join point | |
72 * @param graph | |
73 */ | |
74 public Phi(CiKind kind, Merge block, Graph graph) { | |
75 this(kind, block, DEFAULT_MAX_VALUES, graph); | |
76 } | |
77 | |
78 public Phi(CiKind kind, Merge block, int maxValues, Graph graph) { | |
79 super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph); | |
80 this.maxValues = maxValues; | |
81 usedInputCount = 0; | |
82 setBlock(block); | |
83 } | |
84 | |
85 /** | |
86 * Get the instruction that produces the value associated with the i'th predecessor | |
87 * of the join block. | |
88 * @param i the index of the predecessor | |
89 * @return the instruction that produced the value in the i'th predecessor | |
90 */ | |
91 public Value valueAt(int i) { | |
92 return (Value) inputs().get(INPUT_COUNT + i); | |
93 } | |
94 | |
95 public Node setValueAt(int i, Node x) { | |
96 return inputs().set(INPUT_COUNT + i, x); | |
97 } | |
98 | |
99 /** | |
100 * Get the number of inputs to this phi (i.e. the number of predecessors to the join block). | |
101 * @return the number of inputs in this phi | |
102 */ | |
103 public int valueCount() { | |
104 return usedInputCount; | |
105 } | |
106 | |
107 @Override | |
108 public void accept(ValueVisitor v) { | |
109 v.visitPhi(this); | |
110 } | |
111 | |
112 /** | |
113 * Make this phi illegal if types were not merged correctly. | |
114 */ | |
115 public void makeDead() { | |
116 isDead = true; | |
117 } | |
118 | |
119 public boolean isDead() { | |
120 return isDead; | |
121 } | |
122 | |
123 @Override | |
124 public void print(LogStream out) { | |
125 out.print("phi function ("); | |
126 for (int i = 0; i < valueCount(); ++i) { | |
127 if (i != 0) { | |
128 out.print(' '); | |
129 } | |
130 out.print(valueAt(i)); | |
131 } | |
132 out.print(')'); | |
133 } | |
134 | |
135 @Override | |
136 public String shortName() { | |
137 StringBuilder str = new StringBuilder(); | |
138 for (int i = 0; i < valueCount(); ++i) { | |
139 if (i != 0) { | |
140 str.append(' '); | |
141 } | |
142 str.append(valueAt(i) == null ? "-" : valueAt(i).id()); | |
143 } | |
144 return "Phi: (" + str + ")"; | |
145 } | |
146 | |
147 public Phi addInput(Node y) { | |
148 assert !this.isDeleted() && !y.isDeleted(); | |
149 Phi phi = this; | |
150 if (usedInputCount == maxValues) { | |
151 phi = new Phi(kind, block(), maxValues * 2, graph()); | |
152 for (int i = 0; i < valueCount(); ++i) { | |
153 phi.addInput(valueAt(i)); | |
154 } | |
155 phi.addInput(y); | |
156 this.replace(phi); | |
157 } else { | |
158 setValueAt(usedInputCount++, y); | |
159 } | |
160 return phi; | |
161 } | |
162 | |
163 public void removeInput(int index) { | |
164 assert index < valueCount() : "index: " + index + ", valueCount: " + valueCount() + "@phi " + id(); | |
165 setValueAt(index, Node.Null); | |
166 for (int i = index + 1; i < valueCount(); ++i) { | |
167 setValueAt(i - 1, valueAt(i)); | |
168 } | |
169 usedInputCount--; | |
170 } | |
171 | |
172 @Override | |
173 public Node copy(Graph into) { | |
174 Phi x = new Phi(kind, null, maxValues, into); | |
175 x.usedInputCount = usedInputCount; | |
176 x.isDead = isDead; | |
177 return x; | |
178 } | |
179 } |