Mercurial > hg > truffle
annotate src/share/vm/adlc/output_c.cpp @ 14521:29ccc4cbabca
Merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 12 Mar 2014 13:30:08 +0100 |
parents | 194e8b7fe9ca |
children | 4ca6dc0799b6 |
rev | line source |
---|---|
0 | 1 /* |
14223
de6a9e811145
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
12167
diff
changeset
|
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1541
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1541
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1541
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 // output_c.cpp - Class CPP file output routines for architecture definition | |
26 | |
27 #include "adlc.hpp" | |
28 | |
29 // Utilities to characterize effect statements | |
30 static bool is_def(int usedef) { | |
31 switch(usedef) { | |
32 case Component::DEF: | |
33 case Component::USE_DEF: return true; break; | |
34 } | |
35 return false; | |
36 } | |
37 | |
38 // Define an array containing the machine register names, strings. | |
39 static void defineRegNames(FILE *fp, RegisterForm *registers) { | |
40 if (registers) { | |
41 fprintf(fp,"\n"); | |
42 fprintf(fp,"// An array of character pointers to machine register names.\n"); | |
43 fprintf(fp,"const char *Matcher::regName[REG_COUNT] = {\n"); | |
44 | |
45 // Output the register name for each register in the allocation classes | |
46 RegDef *reg_def = NULL; | |
47 RegDef *next = NULL; | |
48 registers->reset_RegDefs(); | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
49 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) { |
0 | 50 next = registers->iter_RegDefs(); |
51 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
52 fprintf(fp," \"%s\"%s\n", reg_def->_regname, comma); |
0 | 53 } |
54 | |
55 // Finish defining enumeration | |
56 fprintf(fp,"};\n"); | |
57 | |
58 fprintf(fp,"\n"); | |
59 fprintf(fp,"// An array of character pointers to machine register names.\n"); | |
60 fprintf(fp,"const VMReg OptoReg::opto2vm[REG_COUNT] = {\n"); | |
61 reg_def = NULL; | |
62 next = NULL; | |
63 registers->reset_RegDefs(); | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
64 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) { |
0 | 65 next = registers->iter_RegDefs(); |
66 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
67 fprintf(fp,"\t%s%s\n", reg_def->_concrete, comma); |
0 | 68 } |
69 // Finish defining array | |
70 fprintf(fp,"\t};\n"); | |
71 fprintf(fp,"\n"); | |
72 | |
73 fprintf(fp," OptoReg::Name OptoReg::vm2opto[ConcreteRegisterImpl::number_of_registers];\n"); | |
74 | |
75 } | |
76 } | |
77 | |
78 // Define an array containing the machine register encoding values | |
79 static void defineRegEncodes(FILE *fp, RegisterForm *registers) { | |
80 if (registers) { | |
81 fprintf(fp,"\n"); | |
82 fprintf(fp,"// An array of the machine register encode values\n"); | |
83 fprintf(fp,"const unsigned char Matcher::_regEncode[REG_COUNT] = {\n"); | |
84 | |
85 // Output the register encoding for each register in the allocation classes | |
86 RegDef *reg_def = NULL; | |
87 RegDef *next = NULL; | |
88 registers->reset_RegDefs(); | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
89 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) { |
0 | 90 next = registers->iter_RegDefs(); |
91 const char* register_encode = reg_def->register_encode(); | |
92 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | |
93 int encval; | |
94 if (!ADLParser::is_int_token(register_encode, encval)) { | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
95 fprintf(fp," %s%s // %s\n", register_encode, comma, reg_def->_regname); |
0 | 96 } else { |
97 // Output known constants in hex char format (backward compatibility). | |
98 assert(encval < 256, "Exceeded supported width for register encoding"); | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
99 fprintf(fp," (unsigned char)'\\x%X'%s // %s\n", encval, comma, reg_def->_regname); |
0 | 100 } |
101 } | |
102 // Finish defining enumeration | |
103 fprintf(fp,"};\n"); | |
104 | |
105 } // Done defining array | |
106 } | |
107 | |
108 // Output an enumeration of register class names | |
109 static void defineRegClassEnum(FILE *fp, RegisterForm *registers) { | |
110 if (registers) { | |
111 // Output an enumeration of register class names | |
112 fprintf(fp,"\n"); | |
113 fprintf(fp,"// Enumeration of register class names\n"); | |
114 fprintf(fp, "enum machRegisterClass {\n"); | |
115 registers->_rclasses.reset(); | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
116 for (const char *class_name = NULL; (class_name = registers->_rclasses.iter()) != NULL;) { |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
117 const char * class_name_to_upper = toUpper(class_name); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
118 fprintf(fp," %s,\n", class_name_to_upper); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
119 delete[] class_name_to_upper; |
0 | 120 } |
121 // Finish defining enumeration | |
122 fprintf(fp, " _last_Mach_Reg_Class\n"); | |
123 fprintf(fp, "};\n"); | |
124 } | |
125 } | |
126 | |
127 // Declare an enumeration of user-defined register classes | |
128 // and a list of register masks, one for each class. | |
129 void ArchDesc::declare_register_masks(FILE *fp_hpp) { | |
130 const char *rc_name; | |
131 | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
132 if (_register) { |
0 | 133 // Build enumeration of user-defined register classes. |
134 defineRegClassEnum(fp_hpp, _register); | |
135 | |
136 // Generate a list of register masks, one for each class. | |
137 fprintf(fp_hpp,"\n"); | |
138 fprintf(fp_hpp,"// Register masks, one for each register class.\n"); | |
139 _register->_rclasses.reset(); | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
140 for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) { |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
141 const char *prefix = ""; |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
142 RegClass *reg_class = _register->getRegClass(rc_name); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
143 assert(reg_class, "Using an undefined register class"); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
144 |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
145 const char* rc_name_to_upper = toUpper(rc_name); |
0 | 146 |
4121
db2e64ca2d5a
7090968: Allow adlc register class to depend on runtime conditions
roland
parents:
4114
diff
changeset
|
147 if (reg_class->_user_defined == NULL) { |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
148 fprintf(fp_hpp, "extern const RegMask _%s%s_mask;\n", prefix, rc_name_to_upper); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
149 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { return _%s%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper); |
4121
db2e64ca2d5a
7090968: Allow adlc register class to depend on runtime conditions
roland
parents:
4114
diff
changeset
|
150 } else { |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
151 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { %s }\n", prefix, rc_name_to_upper, reg_class->_user_defined); |
4121
db2e64ca2d5a
7090968: Allow adlc register class to depend on runtime conditions
roland
parents:
4114
diff
changeset
|
152 } |
0 | 153 |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
154 if (reg_class->_stack_or_reg) { |
4121
db2e64ca2d5a
7090968: Allow adlc register class to depend on runtime conditions
roland
parents:
4114
diff
changeset
|
155 assert(reg_class->_user_defined == NULL, "no user defined reg class here"); |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
156 fprintf(fp_hpp, "extern const RegMask _%sSTACK_OR_%s_mask;\n", prefix, rc_name_to_upper); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
157 fprintf(fp_hpp, "inline const RegMask &%sSTACK_OR_%s_mask() { return _%sSTACK_OR_%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper); |
0 | 158 } |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
159 delete[] rc_name_to_upper; |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
160 |
0 | 161 } |
162 } | |
163 } | |
164 | |
165 // Generate an enumeration of user-defined register classes | |
166 // and a list of register masks, one for each class. | |
167 void ArchDesc::build_register_masks(FILE *fp_cpp) { | |
168 const char *rc_name; | |
169 | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
170 if (_register) { |
0 | 171 // Generate a list of register masks, one for each class. |
172 fprintf(fp_cpp,"\n"); | |
173 fprintf(fp_cpp,"// Register masks, one for each register class.\n"); | |
174 _register->_rclasses.reset(); | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
175 for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) { |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
176 const char *prefix = ""; |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
177 RegClass *reg_class = _register->getRegClass(rc_name); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
178 assert(reg_class, "Using an undefined register class"); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
179 |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
180 if (reg_class->_user_defined != NULL) { |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
181 continue; |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
182 } |
4121
db2e64ca2d5a
7090968: Allow adlc register class to depend on runtime conditions
roland
parents:
4114
diff
changeset
|
183 |
0 | 184 int len = RegisterForm::RegMask_Size(); |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
185 const char* rc_name_to_upper = toUpper(rc_name); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
186 fprintf(fp_cpp, "const RegMask _%s%s_mask(", prefix, rc_name_to_upper); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
187 |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
188 { |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
189 int i; |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
190 for(i = 0; i < len - 1; i++) { |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
191 fprintf(fp_cpp," 0x%x,", reg_class->regs_in_word(i, false)); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
192 } |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
193 fprintf(fp_cpp," 0x%x );\n", reg_class->regs_in_word(i, false)); |
0 | 194 } |
195 | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
196 if (reg_class->_stack_or_reg) { |
0 | 197 int i; |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
198 fprintf(fp_cpp, "const RegMask _%sSTACK_OR_%s_mask(", prefix, rc_name_to_upper); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
199 for(i = 0; i < len - 1; i++) { |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
200 fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i, true)); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
201 } |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
202 fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i, true)); |
0 | 203 } |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
204 delete[] rc_name_to_upper; |
0 | 205 } |
206 } | |
207 } | |
208 | |
209 // Compute an index for an array in the pipeline_reads_NNN arrays | |
210 static int pipeline_reads_initializer(FILE *fp_cpp, NameList &pipeline_reads, PipeClassForm *pipeclass) | |
211 { | |
212 int templen = 1; | |
213 int paramcount = 0; | |
214 const char *paramname; | |
215 | |
216 if (pipeclass->_parameters.count() == 0) | |
217 return -1; | |
218 | |
219 pipeclass->_parameters.reset(); | |
220 paramname = pipeclass->_parameters.iter(); | |
221 const PipeClassOperandForm *pipeopnd = | |
222 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; | |
223 if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal")) | |
224 pipeclass->_parameters.reset(); | |
225 | |
226 while ( (paramname = pipeclass->_parameters.iter()) != NULL ) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
227 const PipeClassOperandForm *tmppipeopnd = |
0 | 228 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
229 | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
230 if (tmppipeopnd) |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
231 templen += 10 + (int)strlen(tmppipeopnd->_stage); |
0 | 232 else |
233 templen += 19; | |
234 | |
235 paramcount++; | |
236 } | |
237 | |
238 // See if the count is zero | |
239 if (paramcount == 0) { | |
240 return -1; | |
241 } | |
242 | |
243 char *operand_stages = new char [templen]; | |
244 operand_stages[0] = 0; | |
245 int i = 0; | |
246 templen = 0; | |
247 | |
248 pipeclass->_parameters.reset(); | |
249 paramname = pipeclass->_parameters.iter(); | |
250 pipeopnd = (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; | |
251 if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal")) | |
252 pipeclass->_parameters.reset(); | |
253 | |
254 while ( (paramname = pipeclass->_parameters.iter()) != NULL ) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
255 const PipeClassOperandForm *tmppipeopnd = |
0 | 256 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
257 templen += sprintf(&operand_stages[templen], " stage_%s%c\n", | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
258 tmppipeopnd ? tmppipeopnd->_stage : "undefined", |
0 | 259 (++i < paramcount ? ',' : ' ') ); |
260 } | |
261 | |
262 // See if the same string is in the table | |
263 int ndx = pipeline_reads.index(operand_stages); | |
264 | |
265 // No, add it to the table | |
266 if (ndx < 0) { | |
267 pipeline_reads.addName(operand_stages); | |
268 ndx = pipeline_reads.index(operand_stages); | |
269 | |
270 fprintf(fp_cpp, "static const enum machPipelineStages pipeline_reads_%03d[%d] = {\n%s};\n\n", | |
271 ndx+1, paramcount, operand_stages); | |
272 } | |
273 else | |
274 delete [] operand_stages; | |
275 | |
276 return (ndx); | |
277 } | |
278 | |
279 // Compute an index for an array in the pipeline_res_stages_NNN arrays | |
280 static int pipeline_res_stages_initializer( | |
281 FILE *fp_cpp, | |
282 PipelineForm *pipeline, | |
283 NameList &pipeline_res_stages, | |
284 PipeClassForm *pipeclass) | |
285 { | |
286 const PipeClassResourceForm *piperesource; | |
287 int * res_stages = new int [pipeline->_rescount]; | |
288 int i; | |
289 | |
290 for (i = 0; i < pipeline->_rescount; i++) | |
291 res_stages[i] = 0; | |
292 | |
293 for (pipeclass->_resUsage.reset(); | |
294 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) { | |
295 int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); | |
296 for (i = 0; i < pipeline->_rescount; i++) | |
297 if ((1 << i) & used_mask) { | |
298 int stage = pipeline->_stages.index(piperesource->_stage); | |
299 if (res_stages[i] < stage+1) | |
300 res_stages[i] = stage+1; | |
301 } | |
302 } | |
303 | |
304 // Compute the length needed for the resource list | |
305 int commentlen = 0; | |
306 int max_stage = 0; | |
307 for (i = 0; i < pipeline->_rescount; i++) { | |
308 if (res_stages[i] == 0) { | |
309 if (max_stage < 9) | |
310 max_stage = 9; | |
311 } | |
312 else { | |
313 int stagelen = (int)strlen(pipeline->_stages.name(res_stages[i]-1)); | |
314 if (max_stage < stagelen) | |
315 max_stage = stagelen; | |
316 } | |
317 | |
318 commentlen += (int)strlen(pipeline->_reslist.name(i)); | |
319 } | |
320 | |
321 int templen = 1 + commentlen + pipeline->_rescount * (max_stage + 14); | |
322 | |
323 // Allocate space for the resource list | |
324 char * resource_stages = new char [templen]; | |
325 | |
326 templen = 0; | |
327 for (i = 0; i < pipeline->_rescount; i++) { | |
328 const char * const resname = | |
329 res_stages[i] == 0 ? "undefined" : pipeline->_stages.name(res_stages[i]-1); | |
330 | |
331 templen += sprintf(&resource_stages[templen], " stage_%s%-*s // %s\n", | |
332 resname, max_stage - (int)strlen(resname) + 1, | |
333 (i < pipeline->_rescount-1) ? "," : "", | |
334 pipeline->_reslist.name(i)); | |
335 } | |
336 | |
337 // See if the same string is in the table | |
338 int ndx = pipeline_res_stages.index(resource_stages); | |
339 | |
340 // No, add it to the table | |
341 if (ndx < 0) { | |
342 pipeline_res_stages.addName(resource_stages); | |
343 ndx = pipeline_res_stages.index(resource_stages); | |
344 | |
345 fprintf(fp_cpp, "static const enum machPipelineStages pipeline_res_stages_%03d[%d] = {\n%s};\n\n", | |
346 ndx+1, pipeline->_rescount, resource_stages); | |
347 } | |
348 else | |
349 delete [] resource_stages; | |
350 | |
351 delete [] res_stages; | |
352 | |
353 return (ndx); | |
354 } | |
355 | |
356 // Compute an index for an array in the pipeline_res_cycles_NNN arrays | |
357 static int pipeline_res_cycles_initializer( | |
358 FILE *fp_cpp, | |
359 PipelineForm *pipeline, | |
360 NameList &pipeline_res_cycles, | |
361 PipeClassForm *pipeclass) | |
362 { | |
363 const PipeClassResourceForm *piperesource; | |
364 int * res_cycles = new int [pipeline->_rescount]; | |
365 int i; | |
366 | |
367 for (i = 0; i < pipeline->_rescount; i++) | |
368 res_cycles[i] = 0; | |
369 | |
370 for (pipeclass->_resUsage.reset(); | |
371 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) { | |
372 int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); | |
373 for (i = 0; i < pipeline->_rescount; i++) | |
374 if ((1 << i) & used_mask) { | |
375 int cycles = piperesource->_cycles; | |
376 if (res_cycles[i] < cycles) | |
377 res_cycles[i] = cycles; | |
378 } | |
379 } | |
380 | |
381 // Pre-compute the string length | |
382 int templen; | |
383 int cyclelen = 0, commentlen = 0; | |
384 int max_cycles = 0; | |
385 char temp[32]; | |
386 | |
387 for (i = 0; i < pipeline->_rescount; i++) { | |
388 if (max_cycles < res_cycles[i]) | |
389 max_cycles = res_cycles[i]; | |
390 templen = sprintf(temp, "%d", res_cycles[i]); | |
391 if (cyclelen < templen) | |
392 cyclelen = templen; | |
393 commentlen += (int)strlen(pipeline->_reslist.name(i)); | |
394 } | |
395 | |
396 templen = 1 + commentlen + (cyclelen + 8) * pipeline->_rescount; | |
397 | |
398 // Allocate space for the resource list | |
399 char * resource_cycles = new char [templen]; | |
400 | |
401 templen = 0; | |
402 | |
403 for (i = 0; i < pipeline->_rescount; i++) { | |
404 templen += sprintf(&resource_cycles[templen], " %*d%c // %s\n", | |
405 cyclelen, res_cycles[i], (i < pipeline->_rescount-1) ? ',' : ' ', pipeline->_reslist.name(i)); | |
406 } | |
407 | |
408 // See if the same string is in the table | |
409 int ndx = pipeline_res_cycles.index(resource_cycles); | |
410 | |
411 // No, add it to the table | |
412 if (ndx < 0) { | |
413 pipeline_res_cycles.addName(resource_cycles); | |
414 ndx = pipeline_res_cycles.index(resource_cycles); | |
415 | |
416 fprintf(fp_cpp, "static const uint pipeline_res_cycles_%03d[%d] = {\n%s};\n\n", | |
417 ndx+1, pipeline->_rescount, resource_cycles); | |
418 } | |
419 else | |
420 delete [] resource_cycles; | |
421 | |
422 delete [] res_cycles; | |
423 | |
424 return (ndx); | |
425 } | |
426 | |
427 //typedef unsigned long long uint64_t; | |
428 | |
429 // Compute an index for an array in the pipeline_res_mask_NNN arrays | |
430 static int pipeline_res_mask_initializer( | |
431 FILE *fp_cpp, | |
432 PipelineForm *pipeline, | |
433 NameList &pipeline_res_mask, | |
434 NameList &pipeline_res_args, | |
435 PipeClassForm *pipeclass) | |
436 { | |
437 const PipeClassResourceForm *piperesource; | |
438 const uint rescount = pipeline->_rescount; | |
439 const uint maxcycleused = pipeline->_maxcycleused; | |
440 const uint cyclemasksize = (maxcycleused + 31) >> 5; | |
441 | |
442 int i, j; | |
443 int element_count = 0; | |
444 uint *res_mask = new uint [cyclemasksize]; | |
445 uint resources_used = 0; | |
446 uint resources_used_exclusively = 0; | |
447 | |
448 for (pipeclass->_resUsage.reset(); | |
10389 | 449 (piperesource = (const PipeClassResourceForm*)pipeclass->_resUsage.iter()) != NULL; ) { |
0 | 450 element_count++; |
10389 | 451 } |
0 | 452 |
453 // Pre-compute the string length | |
454 int templen; | |
455 int commentlen = 0; | |
456 int max_cycles = 0; | |
457 | |
458 int cyclelen = ((maxcycleused + 3) >> 2); | |
459 int masklen = (rescount + 3) >> 2; | |
460 | |
461 int cycledigit = 0; | |
462 for (i = maxcycleused; i > 0; i /= 10) | |
463 cycledigit++; | |
464 | |
465 int maskdigit = 0; | |
466 for (i = rescount; i > 0; i /= 10) | |
467 maskdigit++; | |
468 | |
10389 | 469 static const char* pipeline_use_cycle_mask = "Pipeline_Use_Cycle_Mask"; |
470 static const char* pipeline_use_element = "Pipeline_Use_Element"; | |
0 | 471 |
472 templen = 1 + | |
473 (int)(strlen(pipeline_use_cycle_mask) + (int)strlen(pipeline_use_element) + | |
474 (cyclemasksize * 12) + masklen + (cycledigit * 2) + 30) * element_count; | |
475 | |
476 // Allocate space for the resource list | |
477 char * resource_mask = new char [templen]; | |
478 char * last_comma = NULL; | |
479 | |
480 templen = 0; | |
481 | |
482 for (pipeclass->_resUsage.reset(); | |
10389 | 483 (piperesource = (const PipeClassResourceForm*)pipeclass->_resUsage.iter()) != NULL; ) { |
0 | 484 int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); |
485 | |
10389 | 486 if (!used_mask) { |
0 | 487 fprintf(stderr, "*** used_mask is 0 ***\n"); |
10389 | 488 } |
0 | 489 |
490 resources_used |= used_mask; | |
491 | |
492 uint lb, ub; | |
493 | |
494 for (lb = 0; (used_mask & (1 << lb)) == 0; lb++); | |
495 for (ub = 31; (used_mask & (1 << ub)) == 0; ub--); | |
496 | |
10389 | 497 if (lb == ub) { |
0 | 498 resources_used_exclusively |= used_mask; |
10389 | 499 } |
0 | 500 |
501 int formatlen = | |
502 sprintf(&resource_mask[templen], " %s(0x%0*x, %*d, %*d, %s %s(", | |
503 pipeline_use_element, | |
504 masklen, used_mask, | |
505 cycledigit, lb, cycledigit, ub, | |
506 ((used_mask & (used_mask-1)) != 0) ? "true, " : "false,", | |
507 pipeline_use_cycle_mask); | |
508 | |
509 templen += formatlen; | |
510 | |
511 memset(res_mask, 0, cyclemasksize * sizeof(uint)); | |
512 | |
513 int cycles = piperesource->_cycles; | |
514 uint stage = pipeline->_stages.index(piperesource->_stage); | |
10389 | 515 if ((uint)NameList::Not_in_list == stage) { |
6850 | 516 fprintf(stderr, |
517 "pipeline_res_mask_initializer: " | |
518 "semantic error: " | |
519 "pipeline stage undeclared: %s\n", | |
520 piperesource->_stage); | |
521 exit(1); | |
522 } | |
10389 | 523 uint upper_limit = stage + cycles - 1; |
524 uint lower_limit = stage - 1; | |
0 | 525 uint upper_idx = upper_limit >> 5; |
526 uint lower_idx = lower_limit >> 5; | |
527 uint upper_position = upper_limit & 0x1f; | |
528 uint lower_position = lower_limit & 0x1f; | |
529 | |
530 uint mask = (((uint)1) << upper_position) - 1; | |
531 | |
10389 | 532 while (upper_idx > lower_idx) { |
0 | 533 res_mask[upper_idx--] |= mask; |
534 mask = (uint)-1; | |
535 } | |
536 | |
537 mask -= (((uint)1) << lower_position) - 1; | |
538 res_mask[upper_idx] |= mask; | |
539 | |
540 for (j = cyclemasksize-1; j >= 0; j--) { | |
541 formatlen = | |
542 sprintf(&resource_mask[templen], "0x%08x%s", res_mask[j], j > 0 ? ", " : ""); | |
543 templen += formatlen; | |
544 } | |
545 | |
546 resource_mask[templen++] = ')'; | |
547 resource_mask[templen++] = ')'; | |
548 last_comma = &resource_mask[templen]; | |
549 resource_mask[templen++] = ','; | |
550 resource_mask[templen++] = '\n'; | |
551 } | |
552 | |
553 resource_mask[templen] = 0; | |
10389 | 554 if (last_comma) { |
0 | 555 last_comma[0] = ' '; |
10389 | 556 } |
0 | 557 |
558 // See if the same string is in the table | |
559 int ndx = pipeline_res_mask.index(resource_mask); | |
560 | |
561 // No, add it to the table | |
562 if (ndx < 0) { | |
563 pipeline_res_mask.addName(resource_mask); | |
564 ndx = pipeline_res_mask.index(resource_mask); | |
565 | |
566 if (strlen(resource_mask) > 0) | |
567 fprintf(fp_cpp, "static const Pipeline_Use_Element pipeline_res_mask_%03d[%d] = {\n%s};\n\n", | |
568 ndx+1, element_count, resource_mask); | |
569 | |
10389 | 570 char* args = new char [9 + 2*masklen + maskdigit]; |
0 | 571 |
572 sprintf(args, "0x%0*x, 0x%0*x, %*d", | |
573 masklen, resources_used, | |
574 masklen, resources_used_exclusively, | |
575 maskdigit, element_count); | |
576 | |
577 pipeline_res_args.addName(args); | |
578 } | |
10389 | 579 else { |
0 | 580 delete [] resource_mask; |
10389 | 581 } |
0 | 582 |
583 delete [] res_mask; | |
584 //delete [] res_masks; | |
585 | |
586 return (ndx); | |
587 } | |
588 | |
589 void ArchDesc::build_pipe_classes(FILE *fp_cpp) { | |
590 const char *classname; | |
591 const char *resourcename; | |
592 int resourcenamelen = 0; | |
593 NameList pipeline_reads; | |
594 NameList pipeline_res_stages; | |
595 NameList pipeline_res_cycles; | |
596 NameList pipeline_res_masks; | |
597 NameList pipeline_res_args; | |
598 const int default_latency = 1; | |
599 const int non_operand_latency = 0; | |
600 const int node_latency = 0; | |
601 | |
602 if (!_pipeline) { | |
603 fprintf(fp_cpp, "uint Node::latency(uint i) const {\n"); | |
604 fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n"); | |
605 fprintf(fp_cpp, " return %d;\n", non_operand_latency); | |
606 fprintf(fp_cpp, "}\n"); | |
607 return; | |
608 } | |
609 | |
610 fprintf(fp_cpp, "\n"); | |
611 fprintf(fp_cpp, "//------------------Pipeline Methods-----------------------------------------\n"); | |
612 fprintf(fp_cpp, "#ifndef PRODUCT\n"); | |
613 fprintf(fp_cpp, "const char * Pipeline::stageName(uint s) {\n"); | |
614 fprintf(fp_cpp, " static const char * const _stage_names[] = {\n"); | |
615 fprintf(fp_cpp, " \"undefined\""); | |
616 | |
617 for (int s = 0; s < _pipeline->_stagecnt; s++) | |
618 fprintf(fp_cpp, ", \"%s\"", _pipeline->_stages.name(s)); | |
619 | |
620 fprintf(fp_cpp, "\n };\n\n"); | |
621 fprintf(fp_cpp, " return (s <= %d ? _stage_names[s] : \"???\");\n", | |
622 _pipeline->_stagecnt); | |
623 fprintf(fp_cpp, "}\n"); | |
624 fprintf(fp_cpp, "#endif\n\n"); | |
625 | |
626 fprintf(fp_cpp, "uint Pipeline::functional_unit_latency(uint start, const Pipeline *pred) const {\n"); | |
627 fprintf(fp_cpp, " // See if the functional units overlap\n"); | |
628 #if 0 | |
629 fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); | |
630 fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); | |
631 fprintf(fp_cpp, " tty->print(\"# functional_unit_latency: start == %%d, this->exclusively == 0x%%03x, pred->exclusively == 0x%%03x\\n\", start, resourcesUsedExclusively(), pred->resourcesUsedExclusively());\n"); | |
632 fprintf(fp_cpp, " }\n"); | |
633 fprintf(fp_cpp, "#endif\n\n"); | |
634 #endif | |
635 fprintf(fp_cpp, " uint mask = resourcesUsedExclusively() & pred->resourcesUsedExclusively();\n"); | |
636 fprintf(fp_cpp, " if (mask == 0)\n return (start);\n\n"); | |
637 #if 0 | |
638 fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); | |
639 fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); | |
640 fprintf(fp_cpp, " tty->print(\"# functional_unit_latency: mask == 0x%%x\\n\", mask);\n"); | |
641 fprintf(fp_cpp, " }\n"); | |
642 fprintf(fp_cpp, "#endif\n\n"); | |
643 #endif | |
644 fprintf(fp_cpp, " for (uint i = 0; i < pred->resourceUseCount(); i++) {\n"); | |
645 fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred->resourceUseElement(i);\n"); | |
646 fprintf(fp_cpp, " if (predUse->multiple())\n"); | |
647 fprintf(fp_cpp, " continue;\n\n"); | |
648 fprintf(fp_cpp, " for (uint j = 0; j < resourceUseCount(); j++) {\n"); | |
649 fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = resourceUseElement(j);\n"); | |
650 fprintf(fp_cpp, " if (currUse->multiple())\n"); | |
651 fprintf(fp_cpp, " continue;\n\n"); | |
652 fprintf(fp_cpp, " if (predUse->used() & currUse->used()) {\n"); | |
653 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->mask();\n"); | |
654 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->mask();\n\n"); | |
655 fprintf(fp_cpp, " for ( y <<= start; x.overlaps(y); start++ )\n"); | |
656 fprintf(fp_cpp, " y <<= 1;\n"); | |
657 fprintf(fp_cpp, " }\n"); | |
658 fprintf(fp_cpp, " }\n"); | |
659 fprintf(fp_cpp, " }\n\n"); | |
660 fprintf(fp_cpp, " // There is the potential for overlap\n"); | |
661 fprintf(fp_cpp, " return (start);\n"); | |
662 fprintf(fp_cpp, "}\n\n"); | |
663 fprintf(fp_cpp, "// The following two routines assume that the root Pipeline_Use entity\n"); | |
664 fprintf(fp_cpp, "// consists of exactly 1 element for each functional unit\n"); | |
665 fprintf(fp_cpp, "// start is relative to the current cycle; used for latency-based info\n"); | |
666 fprintf(fp_cpp, "uint Pipeline_Use::full_latency(uint delay, const Pipeline_Use &pred) const {\n"); | |
667 fprintf(fp_cpp, " for (uint i = 0; i < pred._count; i++) {\n"); | |
668 fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred.element(i);\n"); | |
669 fprintf(fp_cpp, " if (predUse->_multiple) {\n"); | |
670 fprintf(fp_cpp, " uint min_delay = %d;\n", | |
671 _pipeline->_maxcycleused+1); | |
672 fprintf(fp_cpp, " // Multiple possible functional units, choose first unused one\n"); | |
673 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); | |
674 fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = element(j);\n"); | |
675 fprintf(fp_cpp, " uint curr_delay = delay;\n"); | |
676 fprintf(fp_cpp, " if (predUse->_used & currUse->_used) {\n"); | |
677 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->_mask;\n"); | |
678 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n"); | |
679 fprintf(fp_cpp, " for ( y <<= curr_delay; x.overlaps(y); curr_delay++ )\n"); | |
680 fprintf(fp_cpp, " y <<= 1;\n"); | |
681 fprintf(fp_cpp, " }\n"); | |
682 fprintf(fp_cpp, " if (min_delay > curr_delay)\n min_delay = curr_delay;\n"); | |
683 fprintf(fp_cpp, " }\n"); | |
684 fprintf(fp_cpp, " if (delay < min_delay)\n delay = min_delay;\n"); | |
685 fprintf(fp_cpp, " }\n"); | |
686 fprintf(fp_cpp, " else {\n"); | |
687 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); | |
688 fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = element(j);\n"); | |
689 fprintf(fp_cpp, " if (predUse->_used & currUse->_used) {\n"); | |
690 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->_mask;\n"); | |
691 fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n"); | |
692 fprintf(fp_cpp, " for ( y <<= delay; x.overlaps(y); delay++ )\n"); | |
693 fprintf(fp_cpp, " y <<= 1;\n"); | |
694 fprintf(fp_cpp, " }\n"); | |
695 fprintf(fp_cpp, " }\n"); | |
696 fprintf(fp_cpp, " }\n"); | |
697 fprintf(fp_cpp, " }\n\n"); | |
698 fprintf(fp_cpp, " return (delay);\n"); | |
699 fprintf(fp_cpp, "}\n\n"); | |
700 fprintf(fp_cpp, "void Pipeline_Use::add_usage(const Pipeline_Use &pred) {\n"); | |
701 fprintf(fp_cpp, " for (uint i = 0; i < pred._count; i++) {\n"); | |
702 fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred.element(i);\n"); | |
703 fprintf(fp_cpp, " if (predUse->_multiple) {\n"); | |
704 fprintf(fp_cpp, " // Multiple possible functional units, choose first unused one\n"); | |
705 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); | |
706 fprintf(fp_cpp, " Pipeline_Use_Element *currUse = element(j);\n"); | |
707 fprintf(fp_cpp, " if ( !predUse->_mask.overlaps(currUse->_mask) ) {\n"); | |
708 fprintf(fp_cpp, " currUse->_used |= (1 << j);\n"); | |
709 fprintf(fp_cpp, " _resources_used |= (1 << j);\n"); | |
710 fprintf(fp_cpp, " currUse->_mask.Or(predUse->_mask);\n"); | |
711 fprintf(fp_cpp, " break;\n"); | |
712 fprintf(fp_cpp, " }\n"); | |
713 fprintf(fp_cpp, " }\n"); | |
714 fprintf(fp_cpp, " }\n"); | |
715 fprintf(fp_cpp, " else {\n"); | |
716 fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); | |
717 fprintf(fp_cpp, " Pipeline_Use_Element *currUse = element(j);\n"); | |
718 fprintf(fp_cpp, " currUse->_used |= (1 << j);\n"); | |
719 fprintf(fp_cpp, " _resources_used |= (1 << j);\n"); | |
720 fprintf(fp_cpp, " currUse->_mask.Or(predUse->_mask);\n"); | |
721 fprintf(fp_cpp, " }\n"); | |
722 fprintf(fp_cpp, " }\n"); | |
723 fprintf(fp_cpp, " }\n"); | |
724 fprintf(fp_cpp, "}\n\n"); | |
725 | |
726 fprintf(fp_cpp, "uint Pipeline::operand_latency(uint opnd, const Pipeline *pred) const {\n"); | |
727 fprintf(fp_cpp, " int const default_latency = 1;\n"); | |
728 fprintf(fp_cpp, "\n"); | |
729 #if 0 | |
730 fprintf(fp_cpp, "#ifndef PRODUCT\n"); | |
731 fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); | |
732 fprintf(fp_cpp, " tty->print(\"# operand_latency(%%d), _read_stage_count = %%d\\n\", opnd, _read_stage_count);\n"); | |
733 fprintf(fp_cpp, " }\n"); | |
734 fprintf(fp_cpp, "#endif\n\n"); | |
735 #endif | |
1489
cff162798819
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
1203
diff
changeset
|
736 fprintf(fp_cpp, " assert(this, \"NULL pipeline info\");\n"); |
cff162798819
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
1203
diff
changeset
|
737 fprintf(fp_cpp, " assert(pred, \"NULL predecessor pipline info\");\n\n"); |
0 | 738 fprintf(fp_cpp, " if (pred->hasFixedLatency())\n return (pred->fixedLatency());\n\n"); |
739 fprintf(fp_cpp, " // If this is not an operand, then assume a dependence with 0 latency\n"); | |
740 fprintf(fp_cpp, " if (opnd > _read_stage_count)\n return (0);\n\n"); | |
741 fprintf(fp_cpp, " uint writeStage = pred->_write_stage;\n"); | |
742 fprintf(fp_cpp, " uint readStage = _read_stages[opnd-1];\n"); | |
743 #if 0 | |
744 fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); | |
745 fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); | |
746 fprintf(fp_cpp, " tty->print(\"# operand_latency: writeStage=%%s readStage=%%s, opnd=%%d\\n\", stageName(writeStage), stageName(readStage), opnd);\n"); | |
747 fprintf(fp_cpp, " }\n"); | |
748 fprintf(fp_cpp, "#endif\n\n"); | |
749 #endif | |
750 fprintf(fp_cpp, "\n"); | |
751 fprintf(fp_cpp, " if (writeStage == stage_undefined || readStage == stage_undefined)\n"); | |
752 fprintf(fp_cpp, " return (default_latency);\n"); | |
753 fprintf(fp_cpp, "\n"); | |
754 fprintf(fp_cpp, " int delta = writeStage - readStage;\n"); | |
755 fprintf(fp_cpp, " if (delta < 0) delta = 0;\n\n"); | |
756 #if 0 | |
757 fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); | |
758 fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); | |
759 fprintf(fp_cpp, " tty->print(\"# operand_latency: delta=%%d\\n\", delta);\n"); | |
760 fprintf(fp_cpp, " }\n"); | |
761 fprintf(fp_cpp, "#endif\n\n"); | |
762 #endif | |
763 fprintf(fp_cpp, " return (delta);\n"); | |
764 fprintf(fp_cpp, "}\n\n"); | |
765 | |
766 if (!_pipeline) | |
767 /* Do Nothing */; | |
768 | |
769 else if (_pipeline->_maxcycleused <= | |
770 #ifdef SPARC | |
771 64 | |
772 #else | |
773 32 | |
774 #endif | |
775 ) { | |
776 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); | |
777 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(in1._mask & in2._mask);\n"); | |
778 fprintf(fp_cpp, "}\n\n"); | |
779 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); | |
780 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(in1._mask | in2._mask);\n"); | |
781 fprintf(fp_cpp, "}\n\n"); | |
782 } | |
783 else { | |
784 uint l; | |
785 uint masklen = (_pipeline->_maxcycleused + 31) >> 5; | |
786 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); | |
787 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask("); | |
788 for (l = 1; l <= masklen; l++) | |
789 fprintf(fp_cpp, "in1._mask%d & in2._mask%d%s\n", l, l, l < masklen ? ", " : ""); | |
790 fprintf(fp_cpp, ");\n"); | |
791 fprintf(fp_cpp, "}\n\n"); | |
792 fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); | |
793 fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask("); | |
794 for (l = 1; l <= masklen; l++) | |
795 fprintf(fp_cpp, "in1._mask%d | in2._mask%d%s", l, l, l < masklen ? ", " : ""); | |
796 fprintf(fp_cpp, ");\n"); | |
797 fprintf(fp_cpp, "}\n\n"); | |
798 fprintf(fp_cpp, "void Pipeline_Use_Cycle_Mask::Or(const Pipeline_Use_Cycle_Mask &in2) {\n "); | |
799 for (l = 1; l <= masklen; l++) | |
800 fprintf(fp_cpp, " _mask%d |= in2._mask%d;", l, l); | |
801 fprintf(fp_cpp, "\n}\n\n"); | |
802 } | |
803 | |
804 /* Get the length of all the resource names */ | |
805 for (_pipeline->_reslist.reset(), resourcenamelen = 0; | |
806 (resourcename = _pipeline->_reslist.iter()) != NULL; | |
807 resourcenamelen += (int)strlen(resourcename)); | |
808 | |
809 // Create the pipeline class description | |
810 | |
811 fprintf(fp_cpp, "static const Pipeline pipeline_class_Zero_Instructions(0, 0, true, 0, 0, false, false, false, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n"); | |
812 fprintf(fp_cpp, "static const Pipeline pipeline_class_Unknown_Instructions(0, 0, true, 0, 0, false, true, true, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n"); | |
813 | |
814 fprintf(fp_cpp, "const Pipeline_Use_Element Pipeline_Use::elaborated_elements[%d] = {\n", _pipeline->_rescount); | |
815 for (int i1 = 0; i1 < _pipeline->_rescount; i1++) { | |
816 fprintf(fp_cpp, " Pipeline_Use_Element(0, %d, %d, false, Pipeline_Use_Cycle_Mask(", i1, i1); | |
817 uint masklen = (_pipeline->_maxcycleused + 31) >> 5; | |
818 for (int i2 = masklen-1; i2 >= 0; i2--) | |
819 fprintf(fp_cpp, "0%s", i2 > 0 ? ", " : ""); | |
820 fprintf(fp_cpp, "))%s\n", i1 < (_pipeline->_rescount-1) ? "," : ""); | |
821 } | |
822 fprintf(fp_cpp, "};\n\n"); | |
823 | |
824 fprintf(fp_cpp, "const Pipeline_Use Pipeline_Use::elaborated_use(0, 0, %d, (Pipeline_Use_Element *)&elaborated_elements[0]);\n\n", | |
825 _pipeline->_rescount); | |
826 | |
827 for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) { | |
828 fprintf(fp_cpp, "\n"); | |
829 fprintf(fp_cpp, "// Pipeline Class \"%s\"\n", classname); | |
830 PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass(); | |
831 int maxWriteStage = -1; | |
832 int maxMoreInstrs = 0; | |
833 int paramcount = 0; | |
834 int i = 0; | |
835 const char *paramname; | |
836 int resource_count = (_pipeline->_rescount + 3) >> 2; | |
837 | |
838 // Scan the operands, looking for last output stage and number of inputs | |
839 for (pipeclass->_parameters.reset(); (paramname = pipeclass->_parameters.iter()) != NULL; ) { | |
840 const PipeClassOperandForm *pipeopnd = | |
841 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; | |
842 if (pipeopnd) { | |
843 if (pipeopnd->_iswrite) { | |
844 int stagenum = _pipeline->_stages.index(pipeopnd->_stage); | |
845 int moreinsts = pipeopnd->_more_instrs; | |
846 if ((maxWriteStage+maxMoreInstrs) < (stagenum+moreinsts)) { | |
847 maxWriteStage = stagenum; | |
848 maxMoreInstrs = moreinsts; | |
849 } | |
850 } | |
851 } | |
852 | |
853 if (i++ > 0 || (pipeopnd && !pipeopnd->isWrite())) | |
854 paramcount++; | |
855 } | |
856 | |
857 // Create the list of stages for the operands that are read | |
858 // Note that we will build a NameList to reduce the number of copies | |
859 | |
860 int pipeline_reads_index = pipeline_reads_initializer(fp_cpp, pipeline_reads, pipeclass); | |
861 | |
862 int pipeline_res_stages_index = pipeline_res_stages_initializer( | |
863 fp_cpp, _pipeline, pipeline_res_stages, pipeclass); | |
864 | |
865 int pipeline_res_cycles_index = pipeline_res_cycles_initializer( | |
866 fp_cpp, _pipeline, pipeline_res_cycles, pipeclass); | |
867 | |
868 int pipeline_res_mask_index = pipeline_res_mask_initializer( | |
869 fp_cpp, _pipeline, pipeline_res_masks, pipeline_res_args, pipeclass); | |
870 | |
871 #if 0 | |
872 // Process the Resources | |
873 const PipeClassResourceForm *piperesource; | |
874 | |
875 unsigned resources_used = 0; | |
876 unsigned exclusive_resources_used = 0; | |
877 unsigned resource_groups = 0; | |
878 for (pipeclass->_resUsage.reset(); | |
879 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) { | |
880 int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); | |
881 if (used_mask) | |
882 resource_groups++; | |
883 resources_used |= used_mask; | |
884 if ((used_mask & (used_mask-1)) == 0) | |
885 exclusive_resources_used |= used_mask; | |
886 } | |
887 | |
888 if (resource_groups > 0) { | |
889 fprintf(fp_cpp, "static const uint pipeline_res_or_masks_%03d[%d] = {", | |
890 pipeclass->_num, resource_groups); | |
891 for (pipeclass->_resUsage.reset(), i = 1; | |
892 (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; | |
893 i++ ) { | |
894 int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); | |
895 if (used_mask) { | |
896 fprintf(fp_cpp, " 0x%0*x%c", resource_count, used_mask, i < (int)resource_groups ? ',' : ' '); | |
897 } | |
898 } | |
899 fprintf(fp_cpp, "};\n\n"); | |
900 } | |
901 #endif | |
902 | |
903 // Create the pipeline class description | |
904 fprintf(fp_cpp, "static const Pipeline pipeline_class_%03d(", | |
905 pipeclass->_num); | |
906 if (maxWriteStage < 0) | |
907 fprintf(fp_cpp, "(uint)stage_undefined"); | |
908 else if (maxMoreInstrs == 0) | |
909 fprintf(fp_cpp, "(uint)stage_%s", _pipeline->_stages.name(maxWriteStage)); | |
910 else | |
911 fprintf(fp_cpp, "((uint)stage_%s)+%d", _pipeline->_stages.name(maxWriteStage), maxMoreInstrs); | |
912 fprintf(fp_cpp, ", %d, %s, %d, %d, %s, %s, %s, %s,\n", | |
913 paramcount, | |
914 pipeclass->hasFixedLatency() ? "true" : "false", | |
915 pipeclass->fixedLatency(), | |
916 pipeclass->InstructionCount(), | |
917 pipeclass->hasBranchDelay() ? "true" : "false", | |
918 pipeclass->hasMultipleBundles() ? "true" : "false", | |
919 pipeclass->forceSerialization() ? "true" : "false", | |
920 pipeclass->mayHaveNoCode() ? "true" : "false" ); | |
921 if (paramcount > 0) { | |
922 fprintf(fp_cpp, "\n (enum machPipelineStages * const) pipeline_reads_%03d,\n ", | |
923 pipeline_reads_index+1); | |
924 } | |
925 else | |
926 fprintf(fp_cpp, " NULL,"); | |
927 fprintf(fp_cpp, " (enum machPipelineStages * const) pipeline_res_stages_%03d,\n", | |
928 pipeline_res_stages_index+1); | |
929 fprintf(fp_cpp, " (uint * const) pipeline_res_cycles_%03d,\n", | |
930 pipeline_res_cycles_index+1); | |
931 fprintf(fp_cpp, " Pipeline_Use(%s, (Pipeline_Use_Element *)", | |
932 pipeline_res_args.name(pipeline_res_mask_index)); | |
933 if (strlen(pipeline_res_masks.name(pipeline_res_mask_index)) > 0) | |
934 fprintf(fp_cpp, "&pipeline_res_mask_%03d[0]", | |
935 pipeline_res_mask_index+1); | |
936 else | |
937 fprintf(fp_cpp, "NULL"); | |
938 fprintf(fp_cpp, "));\n"); | |
939 } | |
940 | |
941 // Generate the Node::latency method if _pipeline defined | |
942 fprintf(fp_cpp, "\n"); | |
943 fprintf(fp_cpp, "//------------------Inter-Instruction Latency--------------------------------\n"); | |
944 fprintf(fp_cpp, "uint Node::latency(uint i) {\n"); | |
945 if (_pipeline) { | |
946 #if 0 | |
947 fprintf(fp_cpp, "#ifndef PRODUCT\n"); | |
948 fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); | |
949 fprintf(fp_cpp, " tty->print(\"# %%4d->latency(%%d)\\n\", _idx, i);\n"); | |
950 fprintf(fp_cpp, " }\n"); | |
951 fprintf(fp_cpp, "#endif\n"); | |
952 #endif | |
953 fprintf(fp_cpp, " uint j;\n"); | |
954 fprintf(fp_cpp, " // verify in legal range for inputs\n"); | |
955 fprintf(fp_cpp, " assert(i < len(), \"index not in range\");\n\n"); | |
956 fprintf(fp_cpp, " // verify input is not null\n"); | |
957 fprintf(fp_cpp, " Node *pred = in(i);\n"); | |
958 fprintf(fp_cpp, " if (!pred)\n return %d;\n\n", | |
959 non_operand_latency); | |
960 fprintf(fp_cpp, " if (pred->is_Proj())\n pred = pred->in(0);\n\n"); | |
961 fprintf(fp_cpp, " // if either node does not have pipeline info, use default\n"); | |
962 fprintf(fp_cpp, " const Pipeline *predpipe = pred->pipeline();\n"); | |
963 fprintf(fp_cpp, " assert(predpipe, \"no predecessor pipeline info\");\n\n"); | |
964 fprintf(fp_cpp, " if (predpipe->hasFixedLatency())\n return predpipe->fixedLatency();\n\n"); | |
965 fprintf(fp_cpp, " const Pipeline *currpipe = pipeline();\n"); | |
966 fprintf(fp_cpp, " assert(currpipe, \"no pipeline info\");\n\n"); | |
967 fprintf(fp_cpp, " if (!is_Mach())\n return %d;\n\n", | |
968 node_latency); | |
969 fprintf(fp_cpp, " const MachNode *m = as_Mach();\n"); | |
970 fprintf(fp_cpp, " j = m->oper_input_base();\n"); | |
971 fprintf(fp_cpp, " if (i < j)\n return currpipe->functional_unit_latency(%d, predpipe);\n\n", | |
972 non_operand_latency); | |
973 fprintf(fp_cpp, " // determine which operand this is in\n"); | |
974 fprintf(fp_cpp, " uint n = m->num_opnds();\n"); | |
975 fprintf(fp_cpp, " int delta = %d;\n\n", | |
976 non_operand_latency); | |
977 fprintf(fp_cpp, " uint k;\n"); | |
978 fprintf(fp_cpp, " for (k = 1; k < n; k++) {\n"); | |
979 fprintf(fp_cpp, " j += m->_opnds[k]->num_edges();\n"); | |
980 fprintf(fp_cpp, " if (i < j)\n"); | |
981 fprintf(fp_cpp, " break;\n"); | |
982 fprintf(fp_cpp, " }\n"); | |
983 fprintf(fp_cpp, " if (k < n)\n"); | |
984 fprintf(fp_cpp, " delta = currpipe->operand_latency(k,predpipe);\n\n"); | |
985 fprintf(fp_cpp, " return currpipe->functional_unit_latency(delta, predpipe);\n"); | |
986 } | |
987 else { | |
988 fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n"); | |
989 fprintf(fp_cpp, " return %d;\n", | |
990 non_operand_latency); | |
991 } | |
992 fprintf(fp_cpp, "}\n\n"); | |
993 | |
994 // Output the list of nop nodes | |
995 fprintf(fp_cpp, "// Descriptions for emitting different functional unit nops\n"); | |
996 const char *nop; | |
997 int nopcnt = 0; | |
998 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; nopcnt++ ); | |
999 | |
1000 fprintf(fp_cpp, "void Bundle::initialize_nops(MachNode * nop_list[%d], Compile *C) {\n", nopcnt); | |
1001 int i = 0; | |
1002 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; i++ ) { | |
1003 fprintf(fp_cpp, " nop_list[%d] = (MachNode *) new (C) %sNode();\n", i, nop); | |
1004 } | |
1005 fprintf(fp_cpp, "};\n\n"); | |
1006 fprintf(fp_cpp, "#ifndef PRODUCT\n"); | |
6850 | 1007 fprintf(fp_cpp, "void Bundle::dump(outputStream *st) const {\n"); |
0 | 1008 fprintf(fp_cpp, " static const char * bundle_flags[] = {\n"); |
1009 fprintf(fp_cpp, " \"\",\n"); | |
1010 fprintf(fp_cpp, " \"use nop delay\",\n"); | |
1011 fprintf(fp_cpp, " \"use unconditional delay\",\n"); | |
1012 fprintf(fp_cpp, " \"use conditional delay\",\n"); | |
1013 fprintf(fp_cpp, " \"used in conditional delay\",\n"); | |
1014 fprintf(fp_cpp, " \"used in unconditional delay\",\n"); | |
1015 fprintf(fp_cpp, " \"used in all conditional delays\",\n"); | |
1016 fprintf(fp_cpp, " };\n\n"); | |
1017 | |
1018 fprintf(fp_cpp, " static const char *resource_names[%d] = {", _pipeline->_rescount); | |
1019 for (i = 0; i < _pipeline->_rescount; i++) | |
1020 fprintf(fp_cpp, " \"%s\"%c", _pipeline->_reslist.name(i), i < _pipeline->_rescount-1 ? ',' : ' '); | |
1021 fprintf(fp_cpp, "};\n\n"); | |
1022 | |
1023 // See if the same string is in the table | |
1024 fprintf(fp_cpp, " bool needs_comma = false;\n\n"); | |
1025 fprintf(fp_cpp, " if (_flags) {\n"); | |
6850 | 1026 fprintf(fp_cpp, " st->print(\"%%s\", bundle_flags[_flags]);\n"); |
0 | 1027 fprintf(fp_cpp, " needs_comma = true;\n"); |
1028 fprintf(fp_cpp, " };\n"); | |
1029 fprintf(fp_cpp, " if (instr_count()) {\n"); | |
6850 | 1030 fprintf(fp_cpp, " st->print(\"%%s%%d instr%%s\", needs_comma ? \", \" : \"\", instr_count(), instr_count() != 1 ? \"s\" : \"\");\n"); |
0 | 1031 fprintf(fp_cpp, " needs_comma = true;\n"); |
1032 fprintf(fp_cpp, " };\n"); | |
1033 fprintf(fp_cpp, " uint r = resources_used();\n"); | |
1034 fprintf(fp_cpp, " if (r) {\n"); | |
6850 | 1035 fprintf(fp_cpp, " st->print(\"%%sresource%%s:\", needs_comma ? \", \" : \"\", (r & (r-1)) != 0 ? \"s\" : \"\");\n"); |
0 | 1036 fprintf(fp_cpp, " for (uint i = 0; i < %d; i++)\n", _pipeline->_rescount); |
1037 fprintf(fp_cpp, " if ((r & (1 << i)) != 0)\n"); | |
6850 | 1038 fprintf(fp_cpp, " st->print(\" %%s\", resource_names[i]);\n"); |
0 | 1039 fprintf(fp_cpp, " needs_comma = true;\n"); |
1040 fprintf(fp_cpp, " };\n"); | |
6850 | 1041 fprintf(fp_cpp, " st->print(\"\\n\");\n"); |
0 | 1042 fprintf(fp_cpp, "}\n"); |
1043 fprintf(fp_cpp, "#endif\n"); | |
1044 } | |
1045 | |
1046 // --------------------------------------------------------------------------- | |
1047 //------------------------------Utilities to build Instruction Classes-------- | |
1048 // --------------------------------------------------------------------------- | |
1049 | |
1050 static void defineOut_RegMask(FILE *fp, const char *node, const char *regMask) { | |
1051 fprintf(fp,"const RegMask &%sNode::out_RegMask() const { return (%s); }\n", | |
1052 node, regMask); | |
1053 } | |
1054 | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1055 static void print_block_index(FILE *fp, int inst_position) { |
0 | 1056 assert( inst_position >= 0, "Instruction number less than zero"); |
1057 fprintf(fp, "block_index"); | |
1058 if( inst_position != 0 ) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1059 fprintf(fp, " - %d", inst_position); |
0 | 1060 } |
1061 } | |
1062 | |
1063 // Scan the peepmatch and output a test for each instruction | |
1064 static void check_peepmatch_instruction_sequence(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1065 int parent = -1; |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1066 int inst_position = 0; |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1067 const char* inst_name = NULL; |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1068 int input = 0; |
0 | 1069 fprintf(fp, " // Check instruction sub-tree\n"); |
1070 pmatch->reset(); | |
1071 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); | |
1072 inst_name != NULL; | |
1073 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { | |
1074 // If this is not a placeholder | |
1075 if( ! pmatch->is_placeholder() ) { | |
1076 // Define temporaries 'inst#', based on parent and parent's input index | |
1077 if( parent != -1 ) { // root was initialized | |
1078 fprintf(fp, " // Identify previous instruction if inside this block\n"); | |
1079 fprintf(fp, " if( "); | |
1080 print_block_index(fp, inst_position); | |
12167
650868c062a9
8023691: Create interface for nodes in class Block
adlertz
parents:
10389
diff
changeset
|
1081 fprintf(fp, " > 0 ) {\n Node *n = block->get_node("); |
0 | 1082 print_block_index(fp, inst_position); |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1083 fprintf(fp, ");\n inst%d = (n->is_Mach()) ? ", inst_position); |
0 | 1084 fprintf(fp, "n->as_Mach() : NULL;\n }\n"); |
1085 } | |
1086 | |
1087 // When not the root | |
1088 // Test we have the correct instruction by comparing the rule. | |
1089 if( parent != -1 ) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1090 fprintf(fp, " matches = matches && (inst%d != NULL) && (inst%d->rule() == %s_rule);\n", |
0 | 1091 inst_position, inst_position, inst_name); |
1092 } | |
1093 } else { | |
1094 // Check that user did not try to constrain a placeholder | |
1095 assert( ! pconstraint->constrains_instruction(inst_position), | |
1096 "fatal(): Can not constrain a placeholder instruction"); | |
1097 } | |
1098 } | |
1099 } | |
1100 | |
1101 // Build mapping for register indices, num_edges to input | |
1102 static void build_instruction_index_mapping( FILE *fp, FormDict &globals, PeepMatch *pmatch ) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1103 int parent = -1; |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1104 int inst_position = 0; |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1105 const char* inst_name = NULL; |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1106 int input = 0; |
0 | 1107 fprintf(fp, " // Build map to register info\n"); |
1108 pmatch->reset(); | |
1109 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); | |
1110 inst_name != NULL; | |
1111 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { | |
1112 // If this is not a placeholder | |
1113 if( ! pmatch->is_placeholder() ) { | |
1114 // Define temporaries 'inst#', based on self's inst_position | |
1115 InstructForm *inst = globals[inst_name]->is_instruction(); | |
1116 if( inst != NULL ) { | |
1117 char inst_prefix[] = "instXXXX_"; | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1118 sprintf(inst_prefix, "inst%d_", inst_position); |
0 | 1119 char receiver[] = "instXXXX->"; |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1120 sprintf(receiver, "inst%d->", inst_position); |
0 | 1121 inst->index_temps( fp, globals, inst_prefix, receiver ); |
1122 } | |
1123 } | |
1124 } | |
1125 } | |
1126 | |
1127 // Generate tests for the constraints | |
1128 static void check_peepconstraints(FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint) { | |
1129 fprintf(fp, "\n"); | |
1130 fprintf(fp, " // Check constraints on sub-tree-leaves\n"); | |
1131 | |
1132 // Build mapping from num_edges to local variables | |
1133 build_instruction_index_mapping( fp, globals, pmatch ); | |
1134 | |
1135 // Build constraint tests | |
1136 if( pconstraint != NULL ) { | |
1137 fprintf(fp, " matches = matches &&"); | |
1138 bool first_constraint = true; | |
1139 while( pconstraint != NULL ) { | |
1140 // indentation and connecting '&&' | |
1141 const char *indentation = " "; | |
1142 fprintf(fp, "\n%s%s", indentation, (!first_constraint ? "&& " : " ")); | |
1143 | |
1144 // Only have '==' relation implemented | |
1145 if( strcmp(pconstraint->_relation,"==") != 0 ) { | |
1146 assert( false, "Unimplemented()" ); | |
1147 } | |
1148 | |
1149 // LEFT | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1150 int left_index = pconstraint->_left_inst; |
0 | 1151 const char *left_op = pconstraint->_left_op; |
1152 // Access info on the instructions whose operands are compared | |
1153 InstructForm *inst_left = globals[pmatch->instruction_name(left_index)]->is_instruction(); | |
1154 assert( inst_left, "Parser should guaranty this is an instruction"); | |
1155 int left_op_base = inst_left->oper_input_base(globals); | |
1156 // Access info on the operands being compared | |
1157 int left_op_index = inst_left->operand_position(left_op, Component::USE); | |
1158 if( left_op_index == -1 ) { | |
1159 left_op_index = inst_left->operand_position(left_op, Component::DEF); | |
1160 if( left_op_index == -1 ) { | |
1161 left_op_index = inst_left->operand_position(left_op, Component::USE_DEF); | |
1162 } | |
1163 } | |
1164 assert( left_op_index != NameList::Not_in_list, "Did not find operand in instruction"); | |
1165 ComponentList components_left = inst_left->_components; | |
1166 const char *left_comp_type = components_left.at(left_op_index)->_type; | |
1167 OpClassForm *left_opclass = globals[left_comp_type]->is_opclass(); | |
1168 Form::InterfaceType left_interface_type = left_opclass->interface_type(globals); | |
1169 | |
1170 | |
1171 // RIGHT | |
1172 int right_op_index = -1; | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1173 int right_index = pconstraint->_right_inst; |
0 | 1174 const char *right_op = pconstraint->_right_op; |
1175 if( right_index != -1 ) { // Match operand | |
1176 // Access info on the instructions whose operands are compared | |
1177 InstructForm *inst_right = globals[pmatch->instruction_name(right_index)]->is_instruction(); | |
1178 assert( inst_right, "Parser should guaranty this is an instruction"); | |
1179 int right_op_base = inst_right->oper_input_base(globals); | |
1180 // Access info on the operands being compared | |
1181 right_op_index = inst_right->operand_position(right_op, Component::USE); | |
1182 if( right_op_index == -1 ) { | |
1183 right_op_index = inst_right->operand_position(right_op, Component::DEF); | |
1184 if( right_op_index == -1 ) { | |
1185 right_op_index = inst_right->operand_position(right_op, Component::USE_DEF); | |
1186 } | |
1187 } | |
1188 assert( right_op_index != NameList::Not_in_list, "Did not find operand in instruction"); | |
1189 ComponentList components_right = inst_right->_components; | |
1190 const char *right_comp_type = components_right.at(right_op_index)->_type; | |
1191 OpClassForm *right_opclass = globals[right_comp_type]->is_opclass(); | |
1192 Form::InterfaceType right_interface_type = right_opclass->interface_type(globals); | |
1193 assert( right_interface_type == left_interface_type, "Both must be same interface"); | |
1194 | |
1195 } else { // Else match register | |
1196 // assert( false, "should be a register" ); | |
1197 } | |
1198 | |
1199 // | |
1200 // Check for equivalence | |
1201 // | |
1202 // fprintf(fp, "phase->eqv( "); | |
1203 // fprintf(fp, "inst%d->in(%d+%d) /* %s */, inst%d->in(%d+%d) /* %s */", | |
1204 // left_index, left_op_base, left_op_index, left_op, | |
1205 // right_index, right_op_base, right_op_index, right_op ); | |
1206 // fprintf(fp, ")"); | |
1207 // | |
1208 switch( left_interface_type ) { | |
1209 case Form::register_interface: { | |
1210 // Check that they are allocated to the same register | |
1211 // Need parameter for index position if not result operand | |
1212 char left_reg_index[] = ",instXXXX_idxXXXX"; | |
1213 if( left_op_index != 0 ) { | |
1214 assert( (left_index <= 9999) && (left_op_index <= 9999), "exceed string size"); | |
1215 // Must have index into operands | |
6850 | 1216 sprintf(left_reg_index,",inst%d_idx%d", (int)left_index, left_op_index); |
0 | 1217 } else { |
1218 strcpy(left_reg_index, ""); | |
1219 } | |
1220 fprintf(fp, "(inst%d->_opnds[%d]->reg(ra_,inst%d%s) /* %d.%s */", | |
1221 left_index, left_op_index, left_index, left_reg_index, left_index, left_op ); | |
1222 fprintf(fp, " == "); | |
1223 | |
1224 if( right_index != -1 ) { | |
1225 char right_reg_index[18] = ",instXXXX_idxXXXX"; | |
1226 if( right_op_index != 0 ) { | |
1227 assert( (right_index <= 9999) && (right_op_index <= 9999), "exceed string size"); | |
1228 // Must have index into operands | |
6850 | 1229 sprintf(right_reg_index,",inst%d_idx%d", (int)right_index, right_op_index); |
0 | 1230 } else { |
1231 strcpy(right_reg_index, ""); | |
1232 } | |
1233 fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->reg(ra_,inst%d%s)", | |
1234 right_index, right_op, right_index, right_op_index, right_index, right_reg_index ); | |
1235 } else { | |
1236 fprintf(fp, "%s_enc", right_op ); | |
1237 } | |
1238 fprintf(fp,")"); | |
1239 break; | |
1240 } | |
1241 case Form::constant_interface: { | |
1242 // Compare the '->constant()' values | |
1243 fprintf(fp, "(inst%d->_opnds[%d]->constant() /* %d.%s */", | |
1244 left_index, left_op_index, left_index, left_op ); | |
1245 fprintf(fp, " == "); | |
1246 fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->constant())", | |
1247 right_index, right_op, right_index, right_op_index ); | |
1248 break; | |
1249 } | |
1250 case Form::memory_interface: { | |
1251 // Compare 'base', 'index', 'scale', and 'disp' | |
1252 // base | |
1253 fprintf(fp, "( \n"); | |
1254 fprintf(fp, " (inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d) /* %d.%s$$base */", | |
1255 left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op ); | |
1256 fprintf(fp, " == "); | |
1257 fprintf(fp, "/* %d.%s$$base */ inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d)) &&\n", | |
1258 right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index ); | |
1259 // index | |
1260 fprintf(fp, " (inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d) /* %d.%s$$index */", | |
1261 left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op ); | |
1262 fprintf(fp, " == "); | |
1263 fprintf(fp, "/* %d.%s$$index */ inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d)) &&\n", | |
1264 right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index ); | |
1265 // scale | |
1266 fprintf(fp, " (inst%d->_opnds[%d]->scale() /* %d.%s$$scale */", | |
1267 left_index, left_op_index, left_index, left_op ); | |
1268 fprintf(fp, " == "); | |
1269 fprintf(fp, "/* %d.%s$$scale */ inst%d->_opnds[%d]->scale()) &&\n", | |
1270 right_index, right_op, right_index, right_op_index ); | |
1271 // disp | |
1272 fprintf(fp, " (inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d) /* %d.%s$$disp */", | |
1273 left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op ); | |
1274 fprintf(fp, " == "); | |
1275 fprintf(fp, "/* %d.%s$$disp */ inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d))\n", | |
1276 right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index ); | |
1277 fprintf(fp, ") \n"); | |
1278 break; | |
1279 } | |
1280 case Form::conditional_interface: { | |
1281 // Compare the condition code being tested | |
1282 assert( false, "Unimplemented()" ); | |
1283 break; | |
1284 } | |
1285 default: { | |
1286 assert( false, "ShouldNotReachHere()" ); | |
1287 break; | |
1288 } | |
1289 } | |
1290 | |
1291 // Advance to next constraint | |
1292 pconstraint = pconstraint->next(); | |
1293 first_constraint = false; | |
1294 } | |
1295 | |
1296 fprintf(fp, ";\n"); | |
1297 } | |
1298 } | |
1299 | |
1300 // // EXPERIMENTAL -- TEMPORARY code | |
1301 // static Form::DataType get_operand_type(FormDict &globals, InstructForm *instr, const char *op_name ) { | |
1302 // int op_index = instr->operand_position(op_name, Component::USE); | |
1303 // if( op_index == -1 ) { | |
1304 // op_index = instr->operand_position(op_name, Component::DEF); | |
1305 // if( op_index == -1 ) { | |
1306 // op_index = instr->operand_position(op_name, Component::USE_DEF); | |
1307 // } | |
1308 // } | |
1309 // assert( op_index != NameList::Not_in_list, "Did not find operand in instruction"); | |
1310 // | |
1311 // ComponentList components_right = instr->_components; | |
1312 // char *right_comp_type = components_right.at(op_index)->_type; | |
1313 // OpClassForm *right_opclass = globals[right_comp_type]->is_opclass(); | |
1314 // Form::InterfaceType right_interface_type = right_opclass->interface_type(globals); | |
1315 // | |
1316 // return; | |
1317 // } | |
1318 | |
1319 // Construct the new sub-tree | |
1320 static void generate_peepreplace( FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint, PeepReplace *preplace, int max_position ) { | |
1321 fprintf(fp, " // IF instructions and constraints matched\n"); | |
1322 fprintf(fp, " if( matches ) {\n"); | |
1323 fprintf(fp, " // generate the new sub-tree\n"); | |
1324 fprintf(fp, " assert( true, \"Debug stopping point\");\n"); | |
1325 if( preplace != NULL ) { | |
1326 // Get the root of the new sub-tree | |
1327 const char *root_inst = NULL; | |
1328 preplace->next_instruction(root_inst); | |
1329 InstructForm *root_form = globals[root_inst]->is_instruction(); | |
1330 assert( root_form != NULL, "Replacement instruction was not previously defined"); | |
1331 fprintf(fp, " %sNode *root = new (C) %sNode();\n", root_inst, root_inst); | |
1332 | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1333 int inst_num; |
0 | 1334 const char *op_name; |
1335 int opnds_index = 0; // define result operand | |
1336 // Then install the use-operands for the new sub-tree | |
1337 // preplace->reset(); // reset breaks iteration | |
1338 for( preplace->next_operand( inst_num, op_name ); | |
1339 op_name != NULL; | |
1340 preplace->next_operand( inst_num, op_name ) ) { | |
1341 InstructForm *inst_form; | |
1342 inst_form = globals[pmatch->instruction_name(inst_num)]->is_instruction(); | |
1343 assert( inst_form, "Parser should guaranty this is an instruction"); | |
1344 int inst_op_num = inst_form->operand_position(op_name, Component::USE); | |
1345 if( inst_op_num == NameList::Not_in_list ) | |
1346 inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF); | |
1347 assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE"); | |
1348 // find the name of the OperandForm from the local name | |
1349 const Form *form = inst_form->_localNames[op_name]; | |
1350 OperandForm *op_form = form->is_operand(); | |
1351 if( opnds_index == 0 ) { | |
1352 // Initial setup of new instruction | |
1353 fprintf(fp, " // ----- Initial setup -----\n"); | |
1354 // | |
1355 // Add control edge for this node | |
1356 fprintf(fp, " root->add_req(_in[0]); // control edge\n"); | |
1357 // Add unmatched edges from root of match tree | |
1358 int op_base = root_form->oper_input_base(globals); | |
1359 for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1360 fprintf(fp, " root->add_req(inst%d->in(%d)); // unmatched ideal edge\n", |
0 | 1361 inst_num, unmatched_edge); |
1362 } | |
1363 // If new instruction captures bottom type | |
1541
b5fdf39b9749
6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents:
1489
diff
changeset
|
1364 if( root_form->captures_bottom_type(globals) ) { |
0 | 1365 // Get bottom type from instruction whose result we are replacing |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1366 fprintf(fp, " root->_bottom_type = inst%d->bottom_type();\n", inst_num); |
0 | 1367 } |
1368 // Define result register and result operand | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1369 fprintf(fp, " ra_->add_reference(root, inst%d);\n", inst_num); |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1370 fprintf(fp, " ra_->set_oop (root, ra_->is_oop(inst%d));\n", inst_num); |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1371 fprintf(fp, " ra_->set_pair(root->_idx, ra_->get_reg_second(inst%d), ra_->get_reg_first(inst%d));\n", inst_num, inst_num); |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1372 fprintf(fp, " root->_opnds[0] = inst%d->_opnds[0]->clone(C); // result\n", inst_num); |
0 | 1373 fprintf(fp, " // ----- Done with initial setup -----\n"); |
1374 } else { | |
1375 if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) { | |
1376 // Do not have ideal edges for constants after matching | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1377 fprintf(fp, " for( unsigned x%d = inst%d_idx%d; x%d < inst%d_idx%d; x%d++ )\n", |
0 | 1378 inst_op_num, inst_num, inst_op_num, |
1379 inst_op_num, inst_num, inst_op_num+1, inst_op_num ); | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1380 fprintf(fp, " root->add_req( inst%d->in(x%d) );\n", |
0 | 1381 inst_num, inst_op_num ); |
1382 } else { | |
1383 fprintf(fp, " // no ideal edge for constants after matching\n"); | |
1384 } | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1385 fprintf(fp, " root->_opnds[%d] = inst%d->_opnds[%d]->clone(C);\n", |
0 | 1386 opnds_index, inst_num, inst_op_num ); |
1387 } | |
1388 ++opnds_index; | |
1389 } | |
1390 }else { | |
1391 // Replacing subtree with empty-tree | |
1392 assert( false, "ShouldNotReachHere();"); | |
1393 } | |
1394 | |
1395 // Return the new sub-tree | |
1396 fprintf(fp, " deleted = %d;\n", max_position+1 /*zero to one based*/); | |
1397 fprintf(fp, " return root; // return new root;\n"); | |
1398 fprintf(fp, " }\n"); | |
1399 } | |
1400 | |
1401 | |
1402 // Define the Peephole method for an instruction node | |
1403 void ArchDesc::definePeephole(FILE *fp, InstructForm *node) { | |
1404 // Generate Peephole function header | |
1405 fprintf(fp, "MachNode *%sNode::peephole( Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile* C ) {\n", node->_ident); | |
1406 fprintf(fp, " bool matches = true;\n"); | |
1407 | |
1408 // Identify the maximum instruction position, | |
1409 // generate temporaries that hold current instruction | |
1410 // | |
1411 // MachNode *inst0 = NULL; | |
1412 // ... | |
1413 // MachNode *instMAX = NULL; | |
1414 // | |
1415 int max_position = 0; | |
1416 Peephole *peep; | |
1417 for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) { | |
1418 PeepMatch *pmatch = peep->match(); | |
1419 assert( pmatch != NULL, "fatal(), missing peepmatch rule"); | |
1420 if( max_position < pmatch->max_position() ) max_position = pmatch->max_position(); | |
1421 } | |
1422 for( int i = 0; i <= max_position; ++i ) { | |
1423 if( i == 0 ) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1424 fprintf(fp, " MachNode *inst0 = this;\n"); |
0 | 1425 } else { |
1426 fprintf(fp, " MachNode *inst%d = NULL;\n", i); | |
1427 } | |
1428 } | |
1429 | |
1430 // For each peephole rule in architecture description | |
1431 // Construct a test for the desired instruction sub-tree | |
1432 // then check the constraints | |
1433 // If these match, Generate the new subtree | |
1434 for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) { | |
1435 int peephole_number = peep->peephole_number(); | |
1436 PeepMatch *pmatch = peep->match(); | |
1437 PeepConstraint *pconstraint = peep->constraints(); | |
1438 PeepReplace *preplace = peep->replacement(); | |
1439 | |
1440 // Root of this peephole is the current MachNode | |
1441 assert( true, // %%name?%% strcmp( node->_ident, pmatch->name(0) ) == 0, | |
1442 "root of PeepMatch does not match instruction"); | |
1443 | |
1444 // Make each peephole rule individually selectable | |
1445 fprintf(fp, " if( (OptoPeepholeAt == -1) || (OptoPeepholeAt==%d) ) {\n", peephole_number); | |
1446 fprintf(fp, " matches = true;\n"); | |
1447 // Scan the peepmatch and output a test for each instruction | |
1448 check_peepmatch_instruction_sequence( fp, pmatch, pconstraint ); | |
1449 | |
1450 // Check constraints and build replacement inside scope | |
1451 fprintf(fp, " // If instruction subtree matches\n"); | |
1452 fprintf(fp, " if( matches ) {\n"); | |
1453 | |
1454 // Generate tests for the constraints | |
1455 check_peepconstraints( fp, _globalNames, pmatch, pconstraint ); | |
1456 | |
1457 // Construct the new sub-tree | |
1458 generate_peepreplace( fp, _globalNames, pmatch, pconstraint, preplace, max_position ); | |
1459 | |
1460 // End of scope for this peephole's constraints | |
1461 fprintf(fp, " }\n"); | |
1462 // Closing brace '}' to make each peephole rule individually selectable | |
1463 fprintf(fp, " } // end of peephole rule #%d\n", peephole_number); | |
1464 fprintf(fp, "\n"); | |
1465 } | |
1466 | |
1467 fprintf(fp, " return NULL; // No peephole rules matched\n"); | |
1468 fprintf(fp, "}\n"); | |
1469 fprintf(fp, "\n"); | |
1470 } | |
1471 | |
1472 // Define the Expand method for an instruction node | |
1473 void ArchDesc::defineExpand(FILE *fp, InstructForm *node) { | |
1474 unsigned cnt = 0; // Count nodes we have expand into | |
1475 unsigned i; | |
1476 | |
1477 // Generate Expand function header | |
2008 | 1478 fprintf(fp, "MachNode* %sNode::Expand(State* state, Node_List& proj_list, Node* mem) {\n", node->_ident); |
1479 fprintf(fp, " Compile* C = Compile::current();\n"); | |
0 | 1480 // Generate expand code |
1481 if( node->expands() ) { | |
1482 const char *opid; | |
1483 int new_pos, exp_pos; | |
1484 const char *new_id = NULL; | |
1485 const Form *frm = NULL; | |
1486 InstructForm *new_inst = NULL; | |
1487 OperandForm *new_oper = NULL; | |
1488 unsigned numo = node->num_opnds() + | |
1489 node->_exprule->_newopers.count(); | |
1490 | |
1491 // If necessary, generate any operands created in expand rule | |
1492 if (node->_exprule->_newopers.count()) { | |
1493 for(node->_exprule->_newopers.reset(); | |
1494 (new_id = node->_exprule->_newopers.iter()) != NULL; cnt++) { | |
1495 frm = node->_localNames[new_id]; | |
1496 assert(frm, "Invalid entry in new operands list of expand rule"); | |
1497 new_oper = frm->is_operand(); | |
1498 char *tmp = (char *)node->_exprule->_newopconst[new_id]; | |
1499 if (tmp == NULL) { | |
1500 fprintf(fp," MachOper *op%d = new (C) %sOper();\n", | |
1501 cnt, new_oper->_ident); | |
1502 } | |
1503 else { | |
1504 fprintf(fp," MachOper *op%d = new (C) %sOper(%s);\n", | |
1505 cnt, new_oper->_ident, tmp); | |
1506 } | |
1507 } | |
1508 } | |
1509 cnt = 0; | |
1510 // Generate the temps to use for DAG building | |
1511 for(i = 0; i < numo; i++) { | |
1512 if (i < node->num_opnds()) { | |
1513 fprintf(fp," MachNode *tmp%d = this;\n", i); | |
1514 } | |
1515 else { | |
1516 fprintf(fp," MachNode *tmp%d = NULL;\n", i); | |
1517 } | |
1518 } | |
1519 // Build mapping from num_edges to local variables | |
1520 fprintf(fp," unsigned num0 = 0;\n"); | |
1521 for( i = 1; i < node->num_opnds(); i++ ) { | |
1522 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();\n",i,i); | |
1523 } | |
1524 | |
1525 // Build a mapping from operand index to input edges | |
1526 fprintf(fp," unsigned idx0 = oper_input_base();\n"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1527 |
1203 | 1528 // The order in which the memory input is added to a node is very |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1529 // strange. Store nodes get a memory input before Expand is |
1203 | 1530 // called and other nodes get it afterwards or before depending on |
1531 // match order so oper_input_base is wrong during expansion. This | |
1532 // code adjusts it so that expansion will work correctly. | |
1533 int has_memory_edge = node->_matrule->needs_ideal_memory_edge(_globalNames); | |
1534 if (has_memory_edge) { | |
1535 fprintf(fp," if (mem == (Node*)1) {\n"); | |
1536 fprintf(fp," idx0--; // Adjust base because memory edge hasn't been inserted yet\n"); | |
1537 fprintf(fp," }\n"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1538 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1539 |
0 | 1540 for( i = 0; i < node->num_opnds(); i++ ) { |
1541 fprintf(fp," unsigned idx%d = idx%d + num%d;\n", | |
1542 i+1,i,i); | |
1543 } | |
1544 | |
1545 // Declare variable to hold root of expansion | |
1546 fprintf(fp," MachNode *result = NULL;\n"); | |
1547 | |
1548 // Iterate over the instructions 'node' expands into | |
1549 ExpandRule *expand = node->_exprule; | |
1550 NameAndList *expand_instr = NULL; | |
1551 for(expand->reset_instructions(); | |
1552 (expand_instr = expand->iter_instructions()) != NULL; cnt++) { | |
1553 new_id = expand_instr->name(); | |
1554 | |
1555 InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id]; | |
14431
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1556 |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1557 if (!expand_instruction) { |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1558 globalAD->syntax_err(node->_linenum, "In %s: instruction %s used in expand not declared\n", |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1559 node->_ident, new_id); |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1560 continue; |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1561 } |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1562 |
0 | 1563 if (expand_instruction->has_temps()) { |
1564 globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s", | |
1565 node->_ident, new_id); | |
1566 } | |
1567 | |
1568 // Build the node for the instruction | |
1569 fprintf(fp,"\n %sNode *n%d = new (C) %sNode();\n", new_id, cnt, new_id); | |
1570 // Add control edge for this node | |
1571 fprintf(fp," n%d->add_req(_in[0]);\n", cnt); | |
1572 // Build the operand for the value this node defines. | |
1573 Form *form = (Form*)_globalNames[new_id]; | |
1574 assert( form, "'new_id' must be a defined form name"); | |
1575 // Grab the InstructForm for the new instruction | |
1576 new_inst = form->is_instruction(); | |
1577 assert( new_inst, "'new_id' must be an instruction name"); | |
1578 if( node->is_ideal_if() && new_inst->is_ideal_if() ) { | |
1579 fprintf(fp, " ((MachIfNode*)n%d)->_prob = _prob;\n",cnt); | |
1580 fprintf(fp, " ((MachIfNode*)n%d)->_fcnt = _fcnt;\n",cnt); | |
1581 } | |
1582 | |
1583 if( node->is_ideal_fastlock() && new_inst->is_ideal_fastlock() ) { | |
1584 fprintf(fp, " ((MachFastLockNode*)n%d)->_counters = _counters;\n",cnt); | |
1585 } | |
1586 | |
6802
0702f188baeb
7200233: C2: can't use expand rules for vector instruction rules
kvn
parents:
6725
diff
changeset
|
1587 // Fill in the bottom_type where requested |
0702f188baeb
7200233: C2: can't use expand rules for vector instruction rules
kvn
parents:
6725
diff
changeset
|
1588 if (node->captures_bottom_type(_globalNames) && |
0702f188baeb
7200233: C2: can't use expand rules for vector instruction rules
kvn
parents:
6725
diff
changeset
|
1589 new_inst->captures_bottom_type(_globalNames)) { |
0702f188baeb
7200233: C2: can't use expand rules for vector instruction rules
kvn
parents:
6725
diff
changeset
|
1590 fprintf(fp, " ((MachTypeNode*)n%d)->_bottom_type = bottom_type();\n", cnt); |
0702f188baeb
7200233: C2: can't use expand rules for vector instruction rules
kvn
parents:
6725
diff
changeset
|
1591 } |
0702f188baeb
7200233: C2: can't use expand rules for vector instruction rules
kvn
parents:
6725
diff
changeset
|
1592 |
0 | 1593 const char *resultOper = new_inst->reduce_result(); |
1594 fprintf(fp," n%d->set_opnd_array(0, state->MachOperGenerator( %s, C ));\n", | |
1595 cnt, machOperEnum(resultOper)); | |
1596 | |
1597 // get the formal operand NameList | |
1598 NameList *formal_lst = &new_inst->_parameters; | |
1599 formal_lst->reset(); | |
1600 | |
1601 // Handle any memory operand | |
1602 int memory_operand = new_inst->memory_operand(_globalNames); | |
1603 if( memory_operand != InstructForm::NO_MEMORY_OPERAND ) { | |
1604 int node_mem_op = node->memory_operand(_globalNames); | |
1605 assert( node_mem_op != InstructForm::NO_MEMORY_OPERAND, | |
1606 "expand rule member needs memory but top-level inst doesn't have any" ); | |
1203 | 1607 if (has_memory_edge) { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1608 // Copy memory edge |
1203 | 1609 fprintf(fp," if (mem != (Node*)1) {\n"); |
1610 fprintf(fp," n%d->add_req(_in[1]);\t// Add memory edge\n", cnt); | |
1611 fprintf(fp," }\n"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1612 } |
0 | 1613 } |
1614 | |
1615 // Iterate over the new instruction's operands | |
415
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1616 int prev_pos = -1; |
0 | 1617 for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) { |
1618 // Use 'parameter' at current position in list of new instruction's formals | |
1619 // instead of 'opid' when looking up info internal to new_inst | |
1620 const char *parameter = formal_lst->iter(); | |
14431
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1621 if (!parameter) { |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1622 globalAD->syntax_err(node->_linenum, "Operand %s of expand instruction %s has" |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1623 " no equivalent in new instruction %s.", |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1624 opid, node->_ident, new_inst->_ident); |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1625 assert(0, "Wrong expand"); |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1626 } |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
1627 |
0 | 1628 // Check for an operand which is created in the expand rule |
1629 if ((exp_pos = node->_exprule->_newopers.index(opid)) != -1) { | |
1630 new_pos = new_inst->operand_position(parameter,Component::USE); | |
1631 exp_pos += node->num_opnds(); | |
1632 // If there is no use of the created operand, just skip it | |
6850 | 1633 if (new_pos != NameList::Not_in_list) { |
0 | 1634 //Copy the operand from the original made above |
1635 fprintf(fp," n%d->set_opnd_array(%d, op%d->clone(C)); // %s\n", | |
1636 cnt, new_pos, exp_pos-node->num_opnds(), opid); | |
1637 // Check for who defines this operand & add edge if needed | |
1638 fprintf(fp," if(tmp%d != NULL)\n", exp_pos); | |
1639 fprintf(fp," n%d->add_req(tmp%d);\n", cnt, exp_pos); | |
1640 } | |
1641 } | |
1642 else { | |
1643 // Use operand name to get an index into instruction component list | |
1644 // ins = (InstructForm *) _globalNames[new_id]; | |
1645 exp_pos = node->operand_position_format(opid); | |
1646 assert(exp_pos != -1, "Bad expand rule"); | |
415
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1647 if (prev_pos > exp_pos && expand_instruction->_matrule != NULL) { |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1648 // For the add_req calls below to work correctly they need |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1649 // to added in the same order that a match would add them. |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1650 // This means that they would need to be in the order of |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1651 // the components list instead of the formal parameters. |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1652 // This is a sort of hidden invariant that previously |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1653 // wasn't checked and could lead to incorrectly |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1654 // constructed nodes. |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1655 syntax_err(node->_linenum, "For expand in %s to work, parameter declaration order in %s must follow matchrule\n", |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1656 node->_ident, new_inst->_ident); |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1657 } |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
1658 prev_pos = exp_pos; |
0 | 1659 |
1660 new_pos = new_inst->operand_position(parameter,Component::USE); | |
1661 if (new_pos != -1) { | |
1662 // Copy the operand from the ExpandNode to the new node | |
1663 fprintf(fp," n%d->set_opnd_array(%d, opnd_array(%d)->clone(C)); // %s\n", | |
1664 cnt, new_pos, exp_pos, opid); | |
1665 // For each operand add appropriate input edges by looking at tmp's | |
1666 fprintf(fp," if(tmp%d == this) {\n", exp_pos); | |
1667 // Grab corresponding edges from ExpandNode and insert them here | |
1668 fprintf(fp," for(unsigned i = 0; i < num%d; i++) {\n", exp_pos); | |
1669 fprintf(fp," n%d->add_req(_in[i + idx%d]);\n", cnt, exp_pos); | |
1670 fprintf(fp," }\n"); | |
1671 fprintf(fp," }\n"); | |
1672 // This value is generated by one of the new instructions | |
1673 fprintf(fp," else n%d->add_req(tmp%d);\n", cnt, exp_pos); | |
1674 } | |
1675 } | |
1676 | |
1677 // Update the DAG tmp's for values defined by this instruction | |
1678 int new_def_pos = new_inst->operand_position(parameter,Component::DEF); | |
1679 Effect *eform = (Effect *)new_inst->_effects[parameter]; | |
1680 // If this operand is a definition in either an effects rule | |
1681 // or a match rule | |
1682 if((eform) && (is_def(eform->_use_def))) { | |
1683 // Update the temp associated with this operand | |
1684 fprintf(fp," tmp%d = n%d;\n", exp_pos, cnt); | |
1685 } | |
1686 else if( new_def_pos != -1 ) { | |
1687 // Instruction defines a value but user did not declare it | |
1688 // in the 'effect' clause | |
1689 fprintf(fp," tmp%d = n%d;\n", exp_pos, cnt); | |
1690 } | |
1691 } // done iterating over a new instruction's operands | |
1692 | |
1693 // Invoke Expand() for the newly created instruction. | |
1203 | 1694 fprintf(fp," result = n%d->Expand( state, proj_list, mem );\n", cnt); |
0 | 1695 assert( !new_inst->expands(), "Do not have complete support for recursive expansion"); |
1696 } // done iterating over new instructions | |
1697 fprintf(fp,"\n"); | |
1698 } // done generating expand rule | |
1699 | |
2254
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1700 // Generate projections for instruction's additional DEFs and KILLs |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1701 if( ! node->expands() && (node->needs_projections() || node->has_temps())) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1702 // Get string representing the MachNode that projections point at |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1703 const char *machNode = "this"; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1704 // Generate the projections |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1705 fprintf(fp," // Add projection edges for additional defs or kills\n"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1706 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1707 // Examine each component to see if it is a DEF or KILL |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1708 node->_components.reset(); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1709 // Skip the first component, if already handled as (SET dst (...)) |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1710 Component *comp = NULL; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1711 // For kills, the choice of projection numbers is arbitrary |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1712 int proj_no = 1; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1713 bool declared_def = false; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1714 bool declared_kill = false; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1715 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1716 while( (comp = node->_components.iter()) != NULL ) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1717 // Lookup register class associated with operand type |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1718 Form *form = (Form*)_globalNames[comp->_type]; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1719 assert( form, "component type must be a defined form"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1720 OperandForm *op = form->is_operand(); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1721 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1722 if (comp->is(Component::TEMP)) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1723 fprintf(fp, " // TEMP %s\n", comp->_name); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1724 if (!declared_def) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1725 // Define the variable "def" to hold new MachProjNodes |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1726 fprintf(fp, " MachTempNode *def;\n"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1727 declared_def = true; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1728 } |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1729 if (op && op->_interface && op->_interface->is_RegInterface()) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1730 fprintf(fp," def = new (C) MachTempNode(state->MachOperGenerator( %s, C ));\n", |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1731 machOperEnum(op->_ident)); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1732 fprintf(fp," add_req(def);\n"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1733 // The operand for TEMP is already constructed during |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1734 // this mach node construction, see buildMachNode(). |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1735 // |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1736 // int idx = node->operand_position_format(comp->_name); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1737 // fprintf(fp," set_opnd_array(%d, state->MachOperGenerator( %s, C ));\n", |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1738 // idx, machOperEnum(op->_ident)); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1739 } else { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1740 assert(false, "can't have temps which aren't registers"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1741 } |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1742 } else if (comp->isa(Component::KILL)) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1743 fprintf(fp, " // DEF/KILL %s\n", comp->_name); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1744 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1745 if (!declared_kill) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1746 // Define the variable "kill" to hold new MachProjNodes |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1747 fprintf(fp, " MachProjNode *kill;\n"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1748 declared_kill = true; |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1749 } |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1750 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1751 assert( op, "Support additional KILLS for base operands"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1752 const char *regmask = reg_mask(*op); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1753 const char *ideal_type = op->ideal_type(_globalNames, _register); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1754 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1755 if (!op->is_bound_register()) { |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1756 syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n", |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1757 node->_ident, comp->_type, comp->_name); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1758 } |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1759 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1760 fprintf(fp," kill = "); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6802
diff
changeset
|
1761 fprintf(fp,"new (C) MachProjNode( %s, %d, (%s), Op_%s );\n", |
2254
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1762 machNode, proj_no++, regmask, ideal_type); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1763 fprintf(fp," proj_list.push(kill);\n"); |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1764 } |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1765 } |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1766 } |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1767 |
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
1768 if( !node->expands() && node->_matrule != NULL ) { |
0 | 1769 // Remove duplicated operands and inputs which use the same name. |
1770 // Seach through match operands for the same name usage. | |
1771 uint cur_num_opnds = node->num_opnds(); | |
1772 if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) { | |
1773 Component *comp = NULL; | |
1774 // Build mapping from num_edges to local variables | |
1775 fprintf(fp," unsigned num0 = 0;\n"); | |
1776 for( i = 1; i < cur_num_opnds; i++ ) { | |
6850 | 1777 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();",i,i); |
1778 fprintf(fp, " \t// %s\n", node->opnd_ident(i)); | |
0 | 1779 } |
1780 // Build a mapping from operand index to input edges | |
1781 fprintf(fp," unsigned idx0 = oper_input_base();\n"); | |
1782 for( i = 0; i < cur_num_opnds; i++ ) { | |
1783 fprintf(fp," unsigned idx%d = idx%d + num%d;\n", | |
1784 i+1,i,i); | |
1785 } | |
1786 | |
1787 uint new_num_opnds = 1; | |
1788 node->_components.reset(); | |
1789 // Skip first unique operands. | |
1790 for( i = 1; i < cur_num_opnds; i++ ) { | |
1791 comp = node->_components.iter(); | |
10389 | 1792 if (i != node->unique_opnds_idx(i)) { |
0 | 1793 break; |
1794 } | |
1795 new_num_opnds++; | |
1796 } | |
1797 // Replace not unique operands with next unique operands. | |
1798 for( ; i < cur_num_opnds; i++ ) { | |
1799 comp = node->_components.iter(); | |
10389 | 1800 uint j = node->unique_opnds_idx(i); |
0 | 1801 // unique_opnds_idx(i) is unique if unique_opnds_idx(j) is not unique. |
1802 if( j != node->unique_opnds_idx(j) ) { | |
1803 fprintf(fp," set_opnd_array(%d, opnd_array(%d)->clone(C)); // %s\n", | |
1804 new_num_opnds, i, comp->_name); | |
1805 // delete not unique edges here | |
1806 fprintf(fp," for(unsigned i = 0; i < num%d; i++) {\n", i); | |
1807 fprintf(fp," set_req(i + idx%d, _in[i + idx%d]);\n", new_num_opnds, i); | |
1808 fprintf(fp," }\n"); | |
1809 fprintf(fp," num%d = num%d;\n", new_num_opnds, i); | |
1810 fprintf(fp," idx%d = idx%d + num%d;\n", new_num_opnds+1, new_num_opnds, new_num_opnds); | |
1811 new_num_opnds++; | |
1812 } | |
1813 } | |
1814 // delete the rest of edges | |
1815 fprintf(fp," for(int i = idx%d - 1; i >= (int)idx%d; i--) {\n", cur_num_opnds, new_num_opnds); | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
415
diff
changeset
|
1816 fprintf(fp," del_req(i);\n"); |
0 | 1817 fprintf(fp," }\n"); |
1818 fprintf(fp," _num_opnds = %d;\n", new_num_opnds); | |
785 | 1819 assert(new_num_opnds == node->num_unique_opnds(), "what?"); |
0 | 1820 } |
1821 } | |
1822 | |
2008 | 1823 // If the node is a MachConstantNode, insert the MachConstantBaseNode edge. |
1824 // NOTE: this edge must be the last input (see MachConstantNode::mach_constant_base_node_input). | |
14434
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
1825 // There are nodes that don't use $constantablebase, but still require that it |
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
1826 // is an input to the node. Example: divF_reg_immN, Repl32B_imm on x86_64. |
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
1827 if (node->is_mach_constant() || node->needs_constant_base()) { |
14449
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1828 if (node->is_ideal_call() != Form::invalid_type && |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1829 node->is_ideal_call() != Form::JAVA_LEAF) { |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1830 fprintf(fp, " // MachConstantBaseNode added in matcher.\n"); |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1831 _needs_clone_jvms = true; |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1832 } else { |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1833 fprintf(fp, " add_req(C->mach_constant_base_node());\n"); |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1834 } |
2008 | 1835 } |
1836 | |
14449
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1837 fprintf(fp, "\n"); |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1838 if (node->expands()) { |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1839 fprintf(fp, " return result;\n"); |
0 | 1840 } else { |
14449
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1841 fprintf(fp, " return this;\n"); |
0 | 1842 } |
14449
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1843 fprintf(fp, "}\n"); |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
1844 fprintf(fp, "\n"); |
0 | 1845 } |
1846 | |
1847 | |
1848 //------------------------------Emit Routines---------------------------------- | |
1849 // Special classes and routines for defining node emit routines which output | |
1850 // target specific instruction object encodings. | |
1851 // Define the ___Node::emit() routine | |
1852 // | |
1853 // (1) void ___Node::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { | |
1854 // (2) // ... encoding defined by user | |
1855 // (3) | |
1856 // (4) } | |
1857 // | |
1858 | |
1859 class DefineEmitState { | |
1860 private: | |
1861 enum reloc_format { RELOC_NONE = -1, | |
1862 RELOC_IMMEDIATE = 0, | |
1863 RELOC_DISP = 1, | |
1864 RELOC_CALL_DISP = 2 }; | |
1865 enum literal_status{ LITERAL_NOT_SEEN = 0, | |
1866 LITERAL_SEEN = 1, | |
1867 LITERAL_ACCESSED = 2, | |
1868 LITERAL_OUTPUT = 3 }; | |
1869 // Temporaries that describe current operand | |
1870 bool _cleared; | |
1871 OpClassForm *_opclass; | |
1872 OperandForm *_operand; | |
1873 int _operand_idx; | |
1874 const char *_local_name; | |
1875 const char *_operand_name; | |
1876 bool _doing_disp; | |
1877 bool _doing_constant; | |
1878 Form::DataType _constant_type; | |
1879 DefineEmitState::literal_status _constant_status; | |
1880 DefineEmitState::literal_status _reg_status; | |
1881 bool _doing_emit8; | |
1882 bool _doing_emit_d32; | |
1883 bool _doing_emit_d16; | |
1884 bool _doing_emit_hi; | |
1885 bool _doing_emit_lo; | |
1886 bool _may_reloc; | |
1887 reloc_format _reloc_form; | |
1888 const char * _reloc_type; | |
1889 bool _processing_noninput; | |
1890 | |
1891 NameList _strings_to_emit; | |
1892 | |
1893 // Stable state, set by constructor | |
1894 ArchDesc &_AD; | |
1895 FILE *_fp; | |
1896 EncClass &_encoding; | |
1897 InsEncode &_ins_encode; | |
1898 InstructForm &_inst; | |
1899 | |
1900 public: | |
1901 DefineEmitState(FILE *fp, ArchDesc &AD, EncClass &encoding, | |
1902 InsEncode &ins_encode, InstructForm &inst) | |
1903 : _AD(AD), _fp(fp), _encoding(encoding), _ins_encode(ins_encode), _inst(inst) { | |
1904 clear(); | |
1905 } | |
1906 | |
1907 void clear() { | |
1908 _cleared = true; | |
1909 _opclass = NULL; | |
1910 _operand = NULL; | |
1911 _operand_idx = 0; | |
1912 _local_name = ""; | |
1913 _operand_name = ""; | |
1914 _doing_disp = false; | |
1915 _doing_constant= false; | |
1916 _constant_type = Form::none; | |
1917 _constant_status = LITERAL_NOT_SEEN; | |
1918 _reg_status = LITERAL_NOT_SEEN; | |
1919 _doing_emit8 = false; | |
1920 _doing_emit_d32= false; | |
1921 _doing_emit_d16= false; | |
1922 _doing_emit_hi = false; | |
1923 _doing_emit_lo = false; | |
1924 _may_reloc = false; | |
1925 _reloc_form = RELOC_NONE; | |
1926 _reloc_type = AdlcVMDeps::none_reloc_type(); | |
1927 _strings_to_emit.clear(); | |
1928 } | |
1929 | |
1930 // Track necessary state when identifying a replacement variable | |
6850 | 1931 // @arg rep_var: The formal parameter of the encoding. |
0 | 1932 void update_state(const char *rep_var) { |
1933 // A replacement variable or one of its subfields | |
1934 // Obtain replacement variable from list | |
1935 if ( (*rep_var) != '$' ) { | |
1936 // A replacement variable, '$' prefix | |
1937 // check_rep_var( rep_var ); | |
1938 if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) { | |
1939 // No state needed. | |
1940 assert( _opclass == NULL, | |
1941 "'primary', 'secondary' and 'tertiary' don't follow operand."); | |
2008 | 1942 } |
1943 else if ((strcmp(rep_var, "constanttablebase") == 0) || | |
1944 (strcmp(rep_var, "constantoffset") == 0) || | |
1945 (strcmp(rep_var, "constantaddress") == 0)) { | |
14434
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
1946 if (!(_inst.is_mach_constant() || _inst.needs_constant_base())) { |
2008 | 1947 _AD.syntax_err(_encoding._linenum, |
14434
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
1948 "Replacement variable %s not allowed in instruct %s (only in MachConstantNode or MachCall).\n", |
2008 | 1949 rep_var, _encoding._name); |
1950 } | |
1951 } | |
1952 else { | |
6850 | 1953 // Lookup its position in (formal) parameter list of encoding |
0 | 1954 int param_no = _encoding.rep_var_index(rep_var); |
1955 if ( param_no == -1 ) { | |
1956 _AD.syntax_err( _encoding._linenum, | |
1957 "Replacement variable %s not found in enc_class %s.\n", | |
1958 rep_var, _encoding._name); | |
1959 } | |
1960 | |
1961 // Lookup the corresponding ins_encode parameter | |
6850 | 1962 // This is the argument (actual parameter) to the encoding. |
0 | 1963 const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no); |
1964 if (inst_rep_var == NULL) { | |
1965 _AD.syntax_err( _ins_encode._linenum, | |
1966 "Parameter %s not passed to enc_class %s from instruct %s.\n", | |
1967 rep_var, _encoding._name, _inst._ident); | |
1968 } | |
1969 | |
1970 // Check if instruction's actual parameter is a local name in the instruction | |
1971 const Form *local = _inst._localNames[inst_rep_var]; | |
1972 OpClassForm *opc = (local != NULL) ? local->is_opclass() : NULL; | |
1973 // Note: assert removed to allow constant and symbolic parameters | |
1974 // assert( opc, "replacement variable was not found in local names"); | |
1975 // Lookup the index position iff the replacement variable is a localName | |
1976 int idx = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1; | |
1977 | |
1978 if ( idx != -1 ) { | |
1979 // This is a local in the instruction | |
1980 // Update local state info. | |
1981 _opclass = opc; | |
1982 _operand_idx = idx; | |
1983 _local_name = rep_var; | |
1984 _operand_name = inst_rep_var; | |
1985 | |
1986 // !!!!! | |
1987 // Do not support consecutive operands. | |
1988 assert( _operand == NULL, "Unimplemented()"); | |
1989 _operand = opc->is_operand(); | |
1990 } | |
1991 else if( ADLParser::is_literal_constant(inst_rep_var) ) { | |
1992 // Instruction provided a constant expression | |
1993 // Check later that encoding specifies $$$constant to resolve as constant | |
1994 _constant_status = LITERAL_SEEN; | |
1995 } | |
1996 else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) { | |
1997 // Instruction provided an opcode: "primary", "secondary", "tertiary" | |
1998 // Check later that encoding specifies $$$constant to resolve as constant | |
1999 _constant_status = LITERAL_SEEN; | |
2000 } | |
2001 else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) { | |
2002 // Instruction provided a literal register name for this parameter | |
2003 // Check that encoding specifies $$$reg to resolve.as register. | |
2004 _reg_status = LITERAL_SEEN; | |
2005 } | |
2006 else { | |
2007 // Check for unimplemented functionality before hard failure | |
2008 assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label"); | |
2009 assert( false, "ShouldNotReachHere()"); | |
2010 } | |
2011 } // done checking which operand this is. | |
2012 } else { | |
2013 // | |
2014 // A subfield variable, '$$' prefix | |
2015 // Check for fields that may require relocation information. | |
2016 // Then check that literal register parameters are accessed with 'reg' or 'constant' | |
2017 // | |
2018 if ( strcmp(rep_var,"$disp") == 0 ) { | |
2019 _doing_disp = true; | |
2020 assert( _opclass, "Must use operand or operand class before '$disp'"); | |
2021 if( _operand == NULL ) { | |
2022 // Only have an operand class, generate run-time check for relocation | |
2023 _may_reloc = true; | |
2024 _reloc_form = RELOC_DISP; | |
2025 _reloc_type = AdlcVMDeps::oop_reloc_type(); | |
2026 } else { | |
2027 // Do precise check on operand: is it a ConP or not | |
2028 // | |
2029 // Check interface for value of displacement | |
2030 assert( ( _operand->_interface != NULL ), | |
2031 "$disp can only follow memory interface operand"); | |
2032 MemInterface *mem_interface= _operand->_interface->is_MemInterface(); | |
2033 assert( mem_interface != NULL, | |
2034 "$disp can only follow memory interface operand"); | |
2035 const char *disp = mem_interface->_disp; | |
2036 | |
2037 if( disp != NULL && (*disp == '$') ) { | |
2038 // MemInterface::disp contains a replacement variable, | |
2039 // Check if this matches a ConP | |
2040 // | |
2041 // Lookup replacement variable, in operand's component list | |
2042 const char *rep_var_name = disp + 1; // Skip '$' | |
2043 const Component *comp = _operand->_components.search(rep_var_name); | |
2044 assert( comp != NULL,"Replacement variable not found in components"); | |
2045 const char *type = comp->_type; | |
2046 // Lookup operand form for replacement variable's type | |
2047 const Form *form = _AD.globalNames()[type]; | |
2048 assert( form != NULL, "Replacement variable's type not found"); | |
2049 OperandForm *op = form->is_operand(); | |
2050 assert( op, "Attempting to emit a non-register or non-constant"); | |
2051 // Check if this is a constant | |
2052 if (op->_matrule && op->_matrule->is_base_constant(_AD.globalNames())) { | |
2053 // Check which constant this name maps to: _c0, _c1, ..., _cn | |
2054 // const int idx = _operand.constant_position(_AD.globalNames(), comp); | |
2055 // assert( idx != -1, "Constant component not found in operand"); | |
2056 Form::DataType dtype = op->is_base_constant(_AD.globalNames()); | |
2057 if ( dtype == Form::idealP ) { | |
2058 _may_reloc = true; | |
2059 // No longer true that idealP is always an oop | |
2060 _reloc_form = RELOC_DISP; | |
2061 _reloc_type = AdlcVMDeps::oop_reloc_type(); | |
2062 } | |
2063 } | |
2064 | |
2065 else if( _operand->is_user_name_for_sReg() != Form::none ) { | |
2066 // The only non-constant allowed access to disp is an operand sRegX in a stackSlotX | |
2067 assert( op->ideal_to_sReg_type(type) != Form::none, "StackSlots access displacements using 'sRegs'"); | |
2068 _may_reloc = false; | |
2069 } else { | |
2070 assert( false, "fatal(); Only stackSlots can access a non-constant using 'disp'"); | |
2071 } | |
2072 } | |
2073 } // finished with precise check of operand for relocation. | |
2074 } // finished with subfield variable | |
2075 else if ( strcmp(rep_var,"$constant") == 0 ) { | |
2076 _doing_constant = true; | |
2077 if ( _constant_status == LITERAL_NOT_SEEN ) { | |
2078 // Check operand for type of constant | |
2079 assert( _operand, "Must use operand before '$$constant'"); | |
2080 Form::DataType dtype = _operand->is_base_constant(_AD.globalNames()); | |
2081 _constant_type = dtype; | |
2082 if ( dtype == Form::idealP ) { | |
2083 _may_reloc = true; | |
2084 // No longer true that idealP is always an oop | |
2085 // // _must_reloc = true; | |
2086 _reloc_form = RELOC_IMMEDIATE; | |
2087 _reloc_type = AdlcVMDeps::oop_reloc_type(); | |
2088 } else { | |
2089 // No relocation information needed | |
2090 } | |
2091 } else { | |
2092 // User-provided literals may not require relocation information !!!!! | |
2093 assert( _constant_status == LITERAL_SEEN, "Must know we are processing a user-provided literal"); | |
2094 } | |
2095 } | |
2096 else if ( strcmp(rep_var,"$label") == 0 ) { | |
2097 // Calls containing labels require relocation | |
2098 if ( _inst.is_ideal_call() ) { | |
2099 _may_reloc = true; | |
2100 // !!!!! !!!!! | |
2101 _reloc_type = AdlcVMDeps::none_reloc_type(); | |
2102 } | |
2103 } | |
2104 | |
2105 // literal register parameter must be accessed as a 'reg' field. | |
2106 if ( _reg_status != LITERAL_NOT_SEEN ) { | |
2107 assert( _reg_status == LITERAL_SEEN, "Must have seen register literal before now"); | |
2108 if (strcmp(rep_var,"$reg") == 0 || reg_conversion(rep_var) != NULL) { | |
2109 _reg_status = LITERAL_ACCESSED; | |
2110 } else { | |
14431
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2111 _AD.syntax_err(_encoding._linenum, |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2112 "Invalid access to literal register parameter '%s' in %s.\n", |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2113 rep_var, _encoding._name); |
0 | 2114 assert( false, "invalid access to literal register parameter"); |
2115 } | |
2116 } | |
2117 // literal constant parameters must be accessed as a 'constant' field | |
14431
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2118 if (_constant_status != LITERAL_NOT_SEEN) { |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2119 assert(_constant_status == LITERAL_SEEN, "Must have seen constant literal before now"); |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2120 if (strcmp(rep_var,"$constant") == 0) { |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2121 _constant_status = LITERAL_ACCESSED; |
0 | 2122 } else { |
14431
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2123 _AD.syntax_err(_encoding._linenum, |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2124 "Invalid access to literal constant parameter '%s' in %s.\n", |
1410ad6b05f1
8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents:
14428
diff
changeset
|
2125 rep_var, _encoding._name); |
0 | 2126 } |
2127 } | |
2128 } // end replacement and/or subfield | |
2129 | |
2130 } | |
2131 | |
2132 void add_rep_var(const char *rep_var) { | |
2133 // Handle subfield and replacement variables. | |
2134 if ( ( *rep_var == '$' ) && ( *(rep_var+1) == '$' ) ) { | |
2135 // Check for emit prefix, '$$emit32' | |
2136 assert( _cleared, "Can not nest $$$emit32"); | |
2137 if ( strcmp(rep_var,"$$emit32") == 0 ) { | |
2138 _doing_emit_d32 = true; | |
2139 } | |
2140 else if ( strcmp(rep_var,"$$emit16") == 0 ) { | |
2141 _doing_emit_d16 = true; | |
2142 } | |
2143 else if ( strcmp(rep_var,"$$emit_hi") == 0 ) { | |
2144 _doing_emit_hi = true; | |
2145 } | |
2146 else if ( strcmp(rep_var,"$$emit_lo") == 0 ) { | |
2147 _doing_emit_lo = true; | |
2148 } | |
2149 else if ( strcmp(rep_var,"$$emit8") == 0 ) { | |
2150 _doing_emit8 = true; | |
2151 } | |
2152 else { | |
2153 _AD.syntax_err(_encoding._linenum, "Unsupported $$operation '%s'\n",rep_var); | |
2154 assert( false, "fatal();"); | |
2155 } | |
2156 } | |
2157 else { | |
2158 // Update state for replacement variables | |
2159 update_state( rep_var ); | |
2160 _strings_to_emit.addName(rep_var); | |
2161 } | |
2162 _cleared = false; | |
2163 } | |
2164 | |
2165 void emit_replacement() { | |
2166 // A replacement variable or one of its subfields | |
2167 // Obtain replacement variable from list | |
2168 // const char *ec_rep_var = encoding->_rep_vars.iter(); | |
2169 const char *rep_var; | |
2170 _strings_to_emit.reset(); | |
2171 while ( (rep_var = _strings_to_emit.iter()) != NULL ) { | |
2172 | |
2173 if ( (*rep_var) == '$' ) { | |
2174 // A subfield variable, '$$' prefix | |
2175 emit_field( rep_var ); | |
2176 } else { | |
624 | 2177 if (_strings_to_emit.peek() != NULL && |
2178 strcmp(_strings_to_emit.peek(), "$Address") == 0) { | |
2179 fprintf(_fp, "Address::make_raw("); | |
2180 | |
2181 emit_rep_var( rep_var ); | |
2182 fprintf(_fp,"->base(ra_,this,idx%d), ", _operand_idx); | |
2183 | |
2184 _reg_status = LITERAL_ACCESSED; | |
2185 emit_rep_var( rep_var ); | |
2186 fprintf(_fp,"->index(ra_,this,idx%d), ", _operand_idx); | |
2187 | |
2188 _reg_status = LITERAL_ACCESSED; | |
2189 emit_rep_var( rep_var ); | |
2190 fprintf(_fp,"->scale(), "); | |
2191 | |
2192 _reg_status = LITERAL_ACCESSED; | |
2193 emit_rep_var( rep_var ); | |
2194 Form::DataType stack_type = _operand ? _operand->is_user_name_for_sReg() : Form::none; | |
2195 if( _operand && _operand_idx==0 && stack_type != Form::none ) { | |
2196 fprintf(_fp,"->disp(ra_,this,0), "); | |
2197 } else { | |
2198 fprintf(_fp,"->disp(ra_,this,idx%d), ", _operand_idx); | |
2199 } | |
2200 | |
2201 _reg_status = LITERAL_ACCESSED; | |
2202 emit_rep_var( rep_var ); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2203 fprintf(_fp,"->disp_reloc())"); |
624 | 2204 |
2205 // skip trailing $Address | |
2206 _strings_to_emit.iter(); | |
2207 } else { | |
2208 // A replacement variable, '$' prefix | |
2209 const char* next = _strings_to_emit.peek(); | |
2210 const char* next2 = _strings_to_emit.peek(2); | |
2211 if (next != NULL && next2 != NULL && strcmp(next2, "$Register") == 0 && | |
2212 (strcmp(next, "$base") == 0 || strcmp(next, "$index") == 0)) { | |
2213 // handle $rev_var$$base$$Register and $rev_var$$index$$Register by | |
2214 // producing as_Register(opnd_array(#)->base(ra_,this,idx1)). | |
2215 fprintf(_fp, "as_Register("); | |
2216 // emit the operand reference | |
2217 emit_rep_var( rep_var ); | |
2218 rep_var = _strings_to_emit.iter(); | |
2219 assert(strcmp(rep_var, "$base") == 0 || strcmp(rep_var, "$index") == 0, "bad pattern"); | |
2220 // handle base or index | |
2221 emit_field(rep_var); | |
2222 rep_var = _strings_to_emit.iter(); | |
2223 assert(strcmp(rep_var, "$Register") == 0, "bad pattern"); | |
2224 // close up the parens | |
2225 fprintf(_fp, ")"); | |
2226 } else { | |
2227 emit_rep_var( rep_var ); | |
2228 } | |
2229 } | |
0 | 2230 } // end replacement and/or subfield |
2231 } | |
2232 } | |
2233 | |
2234 void emit_reloc_type(const char* type) { | |
2235 fprintf(_fp, "%s", type) | |
2236 ; | |
2237 } | |
2238 | |
2239 | |
2240 void emit() { | |
2241 // | |
2242 // "emit_d32_reloc(" or "emit_hi_reloc" or "emit_lo_reloc" | |
2243 // | |
2244 // Emit the function name when generating an emit function | |
2245 if ( _doing_emit_d32 || _doing_emit_hi || _doing_emit_lo ) { | |
2246 const char *d32_hi_lo = _doing_emit_d32 ? "d32" : (_doing_emit_hi ? "hi" : "lo"); | |
2247 // In general, relocatable isn't known at compiler compile time. | |
2248 // Check results of prior scan | |
2249 if ( ! _may_reloc ) { | |
2250 // Definitely don't need relocation information | |
2251 fprintf( _fp, "emit_%s(cbuf, ", d32_hi_lo ); | |
2252 emit_replacement(); fprintf(_fp, ")"); | |
2253 } | |
2254 else { | |
2255 // Emit RUNTIME CHECK to see if value needs relocation info | |
2256 // If emitting a relocatable address, use 'emit_d32_reloc' | |
2257 const char *disp_constant = _doing_disp ? "disp" : _doing_constant ? "constant" : "INVALID"; | |
2258 assert( (_doing_disp || _doing_constant) | |
2259 && !(_doing_disp && _doing_constant), | |
2260 "Must be emitting either a displacement or a constant"); | |
2261 fprintf(_fp,"\n"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2262 fprintf(_fp,"if ( opnd_array(%d)->%s_reloc() != relocInfo::none ) {\n", |
0 | 2263 _operand_idx, disp_constant); |
2264 fprintf(_fp," "); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2265 fprintf(_fp,"emit_%s_reloc(cbuf, ", d32_hi_lo ); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2266 emit_replacement(); fprintf(_fp,", "); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2267 fprintf(_fp,"opnd_array(%d)->%s_reloc(), ", |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2268 _operand_idx, disp_constant); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2269 fprintf(_fp, "%d", _reloc_form);fprintf(_fp, ");"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4121
diff
changeset
|
2270 fprintf(_fp,"\n"); |
0 | 2271 fprintf(_fp,"} else {\n"); |
2272 fprintf(_fp," emit_%s(cbuf, ", d32_hi_lo); | |
2273 emit_replacement(); fprintf(_fp, ");\n"); fprintf(_fp,"}"); | |
2274 } | |
2275 } | |
2276 else if ( _doing_emit_d16 ) { | |
2277 // Relocation of 16-bit values is not supported | |
2278 fprintf(_fp,"emit_d16(cbuf, "); | |
2279 emit_replacement(); fprintf(_fp, ")"); | |
2280 // No relocation done for 16-bit values | |
2281 } | |
2282 else if ( _doing_emit8 ) { | |
2283 // Relocation of 8-bit values is not supported | |
2284 fprintf(_fp,"emit_d8(cbuf, "); | |
2285 emit_replacement(); fprintf(_fp, ")"); | |
2286 // No relocation done for 8-bit values | |
2287 } | |
2288 else { | |
2289 // Not an emit# command, just output the replacement string. | |
2290 emit_replacement(); | |
2291 } | |
2292 | |
2293 // Get ready for next state collection. | |
2294 clear(); | |
2295 } | |
2296 | |
2297 private: | |
2298 | |
2299 // recognizes names which represent MacroAssembler register types | |
2300 // and return the conversion function to build them from OptoReg | |
2301 const char* reg_conversion(const char* rep_var) { | |
2302 if (strcmp(rep_var,"$Register") == 0) return "as_Register"; | |
2303 if (strcmp(rep_var,"$FloatRegister") == 0) return "as_FloatRegister"; | |
2304 #if defined(IA32) || defined(AMD64) | |
2305 if (strcmp(rep_var,"$XMMRegister") == 0) return "as_XMMRegister"; | |
2306 #endif | |
14444
492e67693373
8029888: PPC64: (part 219): adl replacement variable CondRegister
goetz
parents:
14434
diff
changeset
|
2307 if (strcmp(rep_var,"$CondRegister") == 0) return "as_ConditionRegister"; |
0 | 2308 return NULL; |
2309 } | |
2310 | |
2311 void emit_field(const char *rep_var) { | |
2312 const char* reg_convert = reg_conversion(rep_var); | |
2313 | |
2314 // A subfield variable, '$$subfield' | |
2315 if ( strcmp(rep_var, "$reg") == 0 || reg_convert != NULL) { | |
2316 // $reg form or the $Register MacroAssembler type conversions | |
2317 assert( _operand_idx != -1, | |
2318 "Must use this subfield after operand"); | |
2319 if( _reg_status == LITERAL_NOT_SEEN ) { | |
2320 if (_processing_noninput) { | |
2321 const Form *local = _inst._localNames[_operand_name]; | |
2322 OperandForm *oper = local->is_operand(); | |
2323 const RegDef* first = oper->get_RegClass()->find_first_elem(); | |
2324 if (reg_convert != NULL) { | |
2325 fprintf(_fp, "%s(%s_enc)", reg_convert, first->_regname); | |
2326 } else { | |
2327 fprintf(_fp, "%s_enc", first->_regname); | |
2328 } | |
2329 } else { | |
2330 fprintf(_fp,"->%s(ra_,this", reg_convert != NULL ? reg_convert : "reg"); | |
2331 // Add parameter for index position, if not result operand | |
2332 if( _operand_idx != 0 ) fprintf(_fp,",idx%d", _operand_idx); | |
2333 fprintf(_fp,")"); | |
6850 | 2334 fprintf(_fp, "/* %s */", _operand_name); |
0 | 2335 } |
2336 } else { | |
2337 assert( _reg_status == LITERAL_OUTPUT, "should have output register literal in emit_rep_var"); | |
2338 // Register literal has already been sent to output file, nothing more needed | |
2339 } | |
2340 } | |
2341 else if ( strcmp(rep_var,"$base") == 0 ) { | |
2342 assert( _operand_idx != -1, | |
2343 "Must use this subfield after operand"); | |
2344 assert( ! _may_reloc, "UnImplemented()"); | |
2345 fprintf(_fp,"->base(ra_,this,idx%d)", _operand_idx); | |
2346 } | |
2347 else if ( strcmp(rep_var,"$index") == 0 ) { | |
2348 assert( _operand_idx != -1, | |
2349 "Must use this subfield after operand"); | |
2350 assert( ! _may_reloc, "UnImplemented()"); | |
2351 fprintf(_fp,"->index(ra_,this,idx%d)", _operand_idx); | |
2352 } | |
2353 else if ( strcmp(rep_var,"$scale") == 0 ) { | |
2354 assert( ! _may_reloc, "UnImplemented()"); | |
2355 fprintf(_fp,"->scale()"); | |
2356 } | |
2357 else if ( strcmp(rep_var,"$cmpcode") == 0 ) { | |
2358 assert( ! _may_reloc, "UnImplemented()"); | |
2359 fprintf(_fp,"->ccode()"); | |
2360 } | |
2361 else if ( strcmp(rep_var,"$constant") == 0 ) { | |
2362 if( _constant_status == LITERAL_NOT_SEEN ) { | |
2363 if ( _constant_type == Form::idealD ) { | |
2364 fprintf(_fp,"->constantD()"); | |
2365 } else if ( _constant_type == Form::idealF ) { | |
2366 fprintf(_fp,"->constantF()"); | |
2367 } else if ( _constant_type == Form::idealL ) { | |
2368 fprintf(_fp,"->constantL()"); | |
2369 } else { | |
2370 fprintf(_fp,"->constant()"); | |
2371 } | |
2372 } else { | |
2373 assert( _constant_status == LITERAL_OUTPUT, "should have output constant literal in emit_rep_var"); | |
6850 | 2374 // Constant literal has already been sent to output file, nothing more needed |
0 | 2375 } |
2376 } | |
2377 else if ( strcmp(rep_var,"$disp") == 0 ) { | |
2378 Form::DataType stack_type = _operand ? _operand->is_user_name_for_sReg() : Form::none; | |
2379 if( _operand && _operand_idx==0 && stack_type != Form::none ) { | |
2380 fprintf(_fp,"->disp(ra_,this,0)"); | |
2381 } else { | |
2382 fprintf(_fp,"->disp(ra_,this,idx%d)", _operand_idx); | |
2383 } | |
2384 } | |
2385 else if ( strcmp(rep_var,"$label") == 0 ) { | |
2386 fprintf(_fp,"->label()"); | |
2387 } | |
2388 else if ( strcmp(rep_var,"$method") == 0 ) { | |
2389 fprintf(_fp,"->method()"); | |
2390 } | |
2391 else { | |
2392 printf("emit_field: %s\n",rep_var); | |
6850 | 2393 globalAD->syntax_err(_inst._linenum, "Unknown replacement variable %s in format statement of %s.", |
2394 rep_var, _inst._ident); | |
0 | 2395 assert( false, "UnImplemented()"); |
2396 } | |
2397 } | |
2398 | |
2399 | |
2400 void emit_rep_var(const char *rep_var) { | |
2401 _processing_noninput = false; | |
2402 // A replacement variable, originally '$' | |
2403 if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) { | |
415
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2404 if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(rep_var) )) { |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2405 // Missing opcode |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2406 _AD.syntax_err( _inst._linenum, |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2407 "Missing $%s opcode definition in %s, used by encoding %s\n", |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2408 rep_var, _inst._ident, _encoding._name); |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2409 } |
0 | 2410 } |
2008 | 2411 else if (strcmp(rep_var, "constanttablebase") == 0) { |
2412 fprintf(_fp, "as_Register(ra_->get_encode(in(mach_constant_base_node_input())))"); | |
2413 } | |
2414 else if (strcmp(rep_var, "constantoffset") == 0) { | |
2415 fprintf(_fp, "constant_offset()"); | |
2416 } | |
2417 else if (strcmp(rep_var, "constantaddress") == 0) { | |
2418 fprintf(_fp, "InternalAddress(__ code()->consts()->start() + constant_offset())"); | |
2419 } | |
0 | 2420 else { |
2421 // Lookup its position in parameter list | |
2422 int param_no = _encoding.rep_var_index(rep_var); | |
2423 if ( param_no == -1 ) { | |
2424 _AD.syntax_err( _encoding._linenum, | |
2425 "Replacement variable %s not found in enc_class %s.\n", | |
2426 rep_var, _encoding._name); | |
2427 } | |
2428 // Lookup the corresponding ins_encode parameter | |
2429 const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no); | |
2430 | |
2431 // Check if instruction's actual parameter is a local name in the instruction | |
2432 const Form *local = _inst._localNames[inst_rep_var]; | |
2433 OpClassForm *opc = (local != NULL) ? local->is_opclass() : NULL; | |
2434 // Note: assert removed to allow constant and symbolic parameters | |
2435 // assert( opc, "replacement variable was not found in local names"); | |
2436 // Lookup the index position iff the replacement variable is a localName | |
2437 int idx = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1; | |
2438 if( idx != -1 ) { | |
2439 if (_inst.is_noninput_operand(idx)) { | |
2440 // This operand isn't a normal input so printing it is done | |
2441 // specially. | |
2442 _processing_noninput = true; | |
2443 } else { | |
2444 // Output the emit code for this operand | |
2445 fprintf(_fp,"opnd_array(%d)",idx); | |
2446 } | |
2447 assert( _operand == opc->is_operand(), | |
2448 "Previous emit $operand does not match current"); | |
2449 } | |
2450 else if( ADLParser::is_literal_constant(inst_rep_var) ) { | |
2451 // else check if it is a constant expression | |
2452 // Removed following assert to allow primitive C types as arguments to encodings | |
2453 // assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter"); | |
2454 fprintf(_fp,"(%s)", inst_rep_var); | |
2455 _constant_status = LITERAL_OUTPUT; | |
2456 } | |
2457 else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) { | |
2458 // else check if "primary", "secondary", "tertiary" | |
2459 assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter"); | |
415
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2460 if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(inst_rep_var) )) { |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2461 // Missing opcode |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2462 _AD.syntax_err( _inst._linenum, |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2463 "Missing $%s opcode definition in %s\n", |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2464 rep_var, _inst._ident); |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2465 |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
196
diff
changeset
|
2466 } |
0 | 2467 _constant_status = LITERAL_OUTPUT; |
2468 } | |
2469 else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) { | |
2470 // Instruction provided a literal register name for this parameter | |
2471 // Check that encoding specifies $$$reg to resolve.as register. | |
2472 assert( _reg_status == LITERAL_ACCESSED, "Must be processing a literal register parameter"); | |
2473 fprintf(_fp,"(%s_enc)", inst_rep_var); | |
2474 _reg_status = LITERAL_OUTPUT; | |
2475 } | |
2476 else { | |
2477 // Check for unimplemented functionality before hard failure | |
2478 assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label"); | |
2479 assert( false, "ShouldNotReachHere()"); | |
2480 } | |
2481 // all done | |
2482 } | |
2483 } | |
2484 | |
2485 }; // end class DefineEmitState | |
2486 | |
2487 | |
2488 void ArchDesc::defineSize(FILE *fp, InstructForm &inst) { | |
2489 | |
2490 //(1) | |
2491 // Output instruction's emit prototype | |
6850 | 2492 fprintf(fp,"uint %sNode::size(PhaseRegAlloc *ra_) const {\n", |
0 | 2493 inst._ident); |
2494 | |
6850 | 2495 fprintf(fp, " assert(VerifyOops || MachNode::size(ra_) <= %s, \"bad fixed size\");\n", inst._size); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
2496 |
0 | 2497 //(2) |
2498 // Print the size | |
6850 | 2499 fprintf(fp, " return (VerifyOops ? MachNode::size(ra_) : %s);\n", inst._size); |
0 | 2500 |
2501 // (3) and (4) | |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2502 fprintf(fp,"}\n\n"); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2503 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2504 |
14459 | 2505 // Emit postalloc expand function. |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2506 void ArchDesc::define_postalloc_expand(FILE *fp, InstructForm &inst) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2507 InsEncode *ins_encode = inst._insencode; |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2508 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2509 // Output instruction's postalloc_expand prototype. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2510 fprintf(fp, "void %sNode::postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_) {\n", |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2511 inst._ident); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2512 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2513 assert((_encode != NULL) && (ins_encode != NULL), "You must define an encode section."); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2514 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2515 // Output each operand's offset into the array of registers. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2516 inst.index_temps(fp, _globalNames); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2517 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2518 // Output variables "unsigned idx_<par_name>", Node *n_<par_name> and "MachOpnd *op_<par_name>" |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2519 // for each parameter <par_name> specified in the encoding. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2520 ins_encode->reset(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2521 const char *ec_name = ins_encode->encode_class_iter(); |
14459 | 2522 assert(ec_name != NULL, "Postalloc expand must specify an encoding."); |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2523 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2524 EncClass *encoding = _encode->encClass(ec_name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2525 if (encoding == NULL) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2526 fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2527 abort(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2528 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2529 if (ins_encode->current_encoding_num_args() != encoding->num_args()) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2530 globalAD->syntax_err(ins_encode->_linenum, "In %s: passing %d arguments to %s but expecting %d", |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2531 inst._ident, ins_encode->current_encoding_num_args(), |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2532 ec_name, encoding->num_args()); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2533 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2534 |
14459 | 2535 fprintf(fp, " // Access to ins and operands for postalloc expand.\n"); |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2536 const int buflen = 2000; |
14459 | 2537 char idxbuf[buflen]; char *ib = idxbuf; idxbuf[0] = '\0'; |
2538 char nbuf [buflen]; char *nb = nbuf; nbuf[0] = '\0'; | |
2539 char opbuf [buflen]; char *ob = opbuf; opbuf[0] = '\0'; | |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2540 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2541 encoding->_parameter_type.reset(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2542 encoding->_parameter_name.reset(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2543 const char *type = encoding->_parameter_type.iter(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2544 const char *name = encoding->_parameter_name.iter(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2545 int param_no = 0; |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2546 for (; (type != NULL) && (name != NULL); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2547 (type = encoding->_parameter_type.iter()), (name = encoding->_parameter_name.iter())) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2548 const char* arg_name = ins_encode->rep_var_name(inst, param_no); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2549 int idx = inst.operand_position_format(arg_name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2550 if (strcmp(arg_name, "constanttablebase") == 0) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2551 ib += sprintf(ib, " unsigned idx_%-5s = mach_constant_base_node_input(); \t// %s, \t%s\n", |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2552 name, type, arg_name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2553 nb += sprintf(nb, " Node *n_%-7s = lookup(idx_%s);\n", name, name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2554 // There is no operand for the constanttablebase. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2555 } else if (inst.is_noninput_operand(idx)) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2556 globalAD->syntax_err(inst._linenum, |
14459 | 2557 "In %s: you can not pass the non-input %s to a postalloc expand encoding.\n", |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2558 inst._ident, arg_name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2559 } else { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2560 ib += sprintf(ib, " unsigned idx_%-5s = idx%d; \t// %s, \t%s\n", |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2561 name, idx, type, arg_name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2562 nb += sprintf(nb, " Node *n_%-7s = lookup(idx_%s);\n", name, name); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2563 ob += sprintf(ob, " %sOper *op_%s = (%sOper *)opnd_array(%d);\n", type, name, type, idx); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2564 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2565 param_no++; |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2566 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2567 assert(ib < &idxbuf[buflen-1] && nb < &nbuf[buflen-1] && ob < &opbuf[buflen-1], "buffer overflow"); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2568 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2569 fprintf(fp, "%s", idxbuf); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2570 fprintf(fp, " Node *n_region = lookup(0);\n"); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2571 fprintf(fp, "%s%s", nbuf, opbuf); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2572 fprintf(fp, " Compile *C = ra_->C;\n"); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2573 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2574 // Output this instruction's encodings. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2575 fprintf(fp, " {"); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2576 const char *ec_code = NULL; |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2577 const char *ec_rep_var = NULL; |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2578 assert(encoding == _encode->encClass(ec_name), ""); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2579 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2580 DefineEmitState pending(fp, *this, *encoding, *ins_encode, inst); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2581 encoding->_code.reset(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2582 encoding->_rep_vars.reset(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2583 // Process list of user-defined strings, |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2584 // and occurrences of replacement variables. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2585 // Replacement Vars are pushed into a list and then output. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2586 while ((ec_code = encoding->_code.iter()) != NULL) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2587 if (! encoding->_code.is_signal(ec_code)) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2588 // Emit pending code. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2589 pending.emit(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2590 pending.clear(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2591 // Emit this code section. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2592 fprintf(fp, "%s", ec_code); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2593 } else { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2594 // A replacement variable or one of its subfields. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2595 // Obtain replacement variable from list. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2596 ec_rep_var = encoding->_rep_vars.iter(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2597 pending.add_rep_var(ec_rep_var); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2598 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2599 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2600 // Emit pending code. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2601 pending.emit(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2602 pending.clear(); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2603 fprintf(fp, " }\n"); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2604 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2605 fprintf(fp, "}\n\n"); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2606 |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2607 ec_name = ins_encode->encode_class_iter(); |
14459 | 2608 assert(ec_name == NULL, "Postalloc expand may only have one encoding."); |
0 | 2609 } |
2610 | |
2008 | 2611 // defineEmit ----------------------------------------------------------------- |
2612 void ArchDesc::defineEmit(FILE* fp, InstructForm& inst) { | |
2613 InsEncode* encode = inst._insencode; | |
0 | 2614 |
2615 // (1) | |
2616 // Output instruction's emit prototype | |
2008 | 2617 fprintf(fp, "void %sNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {\n", inst._ident); |
0 | 2618 |
2619 // If user did not define an encode section, | |
2620 // provide stub that does not generate any machine code. | |
2008 | 2621 if( (_encode == NULL) || (encode == NULL) ) { |
0 | 2622 fprintf(fp, " // User did not define an encode section.\n"); |
2008 | 2623 fprintf(fp, "}\n"); |
0 | 2624 return; |
2625 } | |
2626 | |
2627 // Save current instruction's starting address (helps with relocation). | |
2008 | 2628 fprintf(fp, " cbuf.set_insts_mark();\n"); |
2629 | |
2630 // For MachConstantNodes which are ideal jump nodes, fill the jump table. | |
2631 if (inst.is_mach_constant() && inst.is_ideal_jump()) { | |
2632 fprintf(fp, " ra_->C->constant_table().fill_jump_table(cbuf, (MachConstantNode*) this, _index2label);\n"); | |
2633 } | |
0 | 2634 |
2635 // Output each operand's offset into the array of registers. | |
2008 | 2636 inst.index_temps(fp, _globalNames); |
0 | 2637 |
2638 // Output this instruction's encodings | |
2639 const char *ec_name; | |
2640 bool user_defined = false; | |
2008 | 2641 encode->reset(); |
2642 while ((ec_name = encode->encode_class_iter()) != NULL) { | |
2643 fprintf(fp, " {\n"); | |
0 | 2644 // Output user-defined encoding |
2645 user_defined = true; | |
2646 | |
2647 const char *ec_code = NULL; | |
2648 const char *ec_rep_var = NULL; | |
2649 EncClass *encoding = _encode->encClass(ec_name); | |
2650 if (encoding == NULL) { | |
2651 fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name); | |
2652 abort(); | |
2653 } | |
2654 | |
2008 | 2655 if (encode->current_encoding_num_args() != encoding->num_args()) { |
2656 globalAD->syntax_err(encode->_linenum, "In %s: passing %d arguments to %s but expecting %d", | |
2657 inst._ident, encode->current_encoding_num_args(), | |
0 | 2658 ec_name, encoding->num_args()); |
2659 } | |
2660 | |
2008 | 2661 DefineEmitState pending(fp, *this, *encoding, *encode, inst); |
0 | 2662 encoding->_code.reset(); |
2663 encoding->_rep_vars.reset(); | |
2664 // Process list of user-defined strings, | |
2665 // and occurrences of replacement variables. | |
2666 // Replacement Vars are pushed into a list and then output | |
2008 | 2667 while ((ec_code = encoding->_code.iter()) != NULL) { |
2668 if (!encoding->_code.is_signal(ec_code)) { | |
0 | 2669 // Emit pending code |
2670 pending.emit(); | |
2671 pending.clear(); | |
2672 // Emit this code section | |
2008 | 2673 fprintf(fp, "%s", ec_code); |
0 | 2674 } else { |
2675 // A replacement variable or one of its subfields | |
2676 // Obtain replacement variable from list | |
2677 ec_rep_var = encoding->_rep_vars.iter(); | |
2678 pending.add_rep_var(ec_rep_var); | |
2679 } | |
2680 } | |
2681 // Emit pending code | |
2682 pending.emit(); | |
2683 pending.clear(); | |
2008 | 2684 fprintf(fp, " }\n"); |
0 | 2685 } // end while instruction's encodings |
2686 | |
2687 // Check if user stated which encoding to user | |
2688 if ( user_defined == false ) { | |
2689 fprintf(fp, " // User did not define which encode class to use.\n"); | |
2690 } | |
2691 | |
2692 // (3) and (4) | |
6850 | 2693 fprintf(fp, "}\n\n"); |
2008 | 2694 } |
2695 | |
2696 // defineEvalConstant --------------------------------------------------------- | |
2697 void ArchDesc::defineEvalConstant(FILE* fp, InstructForm& inst) { | |
2698 InsEncode* encode = inst._constant; | |
2699 | |
2700 // (1) | |
2701 // Output instruction's emit prototype | |
2702 fprintf(fp, "void %sNode::eval_constant(Compile* C) {\n", inst._ident); | |
2703 | |
4114
6729bbc1fcd6
7003454: order constants in constant table by number of references in code
twisti
parents:
3853
diff
changeset
|
2704 // For ideal jump nodes, add a jump-table entry. |
2008 | 2705 if (inst.is_ideal_jump()) { |
4114
6729bbc1fcd6
7003454: order constants in constant table by number of references in code
twisti
parents:
3853
diff
changeset
|
2706 fprintf(fp, " _constant = C->constant_table().add_jump_table(this);\n"); |
2008 | 2707 } |
2708 | |
2709 // If user did not define an encode section, | |
2710 // provide stub that does not generate any machine code. | |
2711 if ((_encode == NULL) || (encode == NULL)) { | |
2712 fprintf(fp, " // User did not define an encode section.\n"); | |
2713 fprintf(fp, "}\n"); | |
2714 return; | |
2715 } | |
2716 | |
2717 // Output this instruction's encodings | |
2718 const char *ec_name; | |
2719 bool user_defined = false; | |
2720 encode->reset(); | |
2721 while ((ec_name = encode->encode_class_iter()) != NULL) { | |
2722 fprintf(fp, " {\n"); | |
2723 // Output user-defined encoding | |
2724 user_defined = true; | |
2725 | |
2726 const char *ec_code = NULL; | |
2727 const char *ec_rep_var = NULL; | |
2728 EncClass *encoding = _encode->encClass(ec_name); | |
2729 if (encoding == NULL) { | |
2730 fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name); | |
2731 abort(); | |
2732 } | |
2733 | |
2734 if (encode->current_encoding_num_args() != encoding->num_args()) { | |
2735 globalAD->syntax_err(encode->_linenum, "In %s: passing %d arguments to %s but expecting %d", | |
2736 inst._ident, encode->current_encoding_num_args(), | |
2737 ec_name, encoding->num_args()); | |
2738 } | |
2739 | |
2740 DefineEmitState pending(fp, *this, *encoding, *encode, inst); | |
2741 encoding->_code.reset(); | |
2742 encoding->_rep_vars.reset(); | |
2743 // Process list of user-defined strings, | |
2744 // and occurrences of replacement variables. | |
2745 // Replacement Vars are pushed into a list and then output | |
2746 while ((ec_code = encoding->_code.iter()) != NULL) { | |
2747 if (!encoding->_code.is_signal(ec_code)) { | |
2748 // Emit pending code | |
2749 pending.emit(); | |
2750 pending.clear(); | |
2751 // Emit this code section | |
2752 fprintf(fp, "%s", ec_code); | |
2753 } else { | |
2754 // A replacement variable or one of its subfields | |
2755 // Obtain replacement variable from list | |
2756 ec_rep_var = encoding->_rep_vars.iter(); | |
2757 pending.add_rep_var(ec_rep_var); | |
2758 } | |
2759 } | |
2760 // Emit pending code | |
2761 pending.emit(); | |
2762 pending.clear(); | |
2763 fprintf(fp, " }\n"); | |
2764 } // end while instruction's encodings | |
2765 | |
2766 // Check if user stated which encoding to user | |
2767 if (user_defined == false) { | |
2768 fprintf(fp, " // User did not define which encode class to use.\n"); | |
2769 } | |
2770 | |
2771 // (3) and (4) | |
2772 fprintf(fp, "}\n"); | |
0 | 2773 } |
2774 | |
2775 // --------------------------------------------------------------------------- | |
2776 //--------Utilities to build MachOper and MachNode derived Classes------------ | |
2777 // --------------------------------------------------------------------------- | |
2778 | |
2779 //------------------------------Utilities to build Operand Classes------------ | |
2780 static void defineIn_RegMask(FILE *fp, FormDict &globals, OperandForm &oper) { | |
2781 uint num_edges = oper.num_edges(globals); | |
2782 if( num_edges != 0 ) { | |
2783 // Method header | |
2784 fprintf(fp, "const RegMask *%sOper::in_RegMask(int index) const {\n", | |
2785 oper._ident); | |
2786 | |
2787 // Assert that the index is in range. | |
2788 fprintf(fp, " assert(0 <= index && index < %d, \"index out of range\");\n", | |
2789 num_edges); | |
2790 | |
2791 // Figure out if all RegMasks are the same. | |
2792 const char* first_reg_class = oper.in_reg_class(0, globals); | |
2793 bool all_same = true; | |
2794 assert(first_reg_class != NULL, "did not find register mask"); | |
2795 | |
2796 for (uint index = 1; all_same && index < num_edges; index++) { | |
2797 const char* some_reg_class = oper.in_reg_class(index, globals); | |
2798 assert(some_reg_class != NULL, "did not find register mask"); | |
2799 if (strcmp(first_reg_class, some_reg_class) != 0) { | |
2800 all_same = false; | |
2801 } | |
2802 } | |
2803 | |
2804 if (all_same) { | |
2805 // Return the sole RegMask. | |
2806 if (strcmp(first_reg_class, "stack_slots") == 0) { | |
2807 fprintf(fp," return &(Compile::current()->FIRST_STACK_mask());\n"); | |
2808 } else { | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
2809 const char* first_reg_class_to_upper = toUpper(first_reg_class); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
2810 fprintf(fp," return &%s_mask();\n", first_reg_class_to_upper); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
2811 delete[] first_reg_class_to_upper; |
0 | 2812 } |
2813 } else { | |
2814 // Build a switch statement to return the desired mask. | |
2815 fprintf(fp," switch (index) {\n"); | |
2816 | |
2817 for (uint index = 0; index < num_edges; index++) { | |
2818 const char *reg_class = oper.in_reg_class(index, globals); | |
2819 assert(reg_class != NULL, "did not find register mask"); | |
2820 if( !strcmp(reg_class, "stack_slots") ) { | |
2821 fprintf(fp, " case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index); | |
2822 } else { | |
9078
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
2823 const char* reg_class_to_upper = toUpper(reg_class); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
2824 fprintf(fp, " case %d: return &%s_mask();\n", index, reg_class_to_upper); |
705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents:
6850
diff
changeset
|
2825 delete[] reg_class_to_upper; |
0 | 2826 } |
2827 } | |
2828 fprintf(fp," }\n"); | |
2829 fprintf(fp," ShouldNotReachHere();\n"); | |
2830 fprintf(fp," return NULL;\n"); | |
2831 } | |
2832 | |
2833 // Method close | |
2834 fprintf(fp, "}\n\n"); | |
2835 } | |
2836 } | |
2837 | |
2838 // generate code to create a clone for a class derived from MachOper | |
2839 // | |
2840 // (0) MachOper *MachOperXOper::clone(Compile* C) const { | |
2841 // (1) return new (C) MachXOper( _ccode, _c0, _c1, ..., _cn); | |
2842 // (2) } | |
2843 // | |
2844 static void defineClone(FILE *fp, FormDict &globalNames, OperandForm &oper) { | |
6850 | 2845 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper._ident); |
0 | 2846 // Check for constants that need to be copied over |
2847 const int num_consts = oper.num_consts(globalNames); | |
2848 const bool is_ideal_bool = oper.is_ideal_bool(); | |
2849 if( (num_consts > 0) ) { | |
6850 | 2850 fprintf(fp," return new (C) %sOper(", oper._ident); |
0 | 2851 // generate parameters for constants |
2852 int i = 0; | |
2853 fprintf(fp,"_c%d", i); | |
2854 for( i = 1; i < num_consts; ++i) { | |
2855 fprintf(fp,", _c%d", i); | |
2856 } | |
2857 // finish line (1) | |
2858 fprintf(fp,");\n"); | |
2859 } | |
2860 else { | |
2861 assert( num_consts == 0, "Currently support zero or one constant per operand clone function"); | |
6850 | 2862 fprintf(fp," return new (C) %sOper();\n", oper._ident); |
0 | 2863 } |
2864 // finish method | |
2865 fprintf(fp,"}\n"); | |
2866 } | |
2867 | |
2868 // Helper functions for bug 4796752, abstracted with minimal modification | |
2869 // from define_oper_interface() | |
2870 OperandForm *rep_var_to_operand(const char *encoding, OperandForm &oper, FormDict &globals) { | |
2871 OperandForm *op = NULL; | |
2872 // Check for replacement variable | |
2873 if( *encoding == '$' ) { | |
2874 // Replacement variable | |
2875 const char *rep_var = encoding + 1; | |
2876 // Lookup replacement variable, rep_var, in operand's component list | |
2877 const Component *comp = oper._components.search(rep_var); | |
2878 assert( comp != NULL, "Replacement variable not found in components"); | |
2879 // Lookup operand form for replacement variable's type | |
2880 const char *type = comp->_type; | |
2881 Form *form = (Form*)globals[type]; | |
2882 assert( form != NULL, "Replacement variable's type not found"); | |
2883 op = form->is_operand(); | |
2884 assert( op, "Attempting to emit a non-register or non-constant"); | |
2885 } | |
2886 | |
2887 return op; | |
2888 } | |
2889 | |
2890 int rep_var_to_constant_index(const char *encoding, OperandForm &oper, FormDict &globals) { | |
2891 int idx = -1; | |
2892 // Check for replacement variable | |
2893 if( *encoding == '$' ) { | |
2894 // Replacement variable | |
2895 const char *rep_var = encoding + 1; | |
2896 // Lookup replacement variable, rep_var, in operand's component list | |
2897 const Component *comp = oper._components.search(rep_var); | |
2898 assert( comp != NULL, "Replacement variable not found in components"); | |
2899 // Lookup operand form for replacement variable's type | |
2900 const char *type = comp->_type; | |
2901 Form *form = (Form*)globals[type]; | |
2902 assert( form != NULL, "Replacement variable's type not found"); | |
2903 OperandForm *op = form->is_operand(); | |
2904 assert( op, "Attempting to emit a non-register or non-constant"); | |
2905 // Check that this is a constant and find constant's index: | |
2906 if (op->_matrule && op->_matrule->is_base_constant(globals)) { | |
2907 idx = oper.constant_position(globals, comp); | |
2908 } | |
2909 } | |
2910 | |
2911 return idx; | |
2912 } | |
2913 | |
2914 bool is_regI(const char *encoding, OperandForm &oper, FormDict &globals ) { | |
2915 bool is_regI = false; | |
2916 | |
2917 OperandForm *op = rep_var_to_operand(encoding, oper, globals); | |
2918 if( op != NULL ) { | |
2919 // Check that this is a register | |
2920 if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) { | |
2921 // Register | |
2922 const char* ideal = op->ideal_type(globals); | |
2923 is_regI = (ideal && (op->ideal_to_Reg_type(ideal) == Form::idealI)); | |
2924 } | |
2925 } | |
2926 | |
2927 return is_regI; | |
2928 } | |
2929 | |
2930 bool is_conP(const char *encoding, OperandForm &oper, FormDict &globals ) { | |
2931 bool is_conP = false; | |
2932 | |
2933 OperandForm *op = rep_var_to_operand(encoding, oper, globals); | |
2934 if( op != NULL ) { | |
2935 // Check that this is a constant pointer | |
2936 if (op->_matrule && op->_matrule->is_base_constant(globals)) { | |
2937 // Constant | |
2938 Form::DataType dtype = op->is_base_constant(globals); | |
2939 is_conP = (dtype == Form::idealP); | |
2940 } | |
2941 } | |
2942 | |
2943 return is_conP; | |
2944 } | |
2945 | |
2946 | |
2947 // Define a MachOper interface methods | |
2948 void ArchDesc::define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals, | |
2949 const char *name, const char *encoding) { | |
2950 bool emit_position = false; | |
2951 int position = -1; | |
2952 | |
2953 fprintf(fp," virtual int %s", name); | |
2954 // Generate access method for base, index, scale, disp, ... | |
2955 if( (strcmp(name,"base") == 0) || (strcmp(name,"index") == 0) ) { | |
2956 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n"); | |
2957 emit_position = true; | |
2958 } else if ( (strcmp(name,"disp") == 0) ) { | |
2959 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n"); | |
2960 } else { | |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
2961 fprintf(fp, "() const {\n"); |
0 | 2962 } |
2963 | |
2964 // Check for hexadecimal value OR replacement variable | |
2965 if( *encoding == '$' ) { | |
2966 // Replacement variable | |
2967 const char *rep_var = encoding + 1; | |
6850 | 2968 fprintf(fp," // Replacement variable: %s\n", encoding+1); |
0 | 2969 // Lookup replacement variable, rep_var, in operand's component list |
2970 const Component *comp = oper._components.search(rep_var); | |
2971 assert( comp != NULL, "Replacement variable not found in components"); | |
2972 // Lookup operand form for replacement variable's type | |
2973 const char *type = comp->_type; | |
2974 Form *form = (Form*)globals[type]; | |
2975 assert( form != NULL, "Replacement variable's type not found"); | |
2976 OperandForm *op = form->is_operand(); | |
2977 assert( op, "Attempting to emit a non-register or non-constant"); | |
2978 // Check that this is a register or a constant and generate code: | |
2979 if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) { | |
2980 // Register | |
2981 int idx_offset = oper.register_position( globals, rep_var); | |
2982 position = idx_offset; | |
2983 fprintf(fp," return (int)ra_->get_encode(node->in(idx"); | |
2984 if ( idx_offset > 0 ) fprintf(fp, "+%d",idx_offset); | |
2985 fprintf(fp,"));\n"); | |
2986 } else if ( op->ideal_to_sReg_type(op->_ident) != Form::none ) { | |
2987 // StackSlot for an sReg comes either from input node or from self, when idx==0 | |
2988 fprintf(fp," if( idx != 0 ) {\n"); | |
6850 | 2989 fprintf(fp," // Access stack offset (register number) for input operand\n"); |
0 | 2990 fprintf(fp," return ra_->reg2offset(ra_->get_reg_first(node->in(idx)));/* sReg */\n"); |
2991 fprintf(fp," }\n"); | |
6850 | 2992 fprintf(fp," // Access stack offset (register number) from myself\n"); |
0 | 2993 fprintf(fp," return ra_->reg2offset(ra_->get_reg_first(node));/* sReg */\n"); |
2994 } else if (op->_matrule && op->_matrule->is_base_constant(globals)) { | |
2995 // Constant | |
2996 // Check which constant this name maps to: _c0, _c1, ..., _cn | |
2997 const int idx = oper.constant_position(globals, comp); | |
2998 assert( idx != -1, "Constant component not found in operand"); | |
2999 // Output code for this constant, type dependent. | |
3000 fprintf(fp," return (int)" ); | |
3001 oper.access_constant(fp, globals, (uint)idx /* , const_type */); | |
3002 fprintf(fp,";\n"); | |
3003 } else { | |
3004 assert( false, "Attempting to emit a non-register or non-constant"); | |
3005 } | |
3006 } | |
3007 else if( *encoding == '0' && *(encoding+1) == 'x' ) { | |
3008 // Hex value | |
6850 | 3009 fprintf(fp," return %s;\n", encoding); |
0 | 3010 } else { |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3011 globalAD->syntax_err(oper._linenum, "In operand %s: Do not support this encode constant: '%s' for %s.", |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3012 oper._ident, encoding, name); |
0 | 3013 assert( false, "Do not support octal or decimal encode constants"); |
3014 } | |
3015 fprintf(fp," }\n"); | |
3016 | |
3017 if( emit_position && (position != -1) && (oper.num_edges(globals) > 0) ) { | |
3018 fprintf(fp," virtual int %s_position() const { return %d; }\n", name, position); | |
3019 MemInterface *mem_interface = oper._interface->is_MemInterface(); | |
3020 const char *base = mem_interface->_base; | |
3021 const char *disp = mem_interface->_disp; | |
3022 if( emit_position && (strcmp(name,"base") == 0) | |
3023 && base != NULL && is_regI(base, oper, globals) | |
3024 && disp != NULL && is_conP(disp, oper, globals) ) { | |
3025 // Found a memory access using a constant pointer for a displacement | |
3026 // and a base register containing an integer offset. | |
3027 // In this case the base and disp are reversed with respect to what | |
3028 // is expected by MachNode::get_base_and_disp() and MachNode::adr_type(). | |
3029 // Provide a non-NULL return for disp_as_type() that will allow adr_type() | |
3030 // to correctly compute the access type for alias analysis. | |
3031 // | |
3032 // See BugId 4796752, operand indOffset32X in i486.ad | |
3033 int idx = rep_var_to_constant_index(disp, oper, globals); | |
3034 fprintf(fp," virtual const TypePtr *disp_as_type() const { return _c%d; }\n", idx); | |
3035 } | |
3036 } | |
3037 } | |
3038 | |
3039 // | |
3040 // Construct the method to copy _idx, inputs and operands to new node. | |
3041 static void define_fill_new_machnode(bool used, FILE *fp_cpp) { | |
3042 fprintf(fp_cpp, "\n"); | |
3043 fprintf(fp_cpp, "// Copy _idx, inputs and operands to new node\n"); | |
3044 fprintf(fp_cpp, "void MachNode::fill_new_machnode( MachNode* node, Compile* C) const {\n"); | |
3045 if( !used ) { | |
3046 fprintf(fp_cpp, " // This architecture does not have cisc or short branch instructions\n"); | |
3047 fprintf(fp_cpp, " ShouldNotCallThis();\n"); | |
3048 fprintf(fp_cpp, "}\n"); | |
3049 } else { | |
3050 // New node must use same node index for access through allocator's tables | |
3051 fprintf(fp_cpp, " // New node must use same node index\n"); | |
3052 fprintf(fp_cpp, " node->set_idx( _idx );\n"); | |
3053 // Copy machine-independent inputs | |
3054 fprintf(fp_cpp, " // Copy machine-independent inputs\n"); | |
3055 fprintf(fp_cpp, " for( uint j = 0; j < req(); j++ ) {\n"); | |
3056 fprintf(fp_cpp, " node->add_req(in(j));\n"); | |
3057 fprintf(fp_cpp, " }\n"); | |
3058 // Copy machine operands to new MachNode | |
3059 fprintf(fp_cpp, " // Copy my operands, except for cisc position\n"); | |
3060 fprintf(fp_cpp, " int nopnds = num_opnds();\n"); | |
3061 fprintf(fp_cpp, " assert( node->num_opnds() == (uint)nopnds, \"Must have same number of operands\");\n"); | |
3062 fprintf(fp_cpp, " MachOper **to = node->_opnds;\n"); | |
3063 fprintf(fp_cpp, " for( int i = 0; i < nopnds; i++ ) {\n"); | |
3064 fprintf(fp_cpp, " if( i != cisc_operand() ) \n"); | |
3065 fprintf(fp_cpp, " to[i] = _opnds[i]->clone(C);\n"); | |
3066 fprintf(fp_cpp, " }\n"); | |
3067 fprintf(fp_cpp, "}\n"); | |
3068 } | |
3069 fprintf(fp_cpp, "\n"); | |
3070 } | |
3071 | |
3072 //------------------------------defineClasses---------------------------------- | |
3073 // Define members of MachNode and MachOper classes based on | |
3074 // operand and instruction lists | |
3075 void ArchDesc::defineClasses(FILE *fp) { | |
3076 | |
3077 // Define the contents of an array containing the machine register names | |
3078 defineRegNames(fp, _register); | |
3079 // Define an array containing the machine register encoding values | |
3080 defineRegEncodes(fp, _register); | |
3081 // Generate an enumeration of user-defined register classes | |
3082 // and a list of register masks, one for each class. | |
3083 // Only define the RegMask value objects in the expand file. | |
3084 // Declare each as an extern const RegMask ...; in ad_<arch>.hpp | |
3085 declare_register_masks(_HPP_file._fp); | |
3086 // build_register_masks(fp); | |
3087 build_register_masks(_CPP_EXPAND_file._fp); | |
3088 // Define the pipe_classes | |
3089 build_pipe_classes(_CPP_PIPELINE_file._fp); | |
3090 | |
3091 // Generate Machine Classes for each operand defined in AD file | |
3092 fprintf(fp,"\n"); | |
3093 fprintf(fp,"\n"); | |
3094 fprintf(fp,"//------------------Define classes derived from MachOper---------------------\n"); | |
3095 // Iterate through all operands | |
3096 _operands.reset(); | |
3097 OperandForm *oper; | |
3098 for( ; (oper = (OperandForm*)_operands.iter()) != NULL; ) { | |
3099 // Ensure this is a machine-world instruction | |
3100 if ( oper->ideal_only() ) continue; | |
3101 // !!!!! | |
3102 // The declaration of labelOper is in machine-independent file: machnode | |
3103 if ( strcmp(oper->_ident,"label") == 0 ) { | |
3104 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper); | |
3105 | |
3106 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident); | |
3107 fprintf(fp," return new (C) %sOper(_label, _block_num);\n", oper->_ident); | |
3108 fprintf(fp,"}\n"); | |
3109 | |
3110 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n", | |
3111 oper->_ident, machOperEnum(oper->_ident)); | |
3112 // // Currently all XXXOper::Hash() methods are identical (990820) | |
3113 // define_hash(fp, oper->_ident); | |
3114 // // Currently all XXXOper::Cmp() methods are identical (990820) | |
3115 // define_cmp(fp, oper->_ident); | |
3116 fprintf(fp,"\n"); | |
3117 | |
3118 continue; | |
3119 } | |
3120 | |
3121 // The declaration of methodOper is in machine-independent file: machnode | |
3122 if ( strcmp(oper->_ident,"method") == 0 ) { | |
3123 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper); | |
3124 | |
3125 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident); | |
3126 fprintf(fp," return new (C) %sOper(_method);\n", oper->_ident); | |
3127 fprintf(fp,"}\n"); | |
3128 | |
3129 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n", | |
3130 oper->_ident, machOperEnum(oper->_ident)); | |
3131 // // Currently all XXXOper::Hash() methods are identical (990820) | |
3132 // define_hash(fp, oper->_ident); | |
3133 // // Currently all XXXOper::Cmp() methods are identical (990820) | |
3134 // define_cmp(fp, oper->_ident); | |
3135 fprintf(fp,"\n"); | |
3136 | |
3137 continue; | |
3138 } | |
3139 | |
3140 defineIn_RegMask(fp, _globalNames, *oper); | |
3141 defineClone(_CPP_CLONE_file._fp, _globalNames, *oper); | |
3142 // // Currently all XXXOper::Hash() methods are identical (990820) | |
3143 // define_hash(fp, oper->_ident); | |
3144 // // Currently all XXXOper::Cmp() methods are identical (990820) | |
3145 // define_cmp(fp, oper->_ident); | |
3146 | |
3147 // side-call to generate output that used to be in the header file: | |
3148 extern void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file); | |
3149 gen_oper_format(_CPP_FORMAT_file._fp, _globalNames, *oper, true); | |
3150 | |
3151 } | |
3152 | |
3153 | |
3154 // Generate Machine Classes for each instruction defined in AD file | |
3155 fprintf(fp,"//------------------Define members for classes derived from MachNode----------\n"); | |
3156 // Output the definitions for out_RegMask() // & kill_RegMask() | |
3157 _instructions.reset(); | |
3158 InstructForm *instr; | |
3159 MachNodeForm *machnode; | |
3160 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3161 // Ensure this is a machine-world instruction | |
3162 if ( instr->ideal_only() ) continue; | |
3163 | |
3164 defineOut_RegMask(_CPP_MISC_file._fp, instr->_ident, reg_mask(*instr)); | |
3165 } | |
3166 | |
3167 bool used = false; | |
3168 // Output the definitions for expand rules & peephole rules | |
3169 _instructions.reset(); | |
3170 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3171 // Ensure this is a machine-world instruction | |
3172 if ( instr->ideal_only() ) continue; | |
3173 // If there are multiple defs/kills, or an explicit expand rule, build rule | |
3174 if( instr->expands() || instr->needs_projections() || | |
3175 instr->has_temps() || | |
2008 | 3176 instr->is_mach_constant() || |
14434
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
3177 instr->needs_constant_base() || |
0 | 3178 instr->_matrule != NULL && |
3179 instr->num_opnds() != instr->num_unique_opnds() ) | |
3180 defineExpand(_CPP_EXPAND_file._fp, instr); | |
3181 // If there is an explicit peephole rule, build it | |
3182 if ( instr->peepholes() ) | |
3183 definePeephole(_CPP_PEEPHOLE_file._fp, instr); | |
3184 | |
3185 // Output code to convert to the cisc version, if applicable | |
3186 used |= instr->define_cisc_version(*this, fp); | |
3187 | |
3188 // Output code to convert to the short branch version, if applicable | |
1541
b5fdf39b9749
6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents:
1489
diff
changeset
|
3189 used |= instr->define_short_branch_methods(*this, fp); |
0 | 3190 } |
3191 | |
3192 // Construct the method called by cisc_version() to copy inputs and operands. | |
3193 define_fill_new_machnode(used, fp); | |
3194 | |
3195 // Output the definitions for labels | |
3196 _instructions.reset(); | |
3197 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { | |
3198 // Ensure this is a machine-world instruction | |
3199 if ( instr->ideal_only() ) continue; | |
3200 | |
3201 // Access the fields for operand Label | |
3202 int label_position = instr->label_position(); | |
3203 if( label_position != -1 ) { | |
3204 // Set the label | |
3839 | 3205 fprintf(fp,"void %sNode::label_set( Label* label, uint block_num ) {\n", instr->_ident); |
0 | 3206 fprintf(fp," labelOper* oper = (labelOper*)(opnd_array(%d));\n", |
3207 label_position ); | |
3839 | 3208 fprintf(fp," oper->_label = label;\n"); |
0 | 3209 fprintf(fp," oper->_block_num = block_num;\n"); |
3210 fprintf(fp,"}\n"); | |
3853
11211f7cb5a0
7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents:
3839
diff
changeset
|
3211 // Save the label |
11211f7cb5a0
7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents:
3839
diff
changeset
|
3212 fprintf(fp,"void %sNode::save_label( Label** label, uint* block_num ) {\n", instr->_ident); |
11211f7cb5a0
7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents:
3839
diff
changeset
|
3213 fprintf(fp," labelOper* oper = (labelOper*)(opnd_array(%d));\n", |
11211f7cb5a0
7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents:
3839
diff
changeset
|
3214 label_position ); |
11211f7cb5a0
7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents:
3839
diff
changeset
|
3215 fprintf(fp," *label = oper->_label;\n"); |
11211f7cb5a0
7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents:
3839
diff
changeset
|
3216 fprintf(fp," *block_num = oper->_block_num;\n"); |
11211f7cb5a0
7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents:
3839
diff
changeset
|
3217 fprintf(fp,"}\n"); |
0 | 3218 } |
3219 } | |
3220 | |
3221 // Output the definitions for methods | |
3222 _instructions.reset(); | |
3223 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { | |
3224 // Ensure this is a machine-world instruction | |
3225 if ( instr->ideal_only() ) continue; | |
3226 | |
3227 // Access the fields for operand Label | |
3228 int method_position = instr->method_position(); | |
3229 if( method_position != -1 ) { | |
3230 // Access the method's address | |
3231 fprintf(fp,"void %sNode::method_set( intptr_t method ) {\n", instr->_ident); | |
3232 fprintf(fp," ((methodOper*)opnd_array(%d))->_method = method;\n", | |
3233 method_position ); | |
3234 fprintf(fp,"}\n"); | |
3235 fprintf(fp,"\n"); | |
3236 } | |
3237 } | |
3238 | |
3239 // Define this instruction's number of relocation entries, base is '0' | |
3240 _instructions.reset(); | |
3241 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { | |
3242 // Output the definition for number of relocation entries | |
3243 uint reloc_size = instr->reloc(_globalNames); | |
3244 if ( reloc_size != 0 ) { | |
6850 | 3245 fprintf(fp,"int %sNode::reloc() const {\n", instr->_ident); |
3246 fprintf(fp," return %d;\n", reloc_size); | |
0 | 3247 fprintf(fp,"}\n"); |
3248 fprintf(fp,"\n"); | |
3249 } | |
3250 } | |
3251 fprintf(fp,"\n"); | |
3252 | |
3253 // Output the definitions for code generation | |
3254 // | |
3255 // address ___Node::emit(address ptr, PhaseRegAlloc *ra_) const { | |
3256 // // ... encoding defined by user | |
3257 // return ptr; | |
3258 // } | |
3259 // | |
3260 _instructions.reset(); | |
3261 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3262 // Ensure this is a machine-world instruction | |
3263 if ( instr->ideal_only() ) continue; | |
3264 | |
14428
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3265 if (instr->_insencode) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3266 if (instr->postalloc_expands()) { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3267 // Don't write this to _CPP_EXPAND_file, as the code generated calls C-code |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3268 // from code sections in ad file that is dumped to fp. |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3269 define_postalloc_expand(fp, *instr); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3270 } else { |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3271 defineEmit(fp, *instr); |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3272 } |
044b28168e20
8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents:
12167
diff
changeset
|
3273 } |
2008 | 3274 if (instr->is_mach_constant()) defineEvalConstant(fp, *instr); |
3275 if (instr->_size) defineSize (fp, *instr); | |
0 | 3276 |
3277 // side-call to generate output that used to be in the header file: | |
3278 extern void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &oper, bool for_c_file); | |
3279 gen_inst_format(_CPP_FORMAT_file._fp, _globalNames, *instr, true); | |
3280 } | |
3281 | |
3282 // Output the definitions for alias analysis | |
3283 _instructions.reset(); | |
3284 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3285 // Ensure this is a machine-world instruction | |
3286 if ( instr->ideal_only() ) continue; | |
3287 | |
3288 // Analyze machine instructions that either USE or DEF memory. | |
3289 int memory_operand = instr->memory_operand(_globalNames); | |
3290 // Some guys kill all of memory | |
3291 if ( instr->is_wide_memory_kill(_globalNames) ) { | |
3292 memory_operand = InstructForm::MANY_MEMORY_OPERANDS; | |
3293 } | |
3294 | |
3295 if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) { | |
3296 if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) { | |
3297 fprintf(fp,"const TypePtr *%sNode::adr_type() const { return TypePtr::BOTTOM; }\n", instr->_ident); | |
3298 fprintf(fp,"const MachOper* %sNode::memory_operand() const { return (MachOper*)-1; }\n", instr->_ident); | |
3299 } else { | |
3300 fprintf(fp,"const MachOper* %sNode::memory_operand() const { return _opnds[%d]; }\n", instr->_ident, memory_operand); | |
3301 } | |
3302 } | |
3303 } | |
3304 | |
3305 // Get the length of the longest identifier | |
3306 int max_ident_len = 0; | |
3307 _instructions.reset(); | |
3308 | |
3309 for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3310 if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) { | |
3311 int ident_len = (int)strlen(instr->_ident); | |
3312 if( max_ident_len < ident_len ) | |
3313 max_ident_len = ident_len; | |
3314 } | |
3315 } | |
3316 | |
3317 // Emit specifically for Node(s) | |
3318 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n", | |
3319 max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL"); | |
3320 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return %s; }\n", | |
3321 max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL"); | |
3322 fprintf(_CPP_PIPELINE_file._fp, "\n"); | |
3323 | |
3324 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n", | |
3325 max_ident_len, "MachNode", _pipeline ? "(&pipeline_class_Unknown_Instructions)" : "NULL"); | |
3326 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return pipeline_class(); }\n", | |
3327 max_ident_len, "MachNode"); | |
3328 fprintf(_CPP_PIPELINE_file._fp, "\n"); | |
3329 | |
3330 // Output the definitions for machine node specific pipeline data | |
3331 _machnodes.reset(); | |
3332 | |
3333 for ( ; (machnode = (MachNodeForm*)_machnodes.iter()) != NULL; ) { | |
3334 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %sNode::pipeline() const { return (&pipeline_class_%03d); }\n", | |
3335 machnode->_ident, ((class PipeClassForm *)_pipeline->_classdict[machnode->_machnode_pipe])->_num); | |
3336 } | |
3337 | |
3338 fprintf(_CPP_PIPELINE_file._fp, "\n"); | |
3339 | |
3340 // Output the definitions for instruction pipeline static data references | |
3341 _instructions.reset(); | |
3342 | |
3343 for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3344 if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) { | |
3345 fprintf(_CPP_PIPELINE_file._fp, "\n"); | |
3346 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline_class() { return (&pipeline_class_%03d); }\n", | |
3347 max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num); | |
3348 fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline() const { return (&pipeline_class_%03d); }\n", | |
3349 max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num); | |
3350 } | |
3351 } | |
3352 } | |
3353 | |
3354 | |
3355 // -------------------------------- maps ------------------------------------ | |
3356 | |
3357 // Information needed to generate the ReduceOp mapping for the DFA | |
3358 class OutputReduceOp : public OutputMap { | |
3359 public: | |
3360 OutputReduceOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
6850 | 3361 : OutputMap(hpp, cpp, globals, AD, "reduceOp") {}; |
0 | 3362 |
3363 void declaration() { fprintf(_hpp, "extern const int reduceOp[];\n"); } | |
3364 void definition() { fprintf(_cpp, "const int reduceOp[] = {\n"); } | |
3365 void closing() { fprintf(_cpp, " 0 // no trailing comma\n"); | |
3366 OutputMap::closing(); | |
3367 } | |
3368 void map(OpClassForm &opc) { | |
3369 const char *reduce = opc._ident; | |
3370 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3371 else fprintf(_cpp, " 0"); | |
3372 } | |
3373 void map(OperandForm &oper) { | |
3374 // Most operands without match rules, e.g. eFlagsReg, do not have a result operand | |
3375 const char *reduce = (oper._matrule ? oper.reduce_result() : NULL); | |
3376 // operand stackSlot does not have a match rule, but produces a stackSlot | |
3377 if( oper.is_user_name_for_sReg() != Form::none ) reduce = oper.reduce_result(); | |
3378 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3379 else fprintf(_cpp, " 0"); | |
3380 } | |
3381 void map(InstructForm &inst) { | |
3382 const char *reduce = (inst._matrule ? inst.reduce_result() : NULL); | |
3383 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3384 else fprintf(_cpp, " 0"); | |
3385 } | |
3386 void map(char *reduce) { | |
3387 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3388 else fprintf(_cpp, " 0"); | |
3389 } | |
3390 }; | |
3391 | |
3392 // Information needed to generate the LeftOp mapping for the DFA | |
3393 class OutputLeftOp : public OutputMap { | |
3394 public: | |
3395 OutputLeftOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
6850 | 3396 : OutputMap(hpp, cpp, globals, AD, "leftOp") {}; |
0 | 3397 |
3398 void declaration() { fprintf(_hpp, "extern const int leftOp[];\n"); } | |
3399 void definition() { fprintf(_cpp, "const int leftOp[] = {\n"); } | |
3400 void closing() { fprintf(_cpp, " 0 // no trailing comma\n"); | |
3401 OutputMap::closing(); | |
3402 } | |
3403 void map(OpClassForm &opc) { fprintf(_cpp, " 0"); } | |
3404 void map(OperandForm &oper) { | |
3405 const char *reduce = oper.reduce_left(_globals); | |
3406 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3407 else fprintf(_cpp, " 0"); | |
3408 } | |
3409 void map(char *name) { | |
3410 const char *reduce = _AD.reduceLeft(name); | |
3411 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3412 else fprintf(_cpp, " 0"); | |
3413 } | |
3414 void map(InstructForm &inst) { | |
3415 const char *reduce = inst.reduce_left(_globals); | |
3416 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3417 else fprintf(_cpp, " 0"); | |
3418 } | |
3419 }; | |
3420 | |
3421 | |
3422 // Information needed to generate the RightOp mapping for the DFA | |
3423 class OutputRightOp : public OutputMap { | |
3424 public: | |
3425 OutputRightOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
6850 | 3426 : OutputMap(hpp, cpp, globals, AD, "rightOp") {}; |
0 | 3427 |
3428 void declaration() { fprintf(_hpp, "extern const int rightOp[];\n"); } | |
3429 void definition() { fprintf(_cpp, "const int rightOp[] = {\n"); } | |
3430 void closing() { fprintf(_cpp, " 0 // no trailing comma\n"); | |
3431 OutputMap::closing(); | |
3432 } | |
3433 void map(OpClassForm &opc) { fprintf(_cpp, " 0"); } | |
3434 void map(OperandForm &oper) { | |
3435 const char *reduce = oper.reduce_right(_globals); | |
3436 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3437 else fprintf(_cpp, " 0"); | |
3438 } | |
3439 void map(char *name) { | |
3440 const char *reduce = _AD.reduceRight(name); | |
3441 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3442 else fprintf(_cpp, " 0"); | |
3443 } | |
3444 void map(InstructForm &inst) { | |
3445 const char *reduce = inst.reduce_right(_globals); | |
3446 if( reduce ) fprintf(_cpp, " %s_rule", reduce); | |
3447 else fprintf(_cpp, " 0"); | |
3448 } | |
3449 }; | |
3450 | |
3451 | |
3452 // Information needed to generate the Rule names for the DFA | |
3453 class OutputRuleName : public OutputMap { | |
3454 public: | |
3455 OutputRuleName(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
6850 | 3456 : OutputMap(hpp, cpp, globals, AD, "ruleName") {}; |
0 | 3457 |
3458 void declaration() { fprintf(_hpp, "extern const char *ruleName[];\n"); } | |
3459 void definition() { fprintf(_cpp, "const char *ruleName[] = {\n"); } | |
6850 | 3460 void closing() { fprintf(_cpp, " \"invalid rule name\" // no trailing comma\n"); |
0 | 3461 OutputMap::closing(); |
3462 } | |
3463 void map(OpClassForm &opc) { fprintf(_cpp, " \"%s\"", _AD.machOperEnum(opc._ident) ); } | |
3464 void map(OperandForm &oper) { fprintf(_cpp, " \"%s\"", _AD.machOperEnum(oper._ident) ); } | |
3465 void map(char *name) { fprintf(_cpp, " \"%s\"", name ? name : "0"); } | |
3466 void map(InstructForm &inst){ fprintf(_cpp, " \"%s\"", inst._ident ? inst._ident : "0"); } | |
3467 }; | |
3468 | |
3469 | |
3470 // Information needed to generate the swallowed mapping for the DFA | |
3471 class OutputSwallowed : public OutputMap { | |
3472 public: | |
3473 OutputSwallowed(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
6850 | 3474 : OutputMap(hpp, cpp, globals, AD, "swallowed") {}; |
0 | 3475 |
3476 void declaration() { fprintf(_hpp, "extern const bool swallowed[];\n"); } | |
3477 void definition() { fprintf(_cpp, "const bool swallowed[] = {\n"); } | |
3478 void closing() { fprintf(_cpp, " false // no trailing comma\n"); | |
3479 OutputMap::closing(); | |
3480 } | |
3481 void map(OperandForm &oper) { // Generate the entry for this opcode | |
3482 const char *swallowed = oper.swallowed(_globals) ? "true" : "false"; | |
3483 fprintf(_cpp, " %s", swallowed); | |
3484 } | |
3485 void map(OpClassForm &opc) { fprintf(_cpp, " false"); } | |
3486 void map(char *name) { fprintf(_cpp, " false"); } | |
3487 void map(InstructForm &inst){ fprintf(_cpp, " false"); } | |
3488 }; | |
3489 | |
3490 | |
3491 // Information needed to generate the decision array for instruction chain rule | |
3492 class OutputInstChainRule : public OutputMap { | |
3493 public: | |
3494 OutputInstChainRule(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
6850 | 3495 : OutputMap(hpp, cpp, globals, AD, "instruction_chain_rule") {}; |
0 | 3496 |
3497 void declaration() { fprintf(_hpp, "extern const bool instruction_chain_rule[];\n"); } | |
3498 void definition() { fprintf(_cpp, "const bool instruction_chain_rule[] = {\n"); } | |
3499 void closing() { fprintf(_cpp, " false // no trailing comma\n"); | |
3500 OutputMap::closing(); | |
3501 } | |
3502 void map(OpClassForm &opc) { fprintf(_cpp, " false"); } | |
3503 void map(OperandForm &oper) { fprintf(_cpp, " false"); } | |
3504 void map(char *name) { fprintf(_cpp, " false"); } | |
3505 void map(InstructForm &inst) { // Check for simple chain rule | |
3506 const char *chain = inst.is_simple_chain_rule(_globals) ? "true" : "false"; | |
3507 fprintf(_cpp, " %s", chain); | |
3508 } | |
3509 }; | |
3510 | |
3511 | |
3512 //---------------------------build_map------------------------------------ | |
3513 // Build mapping from enumeration for densely packed operands | |
3514 // TO result and child types. | |
3515 void ArchDesc::build_map(OutputMap &map) { | |
3516 FILE *fp_hpp = map.decl_file(); | |
3517 FILE *fp_cpp = map.def_file(); | |
3518 int idx = 0; | |
3519 OperandForm *op; | |
3520 OpClassForm *opc; | |
3521 InstructForm *inst; | |
3522 | |
3523 // Construct this mapping | |
3524 map.declaration(); | |
3525 fprintf(fp_cpp,"\n"); | |
3526 map.definition(); | |
3527 | |
3528 // Output the mapping for operands | |
3529 map.record_position(OutputMap::BEGIN_OPERANDS, idx ); | |
3530 _operands.reset(); | |
3531 for(; (op = (OperandForm*)_operands.iter()) != NULL; ) { | |
3532 // Ensure this is a machine-world instruction | |
3533 if ( op->ideal_only() ) continue; | |
3534 | |
3535 // Generate the entry for this opcode | |
6850 | 3536 fprintf(fp_cpp, " /* %4d */", idx); map.map(*op); fprintf(fp_cpp, ",\n"); |
0 | 3537 ++idx; |
3538 }; | |
3539 fprintf(fp_cpp, " // last operand\n"); | |
3540 | |
3541 // Place all user-defined operand classes into the mapping | |
3542 map.record_position(OutputMap::BEGIN_OPCLASSES, idx ); | |
3543 _opclass.reset(); | |
3544 for(; (opc = (OpClassForm*)_opclass.iter()) != NULL; ) { | |
6850 | 3545 fprintf(fp_cpp, " /* %4d */", idx); map.map(*opc); fprintf(fp_cpp, ",\n"); |
0 | 3546 ++idx; |
3547 }; | |
3548 fprintf(fp_cpp, " // last operand class\n"); | |
3549 | |
3550 // Place all internally defined operands into the mapping | |
3551 map.record_position(OutputMap::BEGIN_INTERNALS, idx ); | |
3552 _internalOpNames.reset(); | |
3553 char *name = NULL; | |
3554 for(; (name = (char *)_internalOpNames.iter()) != NULL; ) { | |
6850 | 3555 fprintf(fp_cpp, " /* %4d */", idx); map.map(name); fprintf(fp_cpp, ",\n"); |
0 | 3556 ++idx; |
3557 }; | |
3558 fprintf(fp_cpp, " // last internally defined operand\n"); | |
3559 | |
3560 // Place all user-defined instructions into the mapping | |
3561 if( map.do_instructions() ) { | |
3562 map.record_position(OutputMap::BEGIN_INSTRUCTIONS, idx ); | |
3563 // Output all simple instruction chain rules first | |
3564 map.record_position(OutputMap::BEGIN_INST_CHAIN_RULES, idx ); | |
3565 { | |
3566 _instructions.reset(); | |
3567 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3568 // Ensure this is a machine-world instruction | |
3569 if ( inst->ideal_only() ) continue; | |
3570 if ( ! inst->is_simple_chain_rule(_globalNames) ) continue; | |
3571 if ( inst->rematerialize(_globalNames, get_registers()) ) continue; | |
3572 | |
6850 | 3573 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n"); |
0 | 3574 ++idx; |
3575 }; | |
3576 map.record_position(OutputMap::BEGIN_REMATERIALIZE, idx ); | |
3577 _instructions.reset(); | |
3578 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3579 // Ensure this is a machine-world instruction | |
3580 if ( inst->ideal_only() ) continue; | |
3581 if ( ! inst->is_simple_chain_rule(_globalNames) ) continue; | |
3582 if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue; | |
3583 | |
6850 | 3584 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n"); |
0 | 3585 ++idx; |
3586 }; | |
3587 map.record_position(OutputMap::END_INST_CHAIN_RULES, idx ); | |
3588 } | |
3589 // Output all instructions that are NOT simple chain rules | |
3590 { | |
3591 _instructions.reset(); | |
3592 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3593 // Ensure this is a machine-world instruction | |
3594 if ( inst->ideal_only() ) continue; | |
3595 if ( inst->is_simple_chain_rule(_globalNames) ) continue; | |
3596 if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue; | |
3597 | |
6850 | 3598 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n"); |
0 | 3599 ++idx; |
3600 }; | |
3601 map.record_position(OutputMap::END_REMATERIALIZE, idx ); | |
3602 _instructions.reset(); | |
3603 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { | |
3604 // Ensure this is a machine-world instruction | |
3605 if ( inst->ideal_only() ) continue; | |
3606 if ( inst->is_simple_chain_rule(_globalNames) ) continue; | |
3607 if ( inst->rematerialize(_globalNames, get_registers()) ) continue; | |
3608 | |
6850 | 3609 fprintf(fp_cpp, " /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n"); |
0 | 3610 ++idx; |
3611 }; | |
3612 } | |
3613 fprintf(fp_cpp, " // last instruction\n"); | |
3614 map.record_position(OutputMap::END_INSTRUCTIONS, idx ); | |
3615 } | |
3616 // Finish defining table | |
3617 map.closing(); | |
3618 }; | |
3619 | |
3620 | |
3621 // Helper function for buildReduceMaps | |
3622 char reg_save_policy(const char *calling_convention) { | |
3623 char callconv; | |
3624 | |
3625 if (!strcmp(calling_convention, "NS")) callconv = 'N'; | |
3626 else if (!strcmp(calling_convention, "SOE")) callconv = 'E'; | |
3627 else if (!strcmp(calling_convention, "SOC")) callconv = 'C'; | |
3628 else if (!strcmp(calling_convention, "AS")) callconv = 'A'; | |
3629 else callconv = 'Z'; | |
3630 | |
3631 return callconv; | |
3632 } | |
3633 | |
14449
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
3634 void ArchDesc::generate_needs_clone_jvms(FILE *fp_cpp) { |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
3635 fprintf(fp_cpp, "bool Compile::needs_clone_jvms() { return %s; }\n\n", |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
3636 _needs_clone_jvms ? "true" : "false"); |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
3637 } |
ad6695638a35
8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents:
14444
diff
changeset
|
3638 |
0 | 3639 //---------------------------generate_assertion_checks------------------- |
3640 void ArchDesc::generate_adlc_verification(FILE *fp_cpp) { | |
3641 fprintf(fp_cpp, "\n"); | |
3642 | |
3643 fprintf(fp_cpp, "#ifndef PRODUCT\n"); | |
3644 fprintf(fp_cpp, "void Compile::adlc_verification() {\n"); | |
3645 globalDefs().print_asserts(fp_cpp); | |
3646 fprintf(fp_cpp, "}\n"); | |
3647 fprintf(fp_cpp, "#endif\n"); | |
3648 fprintf(fp_cpp, "\n"); | |
3649 } | |
3650 | |
3651 //---------------------------addSourceBlocks----------------------------- | |
3652 void ArchDesc::addSourceBlocks(FILE *fp_cpp) { | |
3653 if (_source.count() > 0) | |
3654 _source.output(fp_cpp); | |
3655 | |
3656 generate_adlc_verification(fp_cpp); | |
3657 } | |
3658 //---------------------------addHeaderBlocks----------------------------- | |
3659 void ArchDesc::addHeaderBlocks(FILE *fp_hpp) { | |
3660 if (_header.count() > 0) | |
3661 _header.output(fp_hpp); | |
3662 } | |
3663 //-------------------------addPreHeaderBlocks---------------------------- | |
3664 void ArchDesc::addPreHeaderBlocks(FILE *fp_hpp) { | |
3665 // Output #defines from definition block | |
3666 globalDefs().print_defines(fp_hpp); | |
3667 | |
3668 if (_pre_header.count() > 0) | |
3669 _pre_header.output(fp_hpp); | |
3670 } | |
3671 | |
3672 //---------------------------buildReduceMaps----------------------------- | |
3673 // Build mapping from enumeration for densely packed operands | |
3674 // TO result and child types. | |
3675 void ArchDesc::buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp) { | |
3676 RegDef *rdef; | |
3677 RegDef *next; | |
3678 | |
3679 // The emit bodies currently require functions defined in the source block. | |
3680 | |
3681 // Build external declarations for mappings | |
3682 fprintf(fp_hpp, "\n"); | |
3683 fprintf(fp_hpp, "extern const char register_save_policy[];\n"); | |
3684 fprintf(fp_hpp, "extern const char c_reg_save_policy[];\n"); | |
3685 fprintf(fp_hpp, "extern const int register_save_type[];\n"); | |
3686 fprintf(fp_hpp, "\n"); | |
3687 | |
3688 // Construct Save-Policy array | |
3689 fprintf(fp_cpp, "// Map from machine-independent register number to register_save_policy\n"); | |
3690 fprintf(fp_cpp, "const char register_save_policy[] = {\n"); | |
3691 _register->reset_RegDefs(); | |
3692 for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) { | |
3693 next = _register->iter_RegDefs(); | |
3694 char policy = reg_save_policy(rdef->_callconv); | |
3695 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | |
6850 | 3696 fprintf(fp_cpp, " '%c'%s // %s\n", policy, comma, rdef->_regname); |
0 | 3697 } |
3698 fprintf(fp_cpp, "};\n\n"); | |
3699 | |
3700 // Construct Native Save-Policy array | |
3701 fprintf(fp_cpp, "// Map from machine-independent register number to c_reg_save_policy\n"); | |
3702 fprintf(fp_cpp, "const char c_reg_save_policy[] = {\n"); | |
3703 _register->reset_RegDefs(); | |
3704 for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) { | |
3705 next = _register->iter_RegDefs(); | |
3706 char policy = reg_save_policy(rdef->_c_conv); | |
3707 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | |
6850 | 3708 fprintf(fp_cpp, " '%c'%s // %s\n", policy, comma, rdef->_regname); |
0 | 3709 } |
3710 fprintf(fp_cpp, "};\n\n"); | |
3711 | |
3712 // Construct Register Save Type array | |
3713 fprintf(fp_cpp, "// Map from machine-independent register number to register_save_type\n"); | |
3714 fprintf(fp_cpp, "const int register_save_type[] = {\n"); | |
3715 _register->reset_RegDefs(); | |
3716 for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) { | |
3717 next = _register->iter_RegDefs(); | |
3718 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | |
3719 fprintf(fp_cpp, " %s%s\n", rdef->_idealtype, comma); | |
3720 } | |
3721 fprintf(fp_cpp, "};\n\n"); | |
3722 | |
3723 // Construct the table for reduceOp | |
3724 OutputReduceOp output_reduce_op(fp_hpp, fp_cpp, _globalNames, *this); | |
3725 build_map(output_reduce_op); | |
3726 // Construct the table for leftOp | |
3727 OutputLeftOp output_left_op(fp_hpp, fp_cpp, _globalNames, *this); | |
3728 build_map(output_left_op); | |
3729 // Construct the table for rightOp | |
3730 OutputRightOp output_right_op(fp_hpp, fp_cpp, _globalNames, *this); | |
3731 build_map(output_right_op); | |
3732 // Construct the table of rule names | |
3733 OutputRuleName output_rule_name(fp_hpp, fp_cpp, _globalNames, *this); | |
3734 build_map(output_rule_name); | |
3735 // Construct the boolean table for subsumed operands | |
3736 OutputSwallowed output_swallowed(fp_hpp, fp_cpp, _globalNames, *this); | |
3737 build_map(output_swallowed); | |
3738 // // // Preserve in case we decide to use this table instead of another | |
3739 //// Construct the boolean table for instruction chain rules | |
3740 //OutputInstChainRule output_inst_chain(fp_hpp, fp_cpp, _globalNames, *this); | |
3741 //build_map(output_inst_chain); | |
3742 | |
3743 } | |
3744 | |
3745 | |
3746 //---------------------------buildMachOperGenerator--------------------------- | |
3747 | |
3748 // Recurse through match tree, building path through corresponding state tree, | |
3749 // Until we reach the constant we are looking for. | |
3750 static void path_to_constant(FILE *fp, FormDict &globals, | |
3751 MatchNode *mnode, uint idx) { | |
3752 if ( ! mnode) return; | |
3753 | |
3754 unsigned position = 0; | |
3755 const char *result = NULL; | |
3756 const char *name = NULL; | |
3757 const char *optype = NULL; | |
3758 | |
3759 // Base Case: access constant in ideal node linked to current state node | |
3760 // Each type of constant has its own access function | |
3761 if ( (mnode->_lChild == NULL) && (mnode->_rChild == NULL) | |
3762 && mnode->base_operand(position, globals, result, name, optype) ) { | |
3763 if ( strcmp(optype,"ConI") == 0 ) { | |
3764 fprintf(fp, "_leaf->get_int()"); | |
3765 } else if ( (strcmp(optype,"ConP") == 0) ) { | |
3766 fprintf(fp, "_leaf->bottom_type()->is_ptr()"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
3767 } else if ( (strcmp(optype,"ConN") == 0) ) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
3768 fprintf(fp, "_leaf->bottom_type()->is_narrowoop()"); |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6804
diff
changeset
|
3769 } else if ( (strcmp(optype,"ConNKlass") == 0) ) { |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6804
diff
changeset
|
3770 fprintf(fp, "_leaf->bottom_type()->is_narrowklass()"); |
0 | 3771 } else if ( (strcmp(optype,"ConF") == 0) ) { |
3772 fprintf(fp, "_leaf->getf()"); | |
3773 } else if ( (strcmp(optype,"ConD") == 0) ) { | |
3774 fprintf(fp, "_leaf->getd()"); | |
3775 } else if ( (strcmp(optype,"ConL") == 0) ) { | |
3776 fprintf(fp, "_leaf->get_long()"); | |
3777 } else if ( (strcmp(optype,"Con")==0) ) { | |
3778 // !!!!! - Update if adding a machine-independent constant type | |
3779 fprintf(fp, "_leaf->get_int()"); | |
3780 assert( false, "Unsupported constant type, pointer or indefinite"); | |
3781 } else if ( (strcmp(optype,"Bool") == 0) ) { | |
3782 fprintf(fp, "_leaf->as_Bool()->_test._test"); | |
3783 } else { | |
3784 assert( false, "Unsupported constant type"); | |
3785 } | |
3786 return; | |
3787 } | |
3788 | |
3789 // If constant is in left child, build path and recurse | |
3790 uint lConsts = (mnode->_lChild) ? (mnode->_lChild->num_consts(globals) ) : 0; | |
3791 uint rConsts = (mnode->_rChild) ? (mnode->_rChild->num_consts(globals) ) : 0; | |
3792 if ( (mnode->_lChild) && (lConsts > idx) ) { | |
3793 fprintf(fp, "_kids[0]->"); | |
3794 path_to_constant(fp, globals, mnode->_lChild, idx); | |
3795 return; | |
3796 } | |
3797 // If constant is in right child, build path and recurse | |
3798 if ( (mnode->_rChild) && (rConsts > (idx - lConsts) ) ) { | |
3799 idx = idx - lConsts; | |
3800 fprintf(fp, "_kids[1]->"); | |
3801 path_to_constant(fp, globals, mnode->_rChild, idx); | |
3802 return; | |
3803 } | |
3804 assert( false, "ShouldNotReachHere()"); | |
3805 } | |
3806 | |
3807 // Generate code that is executed when generating a specific Machine Operand | |
3808 static void genMachOperCase(FILE *fp, FormDict &globalNames, ArchDesc &AD, | |
3809 OperandForm &op) { | |
3810 const char *opName = op._ident; | |
3811 const char *opEnumName = AD.machOperEnum(opName); | |
3812 uint num_consts = op.num_consts(globalNames); | |
3813 | |
3814 // Generate the case statement for this opcode | |
3815 fprintf(fp, " case %s:", opEnumName); | |
3816 fprintf(fp, "\n return new (C) %sOper(", opName); | |
3817 // Access parameters for constructor from the stat object | |
3818 // | |
3819 // Build access to condition code value | |
3820 if ( (num_consts > 0) ) { | |
3821 uint i = 0; | |
3822 path_to_constant(fp, globalNames, op._matrule, i); | |
3823 for ( i = 1; i < num_consts; ++i ) { | |
3824 fprintf(fp, ", "); | |
3825 path_to_constant(fp, globalNames, op._matrule, i); | |
3826 } | |
3827 } | |
3828 fprintf(fp, " );\n"); | |
3829 } | |
3830 | |
3831 | |
3832 // Build switch to invoke "new" MachNode or MachOper | |
3833 void ArchDesc::buildMachOperGenerator(FILE *fp_cpp) { | |
3834 int idx = 0; | |
3835 | |
3836 // Build switch to invoke 'new' for a specific MachOper | |
3837 fprintf(fp_cpp, "\n"); | |
3838 fprintf(fp_cpp, "\n"); | |
3839 fprintf(fp_cpp, | |
3840 "//------------------------- MachOper Generator ---------------\n"); | |
3841 fprintf(fp_cpp, | |
3842 "// A switch statement on the dense-packed user-defined type system\n" | |
3843 "// that invokes 'new' on the corresponding class constructor.\n"); | |
3844 fprintf(fp_cpp, "\n"); | |
3845 fprintf(fp_cpp, "MachOper *State::MachOperGenerator"); | |
3846 fprintf(fp_cpp, "(int opcode, Compile* C)"); | |
3847 fprintf(fp_cpp, "{\n"); | |
3848 fprintf(fp_cpp, "\n"); | |
3849 fprintf(fp_cpp, " switch(opcode) {\n"); | |
3850 | |
3851 // Place all user-defined operands into the mapping | |
3852 _operands.reset(); | |
3853 int opIndex = 0; | |
3854 OperandForm *op; | |
3855 for( ; (op = (OperandForm*)_operands.iter()) != NULL; ) { | |
3856 // Ensure this is a machine-world instruction | |
3857 if ( op->ideal_only() ) continue; | |
3858 | |
3859 genMachOperCase(fp_cpp, _globalNames, *this, *op); | |
3860 }; | |
3861 | |
3862 // Do not iterate over operand classes for the operand generator!!! | |
3863 | |
3864 // Place all internal operands into the mapping | |
3865 _internalOpNames.reset(); | |
3866 const char *iopn; | |
3867 for( ; (iopn = _internalOpNames.iter()) != NULL; ) { | |
3868 const char *opEnumName = machOperEnum(iopn); | |
3869 // Generate the case statement for this opcode | |
3870 fprintf(fp_cpp, " case %s:", opEnumName); | |
3871 fprintf(fp_cpp, " return NULL;\n"); | |
3872 }; | |
3873 | |
3874 // Generate the default case for switch(opcode) | |
3875 fprintf(fp_cpp, " \n"); | |
3876 fprintf(fp_cpp, " default:\n"); | |
3877 fprintf(fp_cpp, " fprintf(stderr, \"Default MachOper Generator invoked for: \\n\");\n"); | |
3878 fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%'); | |
3879 fprintf(fp_cpp, " break;\n"); | |
3880 fprintf(fp_cpp, " }\n"); | |
3881 | |
3882 // Generate the closing for method Matcher::MachOperGenerator | |
3883 fprintf(fp_cpp, " return NULL;\n"); | |
3884 fprintf(fp_cpp, "};\n"); | |
3885 } | |
3886 | |
3887 | |
3888 //---------------------------buildMachNode------------------------------------- | |
3889 // Build a new MachNode, for MachNodeGenerator or cisc-spilling | |
3890 void ArchDesc::buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent) { | |
3891 const char *opType = NULL; | |
3892 const char *opClass = inst->_ident; | |
3893 | |
3894 // Create the MachNode object | |
3895 fprintf(fp_cpp, "%s %sNode *node = new (C) %sNode();\n",indent, opClass,opClass); | |
3896 | |
3897 if ( (inst->num_post_match_opnds() != 0) ) { | |
3898 // Instruction that contains operands which are not in match rule. | |
3899 // | |
3900 // Check if the first post-match component may be an interesting def | |
3901 bool dont_care = false; | |
3902 ComponentList &comp_list = inst->_components; | |
3903 Component *comp = NULL; | |
3904 comp_list.reset(); | |
3905 if ( comp_list.match_iter() != NULL ) dont_care = true; | |
3906 | |
3907 // Insert operands that are not in match-rule. | |
3908 // Only insert a DEF if the do_care flag is set | |
3909 comp_list.reset(); | |
3910 while ( comp = comp_list.post_match_iter() ) { | |
3911 // Check if we don't care about DEFs or KILLs that are not USEs | |
3912 if ( dont_care && (! comp->isa(Component::USE)) ) { | |
3913 continue; | |
3914 } | |
3915 dont_care = true; | |
3916 // For each operand not in the match rule, call MachOperGenerator | |
2254
ab42c7e1cf83
7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents:
2008
diff
changeset
|
3917 // with the enum for the opcode that needs to be built. |
0 | 3918 ComponentList clist = inst->_components; |
6850 | 3919 int index = clist.operand_position(comp->_name, comp->_usedef, inst); |
0 | 3920 const char *opcode = machOperEnum(comp->_type); |
3921 fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index); | |
3922 fprintf(fp_cpp, "MachOperGenerator(%s, C));\n", opcode); | |
3923 } | |
3924 } | |
3925 else if ( inst->is_chain_of_constant(_globalNames, opType) ) { | |
3926 // An instruction that chains from a constant! | |
3927 // In this case, we need to subsume the constant into the node | |
3928 // at operand position, oper_input_base(). | |
3929 // | |
3930 // Fill in the constant | |
3931 fprintf(fp_cpp, "%s node->_opnd_array[%d] = ", indent, | |
3932 inst->oper_input_base(_globalNames)); | |
3933 // ##### | |
3934 // Check for multiple constants and then fill them in. | |
3935 // Just like MachOperGenerator | |
3936 const char *opName = inst->_matrule->_rChild->_opType; | |
3937 fprintf(fp_cpp, "new (C) %sOper(", opName); | |
3938 // Grab operand form | |
3939 OperandForm *op = (_globalNames[opName])->is_operand(); | |
3940 // Look up the number of constants | |
3941 uint num_consts = op->num_consts(_globalNames); | |
3942 if ( (num_consts > 0) ) { | |
3943 uint i = 0; | |
3944 path_to_constant(fp_cpp, _globalNames, op->_matrule, i); | |
3945 for ( i = 1; i < num_consts; ++i ) { | |
3946 fprintf(fp_cpp, ", "); | |
3947 path_to_constant(fp_cpp, _globalNames, op->_matrule, i); | |
3948 } | |
3949 } | |
3950 fprintf(fp_cpp, " );\n"); | |
3951 // ##### | |
3952 } | |
3953 | |
3954 // Fill in the bottom_type where requested | |
14434
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
3955 if (inst->captures_bottom_type(_globalNames)) { |
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
3956 if (strncmp("MachCall", inst->mach_base_class(_globalNames), strlen("MachCall"))) { |
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
3957 fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent); |
318d0622a6d7
8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents:
14431
diff
changeset
|
3958 } |
0 | 3959 } |
3960 if( inst->is_ideal_if() ) { | |
3961 fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent); | |
3962 fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent); | |
3963 } | |
3964 if( inst->is_ideal_fastlock() ) { | |
3965 fprintf(fp_cpp, "%s node->_counters = _leaf->as_FastLock()->counters();\n", indent); | |
3966 } | |
3967 | |
3968 } | |
3969 | |
3970 //---------------------------declare_cisc_version------------------------------ | |
3971 // Build CISC version of this instruction | |
3972 void InstructForm::declare_cisc_version(ArchDesc &AD, FILE *fp_hpp) { | |
3973 if( AD.can_cisc_spill() ) { | |
3974 InstructForm *inst_cisc = cisc_spill_alternate(); | |
3975 if (inst_cisc != NULL) { | |
3976 fprintf(fp_hpp, " virtual int cisc_operand() const { return %d; }\n", cisc_spill_operand()); | |
3977 fprintf(fp_hpp, " virtual MachNode *cisc_version(int offset, Compile* C);\n"); | |
3978 fprintf(fp_hpp, " virtual void use_cisc_RegMask();\n"); | |
3979 fprintf(fp_hpp, " virtual const RegMask *cisc_RegMask() const { return _cisc_RegMask; }\n"); | |
3980 } | |
3981 } | |
3982 } | |
3983 | |
3984 //---------------------------define_cisc_version------------------------------- | |
3985 // Build CISC version of this instruction | |
3986 bool InstructForm::define_cisc_version(ArchDesc &AD, FILE *fp_cpp) { | |
3987 InstructForm *inst_cisc = this->cisc_spill_alternate(); | |
3988 if( AD.can_cisc_spill() && (inst_cisc != NULL) ) { | |
3989 const char *name = inst_cisc->_ident; | |
3990 assert( inst_cisc->num_opnds() == this->num_opnds(), "Must have same number of operands"); | |
3991 OperandForm *cisc_oper = AD.cisc_spill_operand(); | |
3992 assert( cisc_oper != NULL, "insanity check"); | |
3993 const char *cisc_oper_name = cisc_oper->_ident; | |
3994 assert( cisc_oper_name != NULL, "insanity check"); | |
3995 // | |
3996 // Set the correct reg_mask_or_stack for the cisc operand | |
3997 fprintf(fp_cpp, "\n"); | |
3998 fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident); | |
3999 // Lookup the correct reg_mask_or_stack | |
4000 const char *reg_mask_name = cisc_reg_mask_name(); | |
4001 fprintf(fp_cpp, " _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name); | |
4002 fprintf(fp_cpp, "}\n"); | |
4003 // | |
4004 // Construct CISC version of this instruction | |
4005 fprintf(fp_cpp, "\n"); | |
4006 fprintf(fp_cpp, "// Build CISC version of this instruction\n"); | |
4007 fprintf(fp_cpp, "MachNode *%sNode::cisc_version( int offset, Compile* C ) {\n", this->_ident); | |
4008 // Create the MachNode object | |
4009 fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name); | |
4010 // Fill in the bottom_type where requested | |
1541
b5fdf39b9749
6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents:
1489
diff
changeset
|
4011 if ( this->captures_bottom_type(AD.globalNames()) ) { |
0 | 4012 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n"); |
4013 } | |
785 | 4014 |
4015 uint cur_num_opnds = num_opnds(); | |
4016 if (cur_num_opnds > 1 && cur_num_opnds != num_unique_opnds()) { | |
4017 fprintf(fp_cpp," node->_num_opnds = %d;\n", num_unique_opnds()); | |
4018 } | |
4019 | |
0 | 4020 fprintf(fp_cpp, "\n"); |
4021 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n"); | |
4022 fprintf(fp_cpp, " fill_new_machnode(node, C);\n"); | |
4023 // Construct operand to access [stack_pointer + offset] | |
4024 fprintf(fp_cpp, " // Construct operand to access [stack_pointer + offset]\n"); | |
4025 fprintf(fp_cpp, " node->set_opnd_array(cisc_operand(), new (C) %sOper(offset));\n", cisc_oper_name); | |
4026 fprintf(fp_cpp, "\n"); | |
4027 | |
4028 // Return result and exit scope | |
4029 fprintf(fp_cpp, " return node;\n"); | |
4030 fprintf(fp_cpp, "}\n"); | |
4031 fprintf(fp_cpp, "\n"); | |
4032 return true; | |
4033 } | |
4034 return false; | |
4035 } | |
4036 | |
4037 //---------------------------declare_short_branch_methods---------------------- | |
4038 // Build prototypes for short branch methods | |
4039 void InstructForm::declare_short_branch_methods(FILE *fp_hpp) { | |
4040 if (has_short_branch_form()) { | |
4041 fprintf(fp_hpp, " virtual MachNode *short_branch_version(Compile* C);\n"); | |
4042 } | |
4043 } | |
4044 | |
4045 //---------------------------define_short_branch_methods----------------------- | |
4046 // Build definitions for short branch methods | |
1541
b5fdf39b9749
6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents:
1489
diff
changeset
|
4047 bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) { |
0 | 4048 if (has_short_branch_form()) { |
4049 InstructForm *short_branch = short_branch_form(); | |
4050 const char *name = short_branch->_ident; | |
4051 | |
4052 // Construct short_branch_version() method. | |
4053 fprintf(fp_cpp, "// Build short branch version of this instruction\n"); | |
4054 fprintf(fp_cpp, "MachNode *%sNode::short_branch_version(Compile* C) {\n", this->_ident); | |
4055 // Create the MachNode object | |
4056 fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name); | |
4057 if( is_ideal_if() ) { | |
4058 fprintf(fp_cpp, " node->_prob = _prob;\n"); | |
4059 fprintf(fp_cpp, " node->_fcnt = _fcnt;\n"); | |
4060 } | |
4061 // Fill in the bottom_type where requested | |
1541
b5fdf39b9749
6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents:
1489
diff
changeset
|
4062 if ( this->captures_bottom_type(AD.globalNames()) ) { |
0 | 4063 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n"); |
4064 } | |
4065 | |
4066 fprintf(fp_cpp, "\n"); | |
4067 // Short branch version must use same node index for access | |
4068 // through allocator's tables | |
4069 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n"); | |
4070 fprintf(fp_cpp, " fill_new_machnode(node, C);\n"); | |
4071 | |
4072 // Return result and exit scope | |
4073 fprintf(fp_cpp, " return node;\n"); | |
4074 fprintf(fp_cpp, "}\n"); | |
4075 fprintf(fp_cpp,"\n"); | |
4076 return true; | |
4077 } | |
4078 return false; | |
4079 } | |
4080 | |
4081 | |
4082 //---------------------------buildMachNodeGenerator---------------------------- | |
4083 // Build switch to invoke appropriate "new" MachNode for an opcode | |
4084 void ArchDesc::buildMachNodeGenerator(FILE *fp_cpp) { | |
4085 | |
4086 // Build switch to invoke 'new' for a specific MachNode | |
4087 fprintf(fp_cpp, "\n"); | |
4088 fprintf(fp_cpp, "\n"); | |
4089 fprintf(fp_cpp, | |
4090 "//------------------------- MachNode Generator ---------------\n"); | |
4091 fprintf(fp_cpp, | |
4092 "// A switch statement on the dense-packed user-defined type system\n" | |
4093 "// that invokes 'new' on the corresponding class constructor.\n"); | |
4094 fprintf(fp_cpp, "\n"); | |
4095 fprintf(fp_cpp, "MachNode *State::MachNodeGenerator"); | |
4096 fprintf(fp_cpp, "(int opcode, Compile* C)"); | |
4097 fprintf(fp_cpp, "{\n"); | |
4098 fprintf(fp_cpp, " switch(opcode) {\n"); | |
4099 | |
4100 // Provide constructor for all user-defined instructions | |
4101 _instructions.reset(); | |
4102 int opIndex = operandFormCount(); | |
4103 InstructForm *inst; | |
4104 for( ; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { | |
4105 // Ensure that matrule is defined. | |
4106 if ( inst->_matrule == NULL ) continue; | |
4107 | |
4108 int opcode = opIndex++; | |
4109 const char *opClass = inst->_ident; | |
4110 char *opType = NULL; | |
4111 | |
4112 // Generate the case statement for this instruction | |
4113 fprintf(fp_cpp, " case %s_rule:", opClass); | |
4114 | |
4115 // Start local scope | |
6850 | 4116 fprintf(fp_cpp, " {\n"); |
0 | 4117 // Generate code to construct the new MachNode |
4118 buildMachNode(fp_cpp, inst, " "); | |
4119 // Return result and exit scope | |
4120 fprintf(fp_cpp, " return node;\n"); | |
4121 fprintf(fp_cpp, " }\n"); | |
4122 } | |
4123 | |
4124 // Generate the default case for switch(opcode) | |
4125 fprintf(fp_cpp, " \n"); | |
4126 fprintf(fp_cpp, " default:\n"); | |
4127 fprintf(fp_cpp, " fprintf(stderr, \"Default MachNode Generator invoked for: \\n\");\n"); | |
4128 fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%'); | |
4129 fprintf(fp_cpp, " break;\n"); | |
4130 fprintf(fp_cpp, " };\n"); | |
4131 | |
4132 // Generate the closing for method Matcher::MachNodeGenerator | |
4133 fprintf(fp_cpp, " return NULL;\n"); | |
4134 fprintf(fp_cpp, "}\n"); | |
4135 } | |
4136 | |
4137 | |
4138 //---------------------------buildInstructMatchCheck-------------------------- | |
4139 // Output the method to Matcher which checks whether or not a specific | |
4140 // instruction has a matching rule for the host architecture. | |
4141 void ArchDesc::buildInstructMatchCheck(FILE *fp_cpp) const { | |
4142 fprintf(fp_cpp, "\n\n"); | |
4143 fprintf(fp_cpp, "const bool Matcher::has_match_rule(int opcode) {\n"); | |
4144 fprintf(fp_cpp, " assert(_last_machine_leaf < opcode && opcode < _last_opcode, \"opcode in range\");\n"); | |
4145 fprintf(fp_cpp, " return _hasMatchRule[opcode];\n"); | |
4146 fprintf(fp_cpp, "}\n\n"); | |
4147 | |
4148 fprintf(fp_cpp, "const bool Matcher::_hasMatchRule[_last_opcode] = {\n"); | |
4149 int i; | |
4150 for (i = 0; i < _last_opcode - 1; i++) { | |
4151 fprintf(fp_cpp, " %-5s, // %s\n", | |
4152 _has_match_rule[i] ? "true" : "false", | |
4153 NodeClassNames[i]); | |
4154 } | |
4155 fprintf(fp_cpp, " %-5s // %s\n", | |
4156 _has_match_rule[i] ? "true" : "false", | |
4157 NodeClassNames[i]); | |
4158 fprintf(fp_cpp, "};\n"); | |
4159 } | |
4160 | |
4161 //---------------------------buildFrameMethods--------------------------------- | |
4162 // Output the methods to Matcher which specify frame behavior | |
4163 void ArchDesc::buildFrameMethods(FILE *fp_cpp) { | |
4164 fprintf(fp_cpp,"\n\n"); | |
4165 // Stack Direction | |
4166 fprintf(fp_cpp,"bool Matcher::stack_direction() const { return %s; }\n\n", | |
4167 _frame->_direction ? "true" : "false"); | |
4168 // Sync Stack Slots | |
4169 fprintf(fp_cpp,"int Compile::sync_stack_slots() const { return %s; }\n\n", | |
4170 _frame->_sync_stack_slots); | |
4171 // Java Stack Alignment | |
4172 fprintf(fp_cpp,"uint Matcher::stack_alignment_in_bytes() { return %s; }\n\n", | |
4173 _frame->_alignment); | |
4174 // Java Return Address Location | |
4175 fprintf(fp_cpp,"OptoReg::Name Matcher::return_addr() const {"); | |
4176 if (_frame->_return_addr_loc) { | |
4177 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", | |
4178 _frame->_return_addr); | |
4179 } | |
4180 else { | |
4181 fprintf(fp_cpp," return OptoReg::stack2reg(%s); }\n\n", | |
4182 _frame->_return_addr); | |
4183 } | |
4184 // Java Stack Slot Preservation | |
4185 fprintf(fp_cpp,"uint Compile::in_preserve_stack_slots() "); | |
4186 fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_in_preserve_slots); | |
4187 // Top Of Stack Slot Preservation, for both Java and C | |
4188 fprintf(fp_cpp,"uint Compile::out_preserve_stack_slots() "); | |
4189 fprintf(fp_cpp,"{ return SharedRuntime::out_preserve_stack_slots(); }\n\n"); | |
4190 // varargs C out slots killed | |
4191 fprintf(fp_cpp,"uint Compile::varargs_C_out_slots_killed() const "); | |
4192 fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_varargs_C_out_slots_killed); | |
4193 // Java Argument Position | |
4194 fprintf(fp_cpp,"void Matcher::calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length, bool is_outgoing) {\n"); | |
4195 fprintf(fp_cpp,"%s\n", _frame->_calling_convention); | |
4196 fprintf(fp_cpp,"}\n\n"); | |
4197 // Native Argument Position | |
4198 fprintf(fp_cpp,"void Matcher::c_calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length) {\n"); | |
4199 fprintf(fp_cpp,"%s\n", _frame->_c_calling_convention); | |
4200 fprintf(fp_cpp,"}\n\n"); | |
4201 // Java Return Value Location | |
4202 fprintf(fp_cpp,"OptoRegPair Matcher::return_value(int ideal_reg, bool is_outgoing) {\n"); | |
4203 fprintf(fp_cpp,"%s\n", _frame->_return_value); | |
4204 fprintf(fp_cpp,"}\n\n"); | |
4205 // Native Return Value Location | |
4206 fprintf(fp_cpp,"OptoRegPair Matcher::c_return_value(int ideal_reg, bool is_outgoing) {\n"); | |
4207 fprintf(fp_cpp,"%s\n", _frame->_c_return_value); | |
4208 fprintf(fp_cpp,"}\n\n"); | |
4209 | |
4210 // Inline Cache Register, mask definition, and encoding | |
4211 fprintf(fp_cpp,"OptoReg::Name Matcher::inline_cache_reg() {"); | |
4212 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", | |
4213 _frame->_inline_cache_reg); | |
4214 fprintf(fp_cpp,"int Matcher::inline_cache_reg_encode() {"); | |
4215 fprintf(fp_cpp," return _regEncode[inline_cache_reg()]; }\n\n"); | |
4216 | |
4217 // Interpreter's Method Oop Register, mask definition, and encoding | |
4218 fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_method_oop_reg() {"); | |
4219 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", | |
4220 _frame->_interpreter_method_oop_reg); | |
4221 fprintf(fp_cpp,"int Matcher::interpreter_method_oop_reg_encode() {"); | |
4222 fprintf(fp_cpp," return _regEncode[interpreter_method_oop_reg()]; }\n\n"); | |
4223 | |
4224 // Interpreter's Frame Pointer Register, mask definition, and encoding | |
4225 fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_frame_pointer_reg() {"); | |
4226 if (_frame->_interpreter_frame_pointer_reg == NULL) | |
4227 fprintf(fp_cpp," return OptoReg::Bad; }\n\n"); | |
4228 else | |
4229 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", | |
4230 _frame->_interpreter_frame_pointer_reg); | |
4231 | |
4232 // Frame Pointer definition | |
4233 /* CNC - I can not contemplate having a different frame pointer between | |
4234 Java and native code; makes my head hurt to think about it. | |
4235 fprintf(fp_cpp,"OptoReg::Name Matcher::frame_pointer() const {"); | |
4236 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", | |
4237 _frame->_frame_pointer); | |
4238 */ | |
4239 // (Native) Frame Pointer definition | |
4240 fprintf(fp_cpp,"OptoReg::Name Matcher::c_frame_pointer() const {"); | |
4241 fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", | |
4242 _frame->_frame_pointer); | |
4243 | |
4244 // Number of callee-save + always-save registers for calling convention | |
4245 fprintf(fp_cpp, "// Number of callee-save + always-save registers\n"); | |
4246 fprintf(fp_cpp, "int Matcher::number_of_saved_registers() {\n"); | |
4247 RegDef *rdef; | |
4248 int nof_saved_registers = 0; | |
4249 _register->reset_RegDefs(); | |
4250 while( (rdef = _register->iter_RegDefs()) != NULL ) { | |
4251 if( !strcmp(rdef->_callconv, "SOE") || !strcmp(rdef->_callconv, "AS") ) | |
4252 ++nof_saved_registers; | |
4253 } | |
4254 fprintf(fp_cpp, " return %d;\n", nof_saved_registers); | |
4255 fprintf(fp_cpp, "};\n\n"); | |
4256 } | |
4257 | |
4258 | |
4259 | |
4260 | |
4261 static int PrintAdlcCisc = 0; | |
4262 //---------------------------identify_cisc_spilling---------------------------- | |
4263 // Get info for the CISC_oracle and MachNode::cisc_version() | |
4264 void ArchDesc::identify_cisc_spill_instructions() { | |
4265 | |
6850 | 4266 if (_frame == NULL) |
4267 return; | |
4268 | |
0 | 4269 // Find the user-defined operand for cisc-spilling |
4270 if( _frame->_cisc_spilling_operand_name != NULL ) { | |
4271 const Form *form = _globalNames[_frame->_cisc_spilling_operand_name]; | |
4272 OperandForm *oper = form ? form->is_operand() : NULL; | |
4273 // Verify the user's suggestion | |
4274 if( oper != NULL ) { | |
4275 // Ensure that match field is defined. | |
4276 if ( oper->_matrule != NULL ) { | |
4277 MatchRule &mrule = *oper->_matrule; | |
4278 if( strcmp(mrule._opType,"AddP") == 0 ) { | |
4279 MatchNode *left = mrule._lChild; | |
4280 MatchNode *right= mrule._rChild; | |
4281 if( left != NULL && right != NULL ) { | |
4282 const Form *left_op = _globalNames[left->_opType]->is_operand(); | |
4283 const Form *right_op = _globalNames[right->_opType]->is_operand(); | |
4284 if( (left_op != NULL && right_op != NULL) | |
4285 && (left_op->interface_type(_globalNames) == Form::register_interface) | |
4286 && (right_op->interface_type(_globalNames) == Form::constant_interface) ) { | |
4287 // Successfully verified operand | |
4288 set_cisc_spill_operand( oper ); | |
4289 if( _cisc_spill_debug ) { | |
4290 fprintf(stderr, "\n\nVerified CISC-spill operand %s\n\n", oper->_ident); | |
4291 } | |
4292 } | |
4293 } | |
4294 } | |
4295 } | |
4296 } | |
4297 } | |
4298 | |
4299 if( cisc_spill_operand() != NULL ) { | |
4300 // N^2 comparison of instructions looking for a cisc-spilling version | |
4301 _instructions.reset(); | |
4302 InstructForm *instr; | |
4303 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
4304 // Ensure that match field is defined. | |
4305 if ( instr->_matrule == NULL ) continue; | |
4306 | |
4307 MatchRule &mrule = *instr->_matrule; | |
4308 Predicate *pred = instr->build_predicate(); | |
4309 | |
4310 // Grab the machine type of the operand | |
4311 const char *rootOp = instr->_ident; | |
4312 mrule._machType = rootOp; | |
4313 | |
4314 // Find result type for match | |
4315 const char *result = instr->reduce_result(); | |
4316 | |
4317 if( PrintAdlcCisc ) fprintf(stderr, " new instruction %s \n", instr->_ident ? instr->_ident : " "); | |
4318 bool found_cisc_alternate = false; | |
4319 _instructions.reset2(); | |
4320 InstructForm *instr2; | |
4321 for( ; !found_cisc_alternate && (instr2 = (InstructForm*)_instructions.iter2()) != NULL; ) { | |
4322 // Ensure that match field is defined. | |
4323 if( PrintAdlcCisc ) fprintf(stderr, " instr2 == %s \n", instr2->_ident ? instr2->_ident : " "); | |
4324 if ( instr2->_matrule != NULL | |
4325 && (instr != instr2 ) // Skip self | |
4326 && (instr2->reduce_result() != NULL) // want same result | |
4327 && (strcmp(result, instr2->reduce_result()) == 0)) { | |
4328 MatchRule &mrule2 = *instr2->_matrule; | |
4329 Predicate *pred2 = instr2->build_predicate(); | |
4330 found_cisc_alternate = instr->cisc_spills_to(*this, instr2); | |
4331 } | |
4332 } | |
4333 } | |
4334 } | |
4335 } | |
4336 | |
4337 //---------------------------build_cisc_spilling------------------------------- | |
4338 // Get info for the CISC_oracle and MachNode::cisc_version() | |
4339 void ArchDesc::build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp) { | |
4340 // Output the table for cisc spilling | |
4341 fprintf(fp_cpp, "// The following instructions can cisc-spill\n"); | |
4342 _instructions.reset(); | |
4343 InstructForm *inst = NULL; | |
4344 for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { | |
4345 // Ensure this is a machine-world instruction | |
4346 if ( inst->ideal_only() ) continue; | |
4347 const char *inst_name = inst->_ident; | |
4348 int operand = inst->cisc_spill_operand(); | |
4349 if( operand != AdlcVMDeps::Not_cisc_spillable ) { | |
4350 InstructForm *inst2 = inst->cisc_spill_alternate(); | |
4351 fprintf(fp_cpp, "// %s can cisc-spill operand %d to %s\n", inst->_ident, operand, inst2->_ident); | |
4352 } | |
4353 } | |
4354 fprintf(fp_cpp, "\n\n"); | |
4355 } | |
4356 | |
4357 //---------------------------identify_short_branches---------------------------- | |
4358 // Get info for our short branch replacement oracle. | |
4359 void ArchDesc::identify_short_branches() { | |
4360 // Walk over all instructions, checking to see if they match a short | |
4361 // branching alternate. | |
4362 _instructions.reset(); | |
4363 InstructForm *instr; | |
4364 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { | |
4365 // The instruction must have a match rule. | |
4366 if (instr->_matrule != NULL && | |
4367 instr->is_short_branch()) { | |
4368 | |
4369 _instructions.reset2(); | |
4370 InstructForm *instr2; | |
4371 while( (instr2 = (InstructForm*)_instructions.iter2()) != NULL ) { | |
4372 instr2->check_branch_variant(*this, instr); | |
4373 } | |
4374 } | |
4375 } | |
4376 } | |
4377 | |
4378 | |
4379 //---------------------------identify_unique_operands--------------------------- | |
4380 // Identify unique operands. | |
4381 void ArchDesc::identify_unique_operands() { | |
4382 // Walk over all instructions. | |
4383 _instructions.reset(); | |
4384 InstructForm *instr; | |
4385 while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { | |
4386 // Ensure this is a machine-world instruction | |
4387 if (!instr->ideal_only()) { | |
4388 instr->set_unique_opnds(); | |
4389 } | |
4390 } | |
4391 } |