Mercurial > hg > truffle
comparison graal/com.oracle.max.cri/src/com/sun/cri/xir/XirTemplate.java @ 3733:e233f5660da4
Added Java files from Maxine project.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 19:59:18 +0100 |
parents | |
children | bc8527f3071c |
comparison
equal
deleted
inserted
replaced
3732:3e2e8b8abdaf | 3733:e233f5660da4 |
---|---|
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.cri.xir; | |
24 | |
25 import java.io.*; | |
26 import java.util.*; | |
27 | |
28 import com.sun.cri.xir.CiXirAssembler.*; | |
29 | |
30 /** | |
31 * Represents a completed template of XIR code that has been first assembled by | |
32 * the runtime, and then verified and preprocessed by the compiler. An {@code XirTemplate} | |
33 * instance is immutable. | |
34 */ | |
35 public class XirTemplate { | |
36 | |
37 /** | |
38 * Flags that indicate key features of the template for quick checking. | |
39 */ | |
40 public enum GlobalFlags { | |
41 /** | |
42 * Contains a call to a {@link GlobalFlags#GLOBAL_STUB} template. | |
43 */ | |
44 HAS_STUB_CALL, | |
45 | |
46 /** | |
47 * Contains a call to the runtime. | |
48 */ | |
49 HAS_RUNTIME_CALL, | |
50 | |
51 /** | |
52 * Not simply a linear sequence of instructions, contains control transfers. | |
53 */ | |
54 HAS_CONTROL_FLOW, | |
55 | |
56 /** | |
57 * Is a shared instruction sequence for use by other templates. | |
58 */ | |
59 GLOBAL_STUB; | |
60 | |
61 public final int mask = 1 << ordinal(); | |
62 } | |
63 | |
64 /** | |
65 * Name of the template. | |
66 */ | |
67 public final String name; | |
68 | |
69 public final XirOperand resultOperand; | |
70 | |
71 /** | |
72 * The sequence of instructions for the fast (inline) path. | |
73 */ | |
74 public final CiXirAssembler.XirInstruction[] fastPath; | |
75 | |
76 /** | |
77 * The sequence of instructions for the slow (out of line) path. | |
78 */ | |
79 public final CiXirAssembler.XirInstruction[] slowPath; | |
80 | |
81 /** | |
82 * Labels used in control transfers. | |
83 */ | |
84 public final XirLabel[] labels; | |
85 | |
86 /** | |
87 * Parameters to the template. | |
88 */ | |
89 public final XirParameter[] parameters; | |
90 | |
91 /** | |
92 * An array of same length as {@link #parameters} where {@code parameterDestroyed[i]} is {@code true} | |
93 * iff {@code parameters[i]} is the {@link XirInstruction#result result} of any {@link XirInstruction} in either | |
94 * {@link #fastPath} or {@link #slowPath}. | |
95 */ | |
96 public final boolean[] parameterDestroyed; | |
97 | |
98 /** | |
99 * Temporary variables used by the template. | |
100 */ | |
101 public final XirTemp[] temps; | |
102 | |
103 /** | |
104 * Constants used in the template. | |
105 */ | |
106 public final XirConstant[] constants; | |
107 | |
108 /** | |
109 * The total number of variables. (relation to temps/parameters???) | |
110 */ | |
111 public final int variableCount; | |
112 | |
113 public final boolean allocateResultOperand; | |
114 | |
115 public final XirTemplate[] calleeTemplates; | |
116 | |
117 public final XirMark[] marks; | |
118 | |
119 public final int outgoingStackSize; | |
120 | |
121 public final XirOperand[] inputOperands; | |
122 public final XirOperand[] inputTempOperands; | |
123 public final XirOperand[] tempOperands; | |
124 | |
125 | |
126 /** | |
127 * The {@link GlobalFlags} associated with the template. | |
128 */ | |
129 public final int flags; | |
130 | |
131 public XirTemplate(String name, | |
132 int variableCount, | |
133 boolean allocateResultOperand, | |
134 XirOperand resultOperand, | |
135 CiXirAssembler.XirInstruction[] fastPath, | |
136 CiXirAssembler.XirInstruction[] slowPath, | |
137 XirLabel[] labels, | |
138 XirParameter[] parameters, | |
139 XirTemp[] temps, | |
140 XirConstant[] constantValues, | |
141 int flags, | |
142 XirTemplate[] calleeTemplates, | |
143 XirMark[] marks, | |
144 int outgoingStackSize) { | |
145 this.name = name; | |
146 this.variableCount = variableCount; | |
147 this.resultOperand = resultOperand; | |
148 this.fastPath = fastPath; | |
149 this.slowPath = slowPath; | |
150 this.labels = labels; | |
151 this.parameters = parameters; | |
152 this.flags = flags; | |
153 this.temps = temps; | |
154 this.allocateResultOperand = allocateResultOperand; | |
155 this.constants = constantValues; | |
156 this.calleeTemplates = calleeTemplates; | |
157 this.marks = marks; | |
158 this.outgoingStackSize = outgoingStackSize; | |
159 | |
160 assert fastPath != null; | |
161 assert labels != null; | |
162 assert parameters != null; | |
163 | |
164 List<XirOperand> inputOperands = new ArrayList<XirOperand>(4); | |
165 List<XirOperand> inputTempOperands = new ArrayList<XirOperand>(4); | |
166 List<XirOperand> tempOperands = new ArrayList<XirOperand>(4); | |
167 | |
168 parameterDestroyed = new boolean[parameters.length]; | |
169 for (int i = 0; i < parameters.length; i++) { | |
170 for (XirInstruction ins : fastPath) { | |
171 if (ins.result == parameters[i]) { | |
172 parameterDestroyed[i] = true; | |
173 break; | |
174 } | |
175 } | |
176 | |
177 if (slowPath != null && !parameterDestroyed[i]) { | |
178 for (XirInstruction ins : slowPath) { | |
179 if (ins.result == parameters[i]) { | |
180 parameterDestroyed[i] = true; | |
181 } | |
182 } | |
183 } | |
184 | |
185 if (parameterDestroyed[i]) { | |
186 inputTempOperands.add(parameters[i]); | |
187 } else { | |
188 inputOperands.add(parameters[i]); | |
189 } | |
190 } | |
191 | |
192 for (XirTemp temp : temps) { | |
193 if (temp.reserve) { | |
194 tempOperands.add(temp); | |
195 } | |
196 } | |
197 | |
198 this.inputOperands = inputOperands.toArray(new XirOperand[inputOperands.size()]); | |
199 this.inputTempOperands = inputTempOperands.toArray(new XirOperand[inputTempOperands.size()]); | |
200 this.tempOperands = tempOperands.toArray(new XirOperand[tempOperands.size()]); | |
201 } | |
202 | |
203 /** | |
204 * Convenience getter that returns the value at a given index in the {@link #parameterDestroyed} array. | |
205 * @param index | |
206 * @return the value at {@code parameterDestroyed[index]} | |
207 */ | |
208 public boolean isParameterDestroyed(int index) { | |
209 return parameterDestroyed[index]; | |
210 } | |
211 | |
212 @Override | |
213 public String toString() { | |
214 return name; | |
215 } | |
216 | |
217 public void print(PrintStream p) { | |
218 final String indent = " "; | |
219 | |
220 p.println(); | |
221 p.println("Template " + name); | |
222 | |
223 p.print("Param:"); | |
224 for (XirParameter param : parameters) { | |
225 p.print(" " + param.detailedToString()); | |
226 } | |
227 p.println(); | |
228 | |
229 if (temps.length > 0) { | |
230 p.print("Temps:"); | |
231 for (XirTemp temp : temps) { | |
232 p.print(" " + temp.detailedToString()); | |
233 } | |
234 p.println(); | |
235 } | |
236 | |
237 if (constants.length > 0) { | |
238 p.print("Constants:"); | |
239 for (XirConstant c : constants) { | |
240 p.print(" " + c.detailedToString()); | |
241 } | |
242 p.println(); | |
243 } | |
244 | |
245 if (flags != 0) { | |
246 p.print("Flags:"); | |
247 for (XirTemplate.GlobalFlags flag : XirTemplate.GlobalFlags.values()) { | |
248 if ((this.flags & flag.mask) != 0) { | |
249 p.print(" " + flag.name()); | |
250 } | |
251 } | |
252 p.println(); | |
253 } | |
254 | |
255 p.println("Fast path:"); | |
256 for (XirInstruction i : fastPath) { | |
257 p.println(indent + i.toString()); | |
258 } | |
259 | |
260 if (slowPath != null) { | |
261 p.println("Slow path:"); | |
262 for (XirInstruction i : slowPath) { | |
263 p.println(indent + i.toString()); | |
264 } | |
265 } | |
266 } | |
267 } |