Mercurial > hg > graal-compiler
annotate src/share/vm/adlc/output_h.cpp @ 367:194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
Reviewed-by: rasbold, jrose
author | never |
---|---|
date | Wed, 17 Sep 2008 12:59:52 -0700 |
parents | c3e045194476 |
children | 4d9884b01ba6 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1998-2008 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // output_h.cpp - Class HPP file output routines for architecture definition | |
26 #include "adlc.hpp" | |
27 | |
28 | |
29 // Generate the #define that describes the number of registers. | |
30 static void defineRegCount(FILE *fp, RegisterForm *registers) { | |
31 if (registers) { | |
32 int regCount = AdlcVMDeps::Physical + registers->_rdefs.count(); | |
33 fprintf(fp,"\n"); | |
34 fprintf(fp,"// the number of reserved registers + machine registers.\n"); | |
35 fprintf(fp,"#define REG_COUNT %d\n", regCount); | |
36 } | |
37 } | |
38 | |
39 // Output enumeration of machine register numbers | |
40 // (1) | |
41 // // Enumerate machine registers starting after reserved regs. | |
42 // // in the order of occurrence in the register block. | |
43 // enum MachRegisterNumbers { | |
44 // EAX_num = 0, | |
45 // ... | |
46 // _last_Mach_Reg | |
47 // } | |
48 void ArchDesc::buildMachRegisterNumbers(FILE *fp_hpp) { | |
49 if (_register) { | |
50 RegDef *reg_def = NULL; | |
51 | |
52 // Output a #define for the number of machine registers | |
53 defineRegCount(fp_hpp, _register); | |
54 | |
55 // Count all the Save_On_Entry and Always_Save registers | |
56 int saved_on_entry = 0; | |
57 int c_saved_on_entry = 0; | |
58 _register->reset_RegDefs(); | |
59 while( (reg_def = _register->iter_RegDefs()) != NULL ) { | |
60 if( strcmp(reg_def->_callconv,"SOE") == 0 || | |
61 strcmp(reg_def->_callconv,"AS") == 0 ) ++saved_on_entry; | |
62 if( strcmp(reg_def->_c_conv,"SOE") == 0 || | |
63 strcmp(reg_def->_c_conv,"AS") == 0 ) ++c_saved_on_entry; | |
64 } | |
65 fprintf(fp_hpp, "\n"); | |
66 fprintf(fp_hpp, "// the number of save_on_entry + always_saved registers.\n"); | |
67 fprintf(fp_hpp, "#define MAX_SAVED_ON_ENTRY_REG_COUNT %d\n", max(saved_on_entry,c_saved_on_entry)); | |
68 fprintf(fp_hpp, "#define SAVED_ON_ENTRY_REG_COUNT %d\n", saved_on_entry); | |
69 fprintf(fp_hpp, "#define C_SAVED_ON_ENTRY_REG_COUNT %d\n", c_saved_on_entry); | |
70 | |
71 // (1) | |
72 // Build definition for enumeration of register numbers | |
73 fprintf(fp_hpp, "\n"); | |
74 fprintf(fp_hpp, "// Enumerate machine register numbers starting after reserved regs.\n"); | |
75 fprintf(fp_hpp, "// in the order of occurrence in the register block.\n"); | |
76 fprintf(fp_hpp, "enum MachRegisterNumbers {\n"); | |
77 | |
78 // Output the register number for each register in the allocation classes | |
79 _register->reset_RegDefs(); | |
80 int i = 0; | |
81 while( (reg_def = _register->iter_RegDefs()) != NULL ) { | |
82 fprintf(fp_hpp," %s_num,\t\t// %d\n", reg_def->_regname, i++); | |
83 } | |
84 // Finish defining enumeration | |
85 fprintf(fp_hpp, " _last_Mach_Reg\t// %d\n", i); | |
86 fprintf(fp_hpp, "};\n"); | |
87 } | |
88 | |
89 fprintf(fp_hpp, "\n// Size of register-mask in ints\n"); | |
90 fprintf(fp_hpp, "#define RM_SIZE %d\n",RegisterForm::RegMask_Size()); | |
91 fprintf(fp_hpp, "// Unroll factor for loops over the data in a RegMask\n"); | |
92 fprintf(fp_hpp, "#define FORALL_BODY "); | |
93 int len = RegisterForm::RegMask_Size(); | |
94 for( int i = 0; i < len; i++ ) | |
95 fprintf(fp_hpp, "BODY(%d) ",i); | |
96 fprintf(fp_hpp, "\n\n"); | |
97 | |
98 fprintf(fp_hpp,"class RegMask;\n"); | |
99 // All RegMasks are declared "extern const ..." in ad_<arch>.hpp | |
100 // fprintf(fp_hpp,"extern RegMask STACK_OR_STACK_SLOTS_mask;\n\n"); | |
101 } | |
102 | |
103 | |
104 // Output enumeration of machine register encodings | |
105 // (2) | |
106 // // Enumerate machine registers starting after reserved regs. | |
107 // // in the order of occurrence in the alloc_class(es). | |
108 // enum MachRegisterEncodes { | |
109 // EAX_enc = 0x00, | |
110 // ... | |
111 // } | |
112 void ArchDesc::buildMachRegisterEncodes(FILE *fp_hpp) { | |
113 if (_register) { | |
114 RegDef *reg_def = NULL; | |
115 RegDef *reg_def_next = NULL; | |
116 | |
117 // (2) | |
118 // Build definition for enumeration of encode values | |
119 fprintf(fp_hpp, "\n"); | |
120 fprintf(fp_hpp, "// Enumerate machine registers starting after reserved regs.\n"); | |
121 fprintf(fp_hpp, "// in the order of occurrence in the alloc_class(es).\n"); | |
122 fprintf(fp_hpp, "enum MachRegisterEncodes {\n"); | |
123 | |
124 // Output the register encoding for each register in the allocation classes | |
125 _register->reset_RegDefs(); | |
126 reg_def_next = _register->iter_RegDefs(); | |
127 while( (reg_def = reg_def_next) != NULL ) { | |
128 reg_def_next = _register->iter_RegDefs(); | |
129 fprintf(fp_hpp," %s_enc = %s%s\n", | |
130 reg_def->_regname, reg_def->register_encode(), reg_def_next == NULL? "" : "," ); | |
131 } | |
132 // Finish defining enumeration | |
133 fprintf(fp_hpp, "};\n"); | |
134 | |
135 } // Done with register form | |
136 } | |
137 | |
138 | |
139 // Declare an array containing the machine register names, strings. | |
140 static void declareRegNames(FILE *fp, RegisterForm *registers) { | |
141 if (registers) { | |
142 // fprintf(fp,"\n"); | |
143 // fprintf(fp,"// An array of character pointers to machine register names.\n"); | |
144 // fprintf(fp,"extern const char *regName[];\n"); | |
145 } | |
146 } | |
147 | |
148 // Declare an array containing the machine register sizes in 32-bit words. | |
149 void ArchDesc::declareRegSizes(FILE *fp) { | |
150 // regSize[] is not used | |
151 } | |
152 | |
153 // Declare an array containing the machine register encoding values | |
154 static void declareRegEncodes(FILE *fp, RegisterForm *registers) { | |
155 if (registers) { | |
156 // // // | |
157 // fprintf(fp,"\n"); | |
158 // fprintf(fp,"// An array containing the machine register encode values\n"); | |
159 // fprintf(fp,"extern const char regEncode[];\n"); | |
160 } | |
161 } | |
162 | |
163 | |
164 // --------------------------------------------------------------------------- | |
165 //------------------------------Utilities to build Instruction Classes-------- | |
166 // --------------------------------------------------------------------------- | |
167 static void out_RegMask(FILE *fp) { | |
168 fprintf(fp," virtual const RegMask &out_RegMask() const;\n"); | |
169 } | |
170 | |
171 // --------------------------------------------------------------------------- | |
172 //--------Utilities to build MachOper and MachNode derived Classes------------ | |
173 // --------------------------------------------------------------------------- | |
174 | |
175 //------------------------------Utilities to build Operand Classes------------ | |
176 static void in_RegMask(FILE *fp) { | |
177 fprintf(fp," virtual const RegMask *in_RegMask(int index) const;\n"); | |
178 } | |
179 | |
180 static void declare_hash(FILE *fp) { | |
181 fprintf(fp," virtual uint hash() const;\n"); | |
182 } | |
183 | |
184 static void declare_cmp(FILE *fp) { | |
185 fprintf(fp," virtual uint cmp( const MachOper &oper ) const;\n"); | |
186 } | |
187 | |
188 static void declareConstStorage(FILE *fp, FormDict &globals, OperandForm *oper) { | |
189 int i = 0; | |
190 Component *comp; | |
191 | |
192 if (oper->num_consts(globals) == 0) return; | |
193 // Iterate over the component list looking for constants | |
194 oper->_components.reset(); | |
195 if ((comp = oper->_components.iter()) == NULL) { | |
196 assert(oper->num_consts(globals) == 1, "Bad component list detected.\n"); | |
197 const char *type = oper->ideal_type(globals); | |
198 if (!strcmp(type, "ConI")) { | |
199 if (i > 0) fprintf(fp,", "); | |
200 fprintf(fp," int32 _c%d;\n", i); | |
201 } | |
202 else if (!strcmp(type, "ConP")) { | |
203 if (i > 0) fprintf(fp,", "); | |
204 fprintf(fp," const TypePtr *_c%d;\n", i); | |
205 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
206 else if (!strcmp(type, "ConN")) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
207 if (i > 0) fprintf(fp,", "); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
208 fprintf(fp," const TypeNarrowOop *_c%d;\n", i); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
209 } |
0 | 210 else if (!strcmp(type, "ConL")) { |
211 if (i > 0) fprintf(fp,", "); | |
212 fprintf(fp," jlong _c%d;\n", i); | |
213 } | |
214 else if (!strcmp(type, "ConF")) { | |
215 if (i > 0) fprintf(fp,", "); | |
216 fprintf(fp," jfloat _c%d;\n", i); | |
217 } | |
218 else if (!strcmp(type, "ConD")) { | |
219 if (i > 0) fprintf(fp,", "); | |
220 fprintf(fp," jdouble _c%d;\n", i); | |
221 } | |
222 else if (!strcmp(type, "Bool")) { | |
223 fprintf(fp,"private:\n"); | |
224 fprintf(fp," BoolTest::mask _c%d;\n", i); | |
225 fprintf(fp,"public:\n"); | |
226 } | |
227 else { | |
228 assert(0, "Non-constant operand lacks component list."); | |
229 } | |
230 } // end if NULL | |
231 else { | |
232 oper->_components.reset(); | |
233 while ((comp = oper->_components.iter()) != NULL) { | |
234 if (!strcmp(comp->base_type(globals), "ConI")) { | |
235 fprintf(fp," jint _c%d;\n", i); | |
236 i++; | |
237 } | |
238 else if (!strcmp(comp->base_type(globals), "ConP")) { | |
239 fprintf(fp," const TypePtr *_c%d;\n", i); | |
240 i++; | |
241 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
242 else if (!strcmp(comp->base_type(globals), "ConN")) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
243 fprintf(fp," const TypePtr *_c%d;\n", i); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
244 i++; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
245 } |
0 | 246 else if (!strcmp(comp->base_type(globals), "ConL")) { |
247 fprintf(fp," jlong _c%d;\n", i); | |
248 i++; | |
249 } | |
250 else if (!strcmp(comp->base_type(globals), "ConF")) { | |
251 fprintf(fp," jfloat _c%d;\n", i); | |
252 i++; | |
253 } | |
254 else if (!strcmp(comp->base_type(globals), "ConD")) { | |
255 fprintf(fp," jdouble _c%d;\n", i); | |
256 i++; | |
257 } | |
258 } | |
259 } | |
260 } | |
261 | |
262 // Declare constructor. | |
263 // Parameters start with condition code, then all other constants | |
264 // | |
265 // (0) public: | |
266 // (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn) | |
267 // (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { } | |
268 // | |
269 static void defineConstructor(FILE *fp, const char *name, uint num_consts, | |
270 ComponentList &lst, bool is_ideal_bool, | |
271 Form::DataType constant_type, FormDict &globals) { | |
272 fprintf(fp,"public:\n"); | |
273 // generate line (1) | |
274 fprintf(fp," %sOper(", name); | |
275 if( num_consts == 0 ) { | |
276 fprintf(fp,") {}\n"); | |
277 return; | |
278 } | |
279 | |
280 // generate parameters for constants | |
281 uint i = 0; | |
282 Component *comp; | |
283 lst.reset(); | |
284 if ((comp = lst.iter()) == NULL) { | |
285 assert(num_consts == 1, "Bad component list detected.\n"); | |
286 switch( constant_type ) { | |
287 case Form::idealI : { | |
288 fprintf(fp,is_ideal_bool ? "BoolTest::mask c%d" : "int32 c%d", i); | |
289 break; | |
290 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
291 case Form::idealN : { fprintf(fp,"const TypeNarrowOop *c%d", i); break; } |
0 | 292 case Form::idealP : { fprintf(fp,"const TypePtr *c%d", i); break; } |
293 case Form::idealL : { fprintf(fp,"jlong c%d", i); break; } | |
294 case Form::idealF : { fprintf(fp,"jfloat c%d", i); break; } | |
295 case Form::idealD : { fprintf(fp,"jdouble c%d", i); break; } | |
296 default: | |
297 assert(!is_ideal_bool, "Non-constant operand lacks component list."); | |
298 break; | |
299 } | |
300 } // end if NULL | |
301 else { | |
302 lst.reset(); | |
303 while((comp = lst.iter()) != NULL) { | |
304 if (!strcmp(comp->base_type(globals), "ConI")) { | |
305 if (i > 0) fprintf(fp,", "); | |
306 fprintf(fp,"int32 c%d", i); | |
307 i++; | |
308 } | |
309 else if (!strcmp(comp->base_type(globals), "ConP")) { | |
310 if (i > 0) fprintf(fp,", "); | |
311 fprintf(fp,"const TypePtr *c%d", i); | |
312 i++; | |
313 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
314 else if (!strcmp(comp->base_type(globals), "ConN")) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
315 if (i > 0) fprintf(fp,", "); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
316 fprintf(fp,"const TypePtr *c%d", i); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
317 i++; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
318 } |
0 | 319 else if (!strcmp(comp->base_type(globals), "ConL")) { |
320 if (i > 0) fprintf(fp,", "); | |
321 fprintf(fp,"jlong c%d", i); | |
322 i++; | |
323 } | |
324 else if (!strcmp(comp->base_type(globals), "ConF")) { | |
325 if (i > 0) fprintf(fp,", "); | |
326 fprintf(fp,"jfloat c%d", i); | |
327 i++; | |
328 } | |
329 else if (!strcmp(comp->base_type(globals), "ConD")) { | |
330 if (i > 0) fprintf(fp,", "); | |
331 fprintf(fp,"jdouble c%d", i); | |
332 i++; | |
333 } | |
334 else if (!strcmp(comp->base_type(globals), "Bool")) { | |
335 if (i > 0) fprintf(fp,", "); | |
336 fprintf(fp,"BoolTest::mask c%d", i); | |
337 i++; | |
338 } | |
339 } | |
340 } | |
341 // finish line (1) and start line (2) | |
342 fprintf(fp,") : "); | |
343 // generate initializers for constants | |
344 i = 0; | |
345 fprintf(fp,"_c%d(c%d)", i, i); | |
346 for( i = 1; i < num_consts; ++i) { | |
347 fprintf(fp,", _c%d(c%d)", i, i); | |
348 } | |
349 // The body for the constructor is empty | |
350 fprintf(fp," {}\n"); | |
351 } | |
352 | |
353 // --------------------------------------------------------------------------- | |
354 // Utilities to generate format rules for machine operands and instructions | |
355 // --------------------------------------------------------------------------- | |
356 | |
357 // Generate the format rule for condition codes | |
358 static void defineCCodeDump(FILE *fp, int i) { | |
359 fprintf(fp, " if( _c%d == BoolTest::eq ) st->print(\"eq\");\n",i); | |
360 fprintf(fp, " else if( _c%d == BoolTest::ne ) st->print(\"ne\");\n",i); | |
361 fprintf(fp, " else if( _c%d == BoolTest::le ) st->print(\"le\");\n",i); | |
362 fprintf(fp, " else if( _c%d == BoolTest::ge ) st->print(\"ge\");\n",i); | |
363 fprintf(fp, " else if( _c%d == BoolTest::lt ) st->print(\"lt\");\n",i); | |
364 fprintf(fp, " else if( _c%d == BoolTest::gt ) st->print(\"gt\");\n",i); | |
365 } | |
366 | |
367 // Output code that dumps constant values, increment "i" if type is constant | |
368 static uint dump_spec_constant(FILE *fp, const char *ideal_type, uint i) { | |
369 if (!strcmp(ideal_type, "ConI")) { | |
370 fprintf(fp," st->print(\"#%%d\", _c%d);\n", i); | |
371 ++i; | |
372 } | |
373 else if (!strcmp(ideal_type, "ConP")) { | |
374 fprintf(fp," _c%d->dump_on(st);\n", i); | |
375 ++i; | |
376 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
377 else if (!strcmp(ideal_type, "ConN")) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
378 fprintf(fp," _c%d->dump();\n", i); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
379 ++i; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
380 } |
0 | 381 else if (!strcmp(ideal_type, "ConL")) { |
382 fprintf(fp," st->print(\"#\" INT64_FORMAT, _c%d);\n", i); | |
383 ++i; | |
384 } | |
385 else if (!strcmp(ideal_type, "ConF")) { | |
386 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i); | |
387 ++i; | |
388 } | |
389 else if (!strcmp(ideal_type, "ConD")) { | |
390 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i); | |
391 ++i; | |
392 } | |
393 else if (!strcmp(ideal_type, "Bool")) { | |
394 defineCCodeDump(fp,i); | |
395 ++i; | |
396 } | |
397 | |
398 return i; | |
399 } | |
400 | |
401 // Generate the format rule for an operand | |
402 void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) { | |
403 if (!for_c_file) { | |
404 // invoked after output #ifndef PRODUCT to ad_<arch>.hpp | |
405 // compile the bodies separately, to cut down on recompilations | |
406 fprintf(fp," virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n"); | |
407 fprintf(fp," virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n"); | |
408 return; | |
409 } | |
410 | |
411 // Local pointer indicates remaining part of format rule | |
412 uint idx = 0; // position of operand in match rule | |
413 | |
414 // Generate internal format function, used when stored locally | |
415 fprintf(fp, "\n#ifndef PRODUCT\n"); | |
416 fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident); | |
417 // Generate the user-defined portion of the format | |
418 if (oper._format) { | |
419 if ( oper._format->_strings.count() != 0 ) { | |
420 // No initialization code for int_format | |
421 | |
422 // Build the format from the entries in strings and rep_vars | |
423 const char *string = NULL; | |
424 oper._format->_rep_vars.reset(); | |
425 oper._format->_strings.reset(); | |
426 while ( (string = oper._format->_strings.iter()) != NULL ) { | |
427 fprintf(fp," "); | |
428 | |
429 // Check if this is a standard string or a replacement variable | |
430 if ( string != NameList::_signal ) { | |
431 // Normal string | |
432 // Pass through to st->print | |
433 fprintf(fp,"st->print(\"%s\");\n", string); | |
434 } else { | |
435 // Replacement variable | |
436 const char *rep_var = oper._format->_rep_vars.iter(); | |
437 // Check that it is a local name, and an operand | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
438 const Form* form = oper._localNames[rep_var]; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
439 if (form == NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
440 globalAD->syntax_err(oper._linenum, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
441 "\'%s\' not found in format for %s\n", rep_var, oper._ident); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
442 assert(form, "replacement variable was not found in local names"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
443 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
444 OperandForm *op = form->is_operand(); |
0 | 445 // Get index if register or constant |
446 if ( op->_matrule && op->_matrule->is_base_register(globals) ) { | |
447 idx = oper.register_position( globals, rep_var); | |
448 } | |
449 else if (op->_matrule && op->_matrule->is_base_constant(globals)) { | |
450 idx = oper.constant_position( globals, rep_var); | |
451 } else { | |
452 idx = 0; | |
453 } | |
454 | |
455 // output invocation of "$..."s format function | |
456 if ( op != NULL ) op->int_format(fp, globals, idx); | |
457 | |
458 if ( idx == -1 ) { | |
459 fprintf(stderr, | |
460 "Using a name, %s, that isn't in match rule\n", rep_var); | |
461 assert( strcmp(op->_ident,"label")==0, "Unimplemented"); | |
462 } | |
463 } // Done with a replacement variable | |
464 } // Done with all format strings | |
465 } else { | |
466 // Default formats for base operands (RegI, RegP, ConI, ConP, ...) | |
467 oper.int_format(fp, globals, 0); | |
468 } | |
469 | |
470 } else { // oper._format == NULL | |
471 // Provide a few special case formats where the AD writer cannot. | |
472 if ( strcmp(oper._ident,"Universe")==0 ) { | |
473 fprintf(fp, " st->print(\"$$univ\");\n"); | |
474 } | |
475 // labelOper::int_format is defined in ad_<...>.cpp | |
476 } | |
477 // ALWAYS! Provide a special case output for condition codes. | |
478 if( oper.is_ideal_bool() ) { | |
479 defineCCodeDump(fp,0); | |
480 } | |
481 fprintf(fp,"}\n"); | |
482 | |
483 // Generate external format function, when data is stored externally | |
484 fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident); | |
485 // Generate the user-defined portion of the format | |
486 if (oper._format) { | |
487 if ( oper._format->_strings.count() != 0 ) { | |
488 | |
489 // Check for a replacement string "$..." | |
490 if ( oper._format->_rep_vars.count() != 0 ) { | |
491 // Initialization code for ext_format | |
492 } | |
493 | |
494 // Build the format from the entries in strings and rep_vars | |
495 const char *string = NULL; | |
496 oper._format->_rep_vars.reset(); | |
497 oper._format->_strings.reset(); | |
498 while ( (string = oper._format->_strings.iter()) != NULL ) { | |
499 fprintf(fp," "); | |
500 | |
501 // Check if this is a standard string or a replacement variable | |
502 if ( string != NameList::_signal ) { | |
503 // Normal string | |
504 // Pass through to st->print | |
505 fprintf(fp,"st->print(\"%s\");\n", string); | |
506 } else { | |
507 // Replacement variable | |
508 const char *rep_var = oper._format->_rep_vars.iter(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
509 // Check that it is a local name, and an operand |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
510 const Form* form = oper._localNames[rep_var]; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
511 if (form == NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
512 globalAD->syntax_err(oper._linenum, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
513 "\'%s\' not found in format for %s\n", rep_var, oper._ident); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
514 assert(form, "replacement variable was not found in local names"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
515 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
516 OperandForm *op = form->is_operand(); |
0 | 517 // Get index if register or constant |
518 if ( op->_matrule && op->_matrule->is_base_register(globals) ) { | |
519 idx = oper.register_position( globals, rep_var); | |
520 } | |
521 else if (op->_matrule && op->_matrule->is_base_constant(globals)) { | |
522 idx = oper.constant_position( globals, rep_var); | |
523 } else { | |
524 idx = 0; | |
525 } | |
526 // output invocation of "$..."s format function | |
527 if ( op != NULL ) op->ext_format(fp, globals, idx); | |
528 | |
529 // Lookup the index position of the replacement variable | |
530 idx = oper._components.operand_position_format(rep_var); | |
531 if ( idx == -1 ) { | |
532 fprintf(stderr, | |
533 "Using a name, %s, that isn't in match rule\n", rep_var); | |
534 assert( strcmp(op->_ident,"label")==0, "Unimplemented"); | |
535 } | |
536 } // Done with a replacement variable | |
537 } // Done with all format strings | |
538 | |
539 } else { | |
540 // Default formats for base operands (RegI, RegP, ConI, ConP, ...) | |
541 oper.ext_format(fp, globals, 0); | |
542 } | |
543 } else { // oper._format == NULL | |
544 // Provide a few special case formats where the AD writer cannot. | |
545 if ( strcmp(oper._ident,"Universe")==0 ) { | |
546 fprintf(fp, " st->print(\"$$univ\");\n"); | |
547 } | |
548 // labelOper::ext_format is defined in ad_<...>.cpp | |
549 } | |
550 // ALWAYS! Provide a special case output for condition codes. | |
551 if( oper.is_ideal_bool() ) { | |
552 defineCCodeDump(fp,0); | |
553 } | |
554 fprintf(fp, "}\n"); | |
555 fprintf(fp, "#endif\n"); | |
556 } | |
557 | |
558 | |
559 // Generate the format rule for an instruction | |
560 void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &inst, bool for_c_file = false) { | |
561 if (!for_c_file) { | |
562 // compile the bodies separately, to cut down on recompilations | |
563 // #ifndef PRODUCT region generated by caller | |
564 fprintf(fp," virtual void format(PhaseRegAlloc *ra, outputStream *st) const;\n"); | |
565 return; | |
566 } | |
567 | |
568 // Define the format function | |
569 fprintf(fp, "#ifndef PRODUCT\n"); | |
570 fprintf(fp, "void %sNode::format(PhaseRegAlloc *ra, outputStream *st) const {\n", inst._ident); | |
571 | |
572 // Generate the user-defined portion of the format | |
573 if( inst._format ) { | |
574 // If there are replacement variables, | |
575 // Generate index values needed for determing the operand position | |
576 if( inst._format->_rep_vars.count() ) | |
577 inst.index_temps(fp, globals); | |
578 | |
579 // Build the format from the entries in strings and rep_vars | |
580 const char *string = NULL; | |
581 inst._format->_rep_vars.reset(); | |
582 inst._format->_strings.reset(); | |
583 while( (string = inst._format->_strings.iter()) != NULL ) { | |
584 fprintf(fp," "); | |
585 // Check if this is a standard string or a replacement variable | |
586 if( string != NameList::_signal ) // Normal string. Pass through. | |
587 fprintf(fp,"st->print(\"%s\");\n", string); | |
588 else // Replacement variable | |
589 inst.rep_var_format( fp, inst._format->_rep_vars.iter() ); | |
590 } // Done with all format strings | |
591 } // Done generating the user-defined portion of the format | |
592 | |
593 // Add call debug info automatically | |
594 Form::CallType call_type = inst.is_ideal_call(); | |
595 if( call_type != Form::invalid_type ) { | |
596 switch( call_type ) { | |
597 case Form::JAVA_DYNAMIC: | |
598 fprintf(fp," _method->print_short_name();\n"); | |
599 break; | |
600 case Form::JAVA_STATIC: | |
601 fprintf(fp," if( _method ) _method->print_short_name(st); else st->print(\" wrapper for: %%s\", _name);\n"); | |
602 fprintf(fp," if( !_method ) dump_trap_args(st);\n"); | |
603 break; | |
604 case Form::JAVA_COMPILED: | |
605 case Form::JAVA_INTERP: | |
606 break; | |
607 case Form::JAVA_RUNTIME: | |
608 case Form::JAVA_LEAF: | |
609 case Form::JAVA_NATIVE: | |
610 fprintf(fp," st->print(\" %%s\", _name);"); | |
611 break; | |
612 default: | |
613 assert(0,"ShouldNotReacHere"); | |
614 } | |
615 fprintf(fp, " st->print_cr(\"\");\n" ); | |
616 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" ); | |
617 fprintf(fp, " st->print(\" # \");\n" ); | |
618 fprintf(fp, " if( _jvms ) _oop_map->print_on(st);\n"); | |
619 } | |
620 else if(inst.is_ideal_safepoint()) { | |
621 fprintf(fp, " st->print(\"\");\n" ); | |
622 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" ); | |
623 fprintf(fp, " st->print(\" # \");\n" ); | |
624 fprintf(fp, " if( _jvms ) _oop_map->print_on(st);\n"); | |
625 } | |
626 else if( inst.is_ideal_if() ) { | |
627 fprintf(fp, " st->print(\" P=%%f C=%%f\",_prob,_fcnt);\n" ); | |
628 } | |
629 else if( inst.is_ideal_mem() ) { | |
630 // Print out the field name if available to improve readability | |
631 fprintf(fp, " if (ra->C->alias_type(adr_type())->field() != NULL) {\n"); | |
632 fprintf(fp, " st->print(\" ! Field \");\n"); | |
633 fprintf(fp, " if( ra->C->alias_type(adr_type())->is_volatile() )\n"); | |
634 fprintf(fp, " st->print(\" Volatile\");\n"); | |
635 fprintf(fp, " ra->C->alias_type(adr_type())->field()->holder()->name()->print_symbol_on(st);\n"); | |
636 fprintf(fp, " st->print(\".\");\n"); | |
637 fprintf(fp, " ra->C->alias_type(adr_type())->field()->name()->print_symbol_on(st);\n"); | |
638 fprintf(fp, " } else\n"); | |
639 // Make sure 'Volatile' gets printed out | |
640 fprintf(fp, " if( ra->C->alias_type(adr_type())->is_volatile() )\n"); | |
641 fprintf(fp, " st->print(\" Volatile!\");\n"); | |
642 } | |
643 | |
644 // Complete the definition of the format function | |
645 fprintf(fp, " }\n#endif\n"); | |
646 } | |
647 | |
648 static bool is_non_constant(char* x) { | |
649 // Tells whether the string (part of an operator interface) is non-constant. | |
650 // Simply detect whether there is an occurrence of a formal parameter, | |
651 // which will always begin with '$'. | |
652 return strchr(x, '$') == 0; | |
653 } | |
654 | |
655 void ArchDesc::declare_pipe_classes(FILE *fp_hpp) { | |
656 if (!_pipeline) | |
657 return; | |
658 | |
659 fprintf(fp_hpp, "\n"); | |
660 fprintf(fp_hpp, "// Pipeline_Use_Cycle_Mask Class\n"); | |
661 fprintf(fp_hpp, "class Pipeline_Use_Cycle_Mask {\n"); | |
662 | |
663 if (_pipeline->_maxcycleused <= | |
664 #ifdef SPARC | |
665 64 | |
666 #else | |
667 32 | |
668 #endif | |
669 ) { | |
670 fprintf(fp_hpp, "protected:\n"); | |
671 fprintf(fp_hpp, " %s _mask;\n\n", _pipeline->_maxcycleused <= 32 ? "uint" : "uint64_t" ); | |
672 fprintf(fp_hpp, "public:\n"); | |
673 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : _mask(0) {}\n\n"); | |
674 if (_pipeline->_maxcycleused <= 32) | |
675 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask) : _mask(mask) {}\n\n"); | |
676 else { | |
677 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n"); | |
678 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n"); | |
679 } | |
680 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n"); | |
681 fprintf(fp_hpp, " _mask = in._mask;\n"); | |
682 fprintf(fp_hpp, " return *this;\n"); | |
683 fprintf(fp_hpp, " }\n\n"); | |
684 fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n"); | |
685 fprintf(fp_hpp, " return ((_mask & in2._mask) != 0);\n"); | |
686 fprintf(fp_hpp, " }\n\n"); | |
687 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n"); | |
688 fprintf(fp_hpp, " _mask <<= n;\n"); | |
689 fprintf(fp_hpp, " return *this;\n"); | |
690 fprintf(fp_hpp, " }\n\n"); | |
691 fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &in2) {\n"); | |
692 fprintf(fp_hpp, " _mask |= in2._mask;\n"); | |
693 fprintf(fp_hpp, " }\n\n"); | |
694 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n"); | |
695 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n"); | |
696 } | |
697 else { | |
698 fprintf(fp_hpp, "protected:\n"); | |
699 uint masklen = (_pipeline->_maxcycleused + 31) >> 5; | |
700 uint l; | |
701 fprintf(fp_hpp, " uint "); | |
702 for (l = 1; l <= masklen; l++) | |
703 fprintf(fp_hpp, "_mask%d%s", l, l < masklen ? ", " : ";\n\n"); | |
704 fprintf(fp_hpp, "public:\n"); | |
705 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : "); | |
706 for (l = 1; l <= masklen; l++) | |
707 fprintf(fp_hpp, "_mask%d(0)%s", l, l < masklen ? ", " : " {}\n\n"); | |
708 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask("); | |
709 for (l = 1; l <= masklen; l++) | |
710 fprintf(fp_hpp, "uint mask%d%s", l, l < masklen ? ", " : ") : "); | |
711 for (l = 1; l <= masklen; l++) | |
712 fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n"); | |
713 | |
714 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n"); | |
715 for (l = 1; l <= masklen; l++) | |
716 fprintf(fp_hpp, " _mask%d = in._mask%d;\n", l, l); | |
717 fprintf(fp_hpp, " return *this;\n"); | |
718 fprintf(fp_hpp, " }\n\n"); | |
719 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n"); | |
720 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask out;\n"); | |
721 for (l = 1; l <= masklen; l++) | |
722 fprintf(fp_hpp, " out._mask%d = _mask%d & in2._mask%d;\n", l, l, l); | |
723 fprintf(fp_hpp, " return out;\n"); | |
724 fprintf(fp_hpp, " }\n\n"); | |
725 fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n"); | |
726 fprintf(fp_hpp, " return ("); | |
727 for (l = 1; l <= masklen; l++) | |
728 fprintf(fp_hpp, "((_mask%d & in2._mask%d) != 0)%s", l, l, l < masklen ? " || " : ""); | |
729 fprintf(fp_hpp, ") ? true : false;\n"); | |
730 fprintf(fp_hpp, " }\n\n"); | |
731 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n"); | |
732 fprintf(fp_hpp, " if (n >= 32)\n"); | |
733 fprintf(fp_hpp, " do {\n "); | |
734 for (l = masklen; l > 1; l--) | |
735 fprintf(fp_hpp, " _mask%d = _mask%d;", l, l-1); | |
736 fprintf(fp_hpp, " _mask%d = 0;\n", 1); | |
737 fprintf(fp_hpp, " } while ((n -= 32) >= 32);\n\n"); | |
738 fprintf(fp_hpp, " if (n > 0) {\n"); | |
739 fprintf(fp_hpp, " uint m = 32 - n;\n"); | |
740 fprintf(fp_hpp, " uint mask = (1 << n) - 1;\n"); | |
741 fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n;\n", 2, 1, 1); | |
742 for (l = 2; l < masklen; l++) { | |
743 fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n; _mask%d |= temp%d;\n", l+1, l, l, l, l); | |
744 } | |
745 fprintf(fp_hpp, " _mask%d <<= n; _mask%d |= temp%d;\n", masklen, masklen, masklen); | |
746 fprintf(fp_hpp, " }\n"); | |
747 | |
748 fprintf(fp_hpp, " return *this;\n"); | |
749 fprintf(fp_hpp, " }\n\n"); | |
750 fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &);\n\n"); | |
751 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n"); | |
752 fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n"); | |
753 } | |
754 | |
755 fprintf(fp_hpp, " friend class Pipeline_Use;\n\n"); | |
756 fprintf(fp_hpp, " friend class Pipeline_Use_Element;\n\n"); | |
757 fprintf(fp_hpp, "};\n\n"); | |
758 | |
759 uint rescount = 0; | |
760 const char *resource; | |
761 | |
762 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { | |
763 int mask = _pipeline->_resdict[resource]->is_resource()->mask(); | |
764 if ((mask & (mask-1)) == 0) | |
765 rescount++; | |
766 } | |
767 | |
768 fprintf(fp_hpp, "// Pipeline_Use_Element Class\n"); | |
769 fprintf(fp_hpp, "class Pipeline_Use_Element {\n"); | |
770 fprintf(fp_hpp, "protected:\n"); | |
771 fprintf(fp_hpp, " // Mask of used functional units\n"); | |
772 fprintf(fp_hpp, " uint _used;\n\n"); | |
773 fprintf(fp_hpp, " // Lower and upper bound of functional unit number range\n"); | |
774 fprintf(fp_hpp, " uint _lb, _ub;\n\n"); | |
775 fprintf(fp_hpp, " // Indicates multiple functionals units available\n"); | |
776 fprintf(fp_hpp, " bool _multiple;\n\n"); | |
777 fprintf(fp_hpp, " // Mask of specific used cycles\n"); | |
778 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask _mask;\n\n"); | |
779 fprintf(fp_hpp, "public:\n"); | |
780 fprintf(fp_hpp, " Pipeline_Use_Element() {}\n\n"); | |
781 fprintf(fp_hpp, " Pipeline_Use_Element(uint used, uint lb, uint ub, bool multiple, Pipeline_Use_Cycle_Mask mask)\n"); | |
782 fprintf(fp_hpp, " : _used(used), _lb(lb), _ub(ub), _multiple(multiple), _mask(mask) {}\n\n"); | |
783 fprintf(fp_hpp, " uint used() const { return _used; }\n\n"); | |
784 fprintf(fp_hpp, " uint lowerBound() const { return _lb; }\n\n"); | |
785 fprintf(fp_hpp, " uint upperBound() const { return _ub; }\n\n"); | |
786 fprintf(fp_hpp, " bool multiple() const { return _multiple; }\n\n"); | |
787 fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask mask() const { return _mask; }\n\n"); | |
788 fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Element &in2) const {\n"); | |
789 fprintf(fp_hpp, " return ((_used & in2._used) != 0 && _mask.overlaps(in2._mask));\n"); | |
790 fprintf(fp_hpp, " }\n\n"); | |
791 fprintf(fp_hpp, " void step(uint cycles) {\n"); | |
792 fprintf(fp_hpp, " _used = 0;\n"); | |
793 fprintf(fp_hpp, " _mask <<= cycles;\n"); | |
794 fprintf(fp_hpp, " }\n\n"); | |
795 fprintf(fp_hpp, " friend class Pipeline_Use;\n"); | |
796 fprintf(fp_hpp, "};\n\n"); | |
797 | |
798 fprintf(fp_hpp, "// Pipeline_Use Class\n"); | |
799 fprintf(fp_hpp, "class Pipeline_Use {\n"); | |
800 fprintf(fp_hpp, "protected:\n"); | |
801 fprintf(fp_hpp, " // These resources can be used\n"); | |
802 fprintf(fp_hpp, " uint _resources_used;\n\n"); | |
803 fprintf(fp_hpp, " // These resources are used; excludes multiple choice functional units\n"); | |
804 fprintf(fp_hpp, " uint _resources_used_exclusively;\n\n"); | |
805 fprintf(fp_hpp, " // Number of elements\n"); | |
806 fprintf(fp_hpp, " uint _count;\n\n"); | |
807 fprintf(fp_hpp, " // This is the array of Pipeline_Use_Elements\n"); | |
808 fprintf(fp_hpp, " Pipeline_Use_Element * _elements;\n\n"); | |
809 fprintf(fp_hpp, "public:\n"); | |
810 fprintf(fp_hpp, " Pipeline_Use(uint resources_used, uint resources_used_exclusively, uint count, Pipeline_Use_Element *elements)\n"); | |
811 fprintf(fp_hpp, " : _resources_used(resources_used)\n"); | |
812 fprintf(fp_hpp, " , _resources_used_exclusively(resources_used_exclusively)\n"); | |
813 fprintf(fp_hpp, " , _count(count)\n"); | |
814 fprintf(fp_hpp, " , _elements(elements)\n"); | |
815 fprintf(fp_hpp, " {}\n\n"); | |
816 fprintf(fp_hpp, " uint resourcesUsed() const { return _resources_used; }\n\n"); | |
817 fprintf(fp_hpp, " uint resourcesUsedExclusively() const { return _resources_used_exclusively; }\n\n"); | |
818 fprintf(fp_hpp, " uint count() const { return _count; }\n\n"); | |
819 fprintf(fp_hpp, " Pipeline_Use_Element * element(uint i) const { return &_elements[i]; }\n\n"); | |
820 fprintf(fp_hpp, " uint full_latency(uint delay, const Pipeline_Use &pred) const;\n\n"); | |
821 fprintf(fp_hpp, " void add_usage(const Pipeline_Use &pred);\n\n"); | |
822 fprintf(fp_hpp, " void reset() {\n"); | |
823 fprintf(fp_hpp, " _resources_used = _resources_used_exclusively = 0;\n"); | |
824 fprintf(fp_hpp, " };\n\n"); | |
825 fprintf(fp_hpp, " void step(uint cycles) {\n"); | |
826 fprintf(fp_hpp, " reset();\n"); | |
827 fprintf(fp_hpp, " for (uint i = 0; i < %d; i++)\n", | |
828 rescount); | |
829 fprintf(fp_hpp, " (&_elements[i])->step(cycles);\n"); | |
830 fprintf(fp_hpp, " };\n\n"); | |
831 fprintf(fp_hpp, " static const Pipeline_Use elaborated_use;\n"); | |
832 fprintf(fp_hpp, " static const Pipeline_Use_Element elaborated_elements[%d];\n\n", | |
833 rescount); | |
834 fprintf(fp_hpp, " friend class Pipeline;\n"); | |
835 fprintf(fp_hpp, "};\n\n"); | |
836 | |
837 fprintf(fp_hpp, "// Pipeline Class\n"); | |
838 fprintf(fp_hpp, "class Pipeline {\n"); | |
839 fprintf(fp_hpp, "public:\n"); | |
840 | |
841 fprintf(fp_hpp, " static bool enabled() { return %s; }\n\n", | |
842 _pipeline ? "true" : "false" ); | |
843 | |
844 assert( _pipeline->_maxInstrsPerBundle && | |
845 ( _pipeline->_instrUnitSize || _pipeline->_bundleUnitSize) && | |
846 _pipeline->_instrFetchUnitSize && | |
847 _pipeline->_instrFetchUnits, | |
848 "unspecified pipeline architecture units"); | |
849 | |
850 uint unitSize = _pipeline->_instrUnitSize ? _pipeline->_instrUnitSize : _pipeline->_bundleUnitSize; | |
851 | |
852 fprintf(fp_hpp, " enum {\n"); | |
853 fprintf(fp_hpp, " _variable_size_instructions = %d,\n", | |
854 _pipeline->_variableSizeInstrs ? 1 : 0); | |
855 fprintf(fp_hpp, " _fixed_size_instructions = %d,\n", | |
856 _pipeline->_variableSizeInstrs ? 0 : 1); | |
857 fprintf(fp_hpp, " _branch_has_delay_slot = %d,\n", | |
858 _pipeline->_branchHasDelaySlot ? 1 : 0); | |
859 fprintf(fp_hpp, " _max_instrs_per_bundle = %d,\n", | |
860 _pipeline->_maxInstrsPerBundle); | |
861 fprintf(fp_hpp, " _max_bundles_per_cycle = %d,\n", | |
862 _pipeline->_maxBundlesPerCycle); | |
863 fprintf(fp_hpp, " _max_instrs_per_cycle = %d\n", | |
864 _pipeline->_maxBundlesPerCycle * _pipeline->_maxInstrsPerBundle); | |
865 fprintf(fp_hpp, " };\n\n"); | |
866 | |
867 fprintf(fp_hpp, " static bool instr_has_unit_size() { return %s; }\n\n", | |
868 _pipeline->_instrUnitSize != 0 ? "true" : "false" ); | |
869 if( _pipeline->_bundleUnitSize != 0 ) | |
870 if( _pipeline->_instrUnitSize != 0 ) | |
871 fprintf(fp_hpp, "// Individual Instructions may be bundled together by the hardware\n\n"); | |
872 else | |
873 fprintf(fp_hpp, "// Instructions exist only in bundles\n\n"); | |
874 else | |
875 fprintf(fp_hpp, "// Bundling is not supported\n\n"); | |
876 if( _pipeline->_instrUnitSize != 0 ) | |
877 fprintf(fp_hpp, " // Size of an instruction\n"); | |
878 else | |
879 fprintf(fp_hpp, " // Size of an individual instruction does not exist - unsupported\n"); | |
880 fprintf(fp_hpp, " static uint instr_unit_size() {"); | |
881 if( _pipeline->_instrUnitSize == 0 ) | |
882 fprintf(fp_hpp, " assert( false, \"Instructions are only in bundles\" );"); | |
883 fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_instrUnitSize); | |
884 | |
885 if( _pipeline->_bundleUnitSize != 0 ) | |
886 fprintf(fp_hpp, " // Size of a bundle\n"); | |
887 else | |
888 fprintf(fp_hpp, " // Bundles do not exist - unsupported\n"); | |
889 fprintf(fp_hpp, " static uint bundle_unit_size() {"); | |
890 if( _pipeline->_bundleUnitSize == 0 ) | |
891 fprintf(fp_hpp, " assert( false, \"Bundles are not supported\" );"); | |
892 fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_bundleUnitSize); | |
893 | |
894 fprintf(fp_hpp, " static bool requires_bundling() { return %s; }\n\n", | |
895 _pipeline->_bundleUnitSize != 0 && _pipeline->_instrUnitSize == 0 ? "true" : "false" ); | |
896 | |
897 fprintf(fp_hpp, "private:\n"); | |
898 fprintf(fp_hpp, " Pipeline(); // Not a legal constructor\n"); | |
899 fprintf(fp_hpp, "\n"); | |
900 fprintf(fp_hpp, " const unsigned char _read_stage_count;\n"); | |
901 fprintf(fp_hpp, " const unsigned char _write_stage;\n"); | |
902 fprintf(fp_hpp, " const unsigned char _fixed_latency;\n"); | |
903 fprintf(fp_hpp, " const unsigned char _instruction_count;\n"); | |
904 fprintf(fp_hpp, " const bool _has_fixed_latency;\n"); | |
905 fprintf(fp_hpp, " const bool _has_branch_delay;\n"); | |
906 fprintf(fp_hpp, " const bool _has_multiple_bundles;\n"); | |
907 fprintf(fp_hpp, " const bool _force_serialization;\n"); | |
908 fprintf(fp_hpp, " const bool _may_have_no_code;\n"); | |
909 fprintf(fp_hpp, " const enum machPipelineStages * const _read_stages;\n"); | |
910 fprintf(fp_hpp, " const enum machPipelineStages * const _resource_stage;\n"); | |
911 fprintf(fp_hpp, " const uint * const _resource_cycles;\n"); | |
912 fprintf(fp_hpp, " const Pipeline_Use _resource_use;\n"); | |
913 fprintf(fp_hpp, "\n"); | |
914 fprintf(fp_hpp, "public:\n"); | |
915 fprintf(fp_hpp, " Pipeline(uint write_stage,\n"); | |
916 fprintf(fp_hpp, " uint count,\n"); | |
917 fprintf(fp_hpp, " bool has_fixed_latency,\n"); | |
918 fprintf(fp_hpp, " uint fixed_latency,\n"); | |
919 fprintf(fp_hpp, " uint instruction_count,\n"); | |
920 fprintf(fp_hpp, " bool has_branch_delay,\n"); | |
921 fprintf(fp_hpp, " bool has_multiple_bundles,\n"); | |
922 fprintf(fp_hpp, " bool force_serialization,\n"); | |
923 fprintf(fp_hpp, " bool may_have_no_code,\n"); | |
924 fprintf(fp_hpp, " enum machPipelineStages * const dst,\n"); | |
925 fprintf(fp_hpp, " enum machPipelineStages * const stage,\n"); | |
926 fprintf(fp_hpp, " uint * const cycles,\n"); | |
927 fprintf(fp_hpp, " Pipeline_Use resource_use)\n"); | |
928 fprintf(fp_hpp, " : _write_stage(write_stage)\n"); | |
929 fprintf(fp_hpp, " , _read_stage_count(count)\n"); | |
930 fprintf(fp_hpp, " , _has_fixed_latency(has_fixed_latency)\n"); | |
931 fprintf(fp_hpp, " , _fixed_latency(fixed_latency)\n"); | |
932 fprintf(fp_hpp, " , _read_stages(dst)\n"); | |
933 fprintf(fp_hpp, " , _resource_stage(stage)\n"); | |
934 fprintf(fp_hpp, " , _resource_cycles(cycles)\n"); | |
935 fprintf(fp_hpp, " , _resource_use(resource_use)\n"); | |
936 fprintf(fp_hpp, " , _instruction_count(instruction_count)\n"); | |
937 fprintf(fp_hpp, " , _has_branch_delay(has_branch_delay)\n"); | |
938 fprintf(fp_hpp, " , _has_multiple_bundles(has_multiple_bundles)\n"); | |
939 fprintf(fp_hpp, " , _force_serialization(force_serialization)\n"); | |
940 fprintf(fp_hpp, " , _may_have_no_code(may_have_no_code)\n"); | |
941 fprintf(fp_hpp, " {};\n"); | |
942 fprintf(fp_hpp, "\n"); | |
943 fprintf(fp_hpp, " uint writeStage() const {\n"); | |
944 fprintf(fp_hpp, " return (_write_stage);\n"); | |
945 fprintf(fp_hpp, " }\n"); | |
946 fprintf(fp_hpp, "\n"); | |
947 fprintf(fp_hpp, " enum machPipelineStages readStage(int ndx) const {\n"); | |
948 fprintf(fp_hpp, " return (ndx < _read_stage_count ? _read_stages[ndx] : stage_undefined);"); | |
949 fprintf(fp_hpp, " }\n\n"); | |
950 fprintf(fp_hpp, " uint resourcesUsed() const {\n"); | |
951 fprintf(fp_hpp, " return _resource_use.resourcesUsed();\n }\n\n"); | |
952 fprintf(fp_hpp, " uint resourcesUsedExclusively() const {\n"); | |
953 fprintf(fp_hpp, " return _resource_use.resourcesUsedExclusively();\n }\n\n"); | |
954 fprintf(fp_hpp, " bool hasFixedLatency() const {\n"); | |
955 fprintf(fp_hpp, " return (_has_fixed_latency);\n }\n\n"); | |
956 fprintf(fp_hpp, " uint fixedLatency() const {\n"); | |
957 fprintf(fp_hpp, " return (_fixed_latency);\n }\n\n"); | |
958 fprintf(fp_hpp, " uint functional_unit_latency(uint start, const Pipeline *pred) const;\n\n"); | |
959 fprintf(fp_hpp, " uint operand_latency(uint opnd, const Pipeline *pred) const;\n\n"); | |
960 fprintf(fp_hpp, " const Pipeline_Use& resourceUse() const {\n"); | |
961 fprintf(fp_hpp, " return (_resource_use); }\n\n"); | |
962 fprintf(fp_hpp, " const Pipeline_Use_Element * resourceUseElement(uint i) const {\n"); | |
963 fprintf(fp_hpp, " return (&_resource_use._elements[i]); }\n\n"); | |
964 fprintf(fp_hpp, " uint resourceUseCount() const {\n"); | |
965 fprintf(fp_hpp, " return (_resource_use._count); }\n\n"); | |
966 fprintf(fp_hpp, " uint instructionCount() const {\n"); | |
967 fprintf(fp_hpp, " return (_instruction_count); }\n\n"); | |
968 fprintf(fp_hpp, " bool hasBranchDelay() const {\n"); | |
969 fprintf(fp_hpp, " return (_has_branch_delay); }\n\n"); | |
970 fprintf(fp_hpp, " bool hasMultipleBundles() const {\n"); | |
971 fprintf(fp_hpp, " return (_has_multiple_bundles); }\n\n"); | |
972 fprintf(fp_hpp, " bool forceSerialization() const {\n"); | |
973 fprintf(fp_hpp, " return (_force_serialization); }\n\n"); | |
974 fprintf(fp_hpp, " bool mayHaveNoCode() const {\n"); | |
975 fprintf(fp_hpp, " return (_may_have_no_code); }\n\n"); | |
976 fprintf(fp_hpp, "//const Pipeline_Use_Cycle_Mask& resourceUseMask(int resource) const {\n"); | |
977 fprintf(fp_hpp, "// return (_resource_use_masks[resource]); }\n\n"); | |
978 fprintf(fp_hpp, "\n#ifndef PRODUCT\n"); | |
979 fprintf(fp_hpp, " static const char * stageName(uint i);\n"); | |
980 fprintf(fp_hpp, "#endif\n"); | |
981 fprintf(fp_hpp, "};\n\n"); | |
982 | |
983 fprintf(fp_hpp, "// Bundle class\n"); | |
984 fprintf(fp_hpp, "class Bundle {\n"); | |
985 | |
986 uint mshift = 0; | |
987 for (uint msize = _pipeline->_maxInstrsPerBundle * _pipeline->_maxBundlesPerCycle; msize != 0; msize >>= 1) | |
988 mshift++; | |
989 | |
990 uint rshift = rescount; | |
991 | |
992 fprintf(fp_hpp, "protected:\n"); | |
993 fprintf(fp_hpp, " enum {\n"); | |
994 fprintf(fp_hpp, " _unused_delay = 0x%x,\n", 0); | |
995 fprintf(fp_hpp, " _use_nop_delay = 0x%x,\n", 1); | |
996 fprintf(fp_hpp, " _use_unconditional_delay = 0x%x,\n", 2); | |
997 fprintf(fp_hpp, " _use_conditional_delay = 0x%x,\n", 3); | |
998 fprintf(fp_hpp, " _used_in_conditional_delay = 0x%x,\n", 4); | |
999 fprintf(fp_hpp, " _used_in_unconditional_delay = 0x%x,\n", 5); | |
1000 fprintf(fp_hpp, " _used_in_all_conditional_delays = 0x%x,\n", 6); | |
1001 fprintf(fp_hpp, "\n"); | |
1002 fprintf(fp_hpp, " _use_delay = 0x%x,\n", 3); | |
1003 fprintf(fp_hpp, " _used_in_delay = 0x%x\n", 4); | |
1004 fprintf(fp_hpp, " };\n\n"); | |
1005 fprintf(fp_hpp, " uint _flags : 3,\n"); | |
1006 fprintf(fp_hpp, " _starts_bundle : 1,\n"); | |
1007 fprintf(fp_hpp, " _instr_count : %d,\n", mshift); | |
1008 fprintf(fp_hpp, " _resources_used : %d;\n", rshift); | |
1009 fprintf(fp_hpp, "public:\n"); | |
1010 fprintf(fp_hpp, " Bundle() : _flags(_unused_delay), _starts_bundle(0), _instr_count(0), _resources_used(0) {}\n\n"); | |
1011 fprintf(fp_hpp, " void set_instr_count(uint i) { _instr_count = i; }\n"); | |
1012 fprintf(fp_hpp, " void set_resources_used(uint i) { _resources_used = i; }\n"); | |
1013 fprintf(fp_hpp, " void clear_usage() { _flags = _unused_delay; }\n"); | |
1014 fprintf(fp_hpp, " void set_starts_bundle() { _starts_bundle = true; }\n"); | |
1015 | |
1016 fprintf(fp_hpp, " uint flags() const { return (_flags); }\n"); | |
1017 fprintf(fp_hpp, " uint instr_count() const { return (_instr_count); }\n"); | |
1018 fprintf(fp_hpp, " uint resources_used() const { return (_resources_used); }\n"); | |
1019 fprintf(fp_hpp, " bool starts_bundle() const { return (_starts_bundle != 0); }\n"); | |
1020 | |
1021 fprintf(fp_hpp, " void set_use_nop_delay() { _flags = _use_nop_delay; }\n"); | |
1022 fprintf(fp_hpp, " void set_use_unconditional_delay() { _flags = _use_unconditional_delay; }\n"); | |
1023 fprintf(fp_hpp, " void set_use_conditional_delay() { _flags = _use_conditional_delay; }\n"); | |
1024 fprintf(fp_hpp, " void set_used_in_unconditional_delay() { _flags = _used_in_unconditional_delay; }\n"); | |
1025 fprintf(fp_hpp, " void set_used_in_conditional_delay() { _flags = _used_in_conditional_delay; }\n"); | |
1026 fprintf(fp_hpp, " void set_used_in_all_conditional_delays() { _flags = _used_in_all_conditional_delays; }\n"); | |
1027 | |
1028 fprintf(fp_hpp, " bool use_nop_delay() { return (_flags == _use_nop_delay); }\n"); | |
1029 fprintf(fp_hpp, " bool use_unconditional_delay() { return (_flags == _use_unconditional_delay); }\n"); | |
1030 fprintf(fp_hpp, " bool use_conditional_delay() { return (_flags == _use_conditional_delay); }\n"); | |
1031 fprintf(fp_hpp, " bool used_in_unconditional_delay() { return (_flags == _used_in_unconditional_delay); }\n"); | |
1032 fprintf(fp_hpp, " bool used_in_conditional_delay() { return (_flags == _used_in_conditional_delay); }\n"); | |
1033 fprintf(fp_hpp, " bool used_in_all_conditional_delays() { return (_flags == _used_in_all_conditional_delays); }\n"); | |
1034 fprintf(fp_hpp, " bool use_delay() { return ((_flags & _use_delay) != 0); }\n"); | |
1035 fprintf(fp_hpp, " bool used_in_delay() { return ((_flags & _used_in_delay) != 0); }\n\n"); | |
1036 | |
1037 fprintf(fp_hpp, " enum {\n"); | |
1038 fprintf(fp_hpp, " _nop_count = %d\n", | |
1039 _pipeline->_nopcnt); | |
1040 fprintf(fp_hpp, " };\n\n"); | |
1041 fprintf(fp_hpp, " static void initialize_nops(MachNode *nop_list[%d], Compile* C);\n\n", | |
1042 _pipeline->_nopcnt); | |
1043 fprintf(fp_hpp, "#ifndef PRODUCT\n"); | |
1044 fprintf(fp_hpp, " void dump() const;\n"); | |
1045 fprintf(fp_hpp, "#endif\n"); | |
1046 fprintf(fp_hpp, "};\n\n"); | |
1047 | |
1048 // const char *classname; | |
1049 // for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) { | |
1050 // PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass(); | |
1051 // fprintf(fp_hpp, "// Pipeline Class Instance for \"%s\"\n", classname); | |
1052 // } | |
1053 } | |
1054 | |
1055 //------------------------------declareClasses--------------------------------- | |
1056 // Construct the class hierarchy of MachNode classes from the instruction & | |
1057 // operand lists | |
1058 void ArchDesc::declareClasses(FILE *fp) { | |
1059 | |
1060 // Declare an array containing the machine register names, strings. | |
1061 declareRegNames(fp, _register); | |
1062 | |
1063 // Declare an array containing the machine register encoding values | |
1064 declareRegEncodes(fp, _register); | |
1065 | |
1066 // Generate declarations for the total number of operands | |
1067 fprintf(fp,"\n"); | |
1068 fprintf(fp,"// Total number of operands defined in architecture definition\n"); | |
1069 int num_operands = 0; | |
1070 OperandForm *op; | |
1071 for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != NULL; ) { | |
1072 // Ensure this is a machine-world instruction | |
1073 if (op->ideal_only()) continue; | |
1074 | |
1075 ++num_operands; | |
1076 } | |
1077 int first_operand_class = num_operands; | |
1078 OpClassForm *opc; | |
1079 for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != NULL; ) { | |
1080 // Ensure this is a machine-world instruction | |
1081 if (opc->ideal_only()) continue; | |
1082 | |
1083 ++num_operands; | |
1084 } | |
1085 fprintf(fp,"#define FIRST_OPERAND_CLASS %d\n", first_operand_class); | |
1086 fprintf(fp,"#define NUM_OPERANDS %d\n", num_operands); | |
1087 fprintf(fp,"\n"); | |
1088 // Generate declarations for the total number of instructions | |
1089 fprintf(fp,"// Total number of instructions defined in architecture definition\n"); | |
1090 fprintf(fp,"#define NUM_INSTRUCTIONS %d\n",instructFormCount()); | |
1091 | |
1092 | |
1093 // Generate Machine Classes for each operand defined in AD file | |
1094 fprintf(fp,"\n"); | |
1095 fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n"); | |
1096 // Iterate through all operands | |
1097 _operands.reset(); | |
1098 OperandForm *oper; | |
1099 for( ; (oper = (OperandForm*)_operands.iter()) != NULL;) { | |
1100 // Ensure this is a machine-world instruction | |
1101 if (oper->ideal_only() ) continue; | |
1102 // The declaration of labelOper is in machine-independent file: machnode | |
1103 if ( strcmp(oper->_ident,"label") == 0 ) continue; | |
1104 // The declaration of methodOper is in machine-independent file: machnode | |
1105 if ( strcmp(oper->_ident,"method") == 0 ) continue; | |
1106 | |
1107 // Build class definition for this operand | |
1108 fprintf(fp,"\n"); | |
1109 fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident); | |
1110 fprintf(fp,"private:\n"); | |
1111 // Operand definitions that depend upon number of input edges | |
1112 { | |
1113 uint num_edges = oper->num_edges(_globalNames); | |
1114 if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;} | |
1115 fprintf(fp," virtual uint num_edges() const { return %d; }\n", | |
1116 num_edges ); | |
1117 } | |
1118 if( num_edges > 0 ) { | |
1119 in_RegMask(fp); | |
1120 } | |
1121 } | |
1122 | |
1123 // Support storing constants inside the MachOper | |
1124 declareConstStorage(fp,_globalNames,oper); | |
1125 | |
1126 // Support storage of the condition codes | |
1127 if( oper->is_ideal_bool() ) { | |
1128 fprintf(fp," virtual int ccode() const { \n"); | |
1129 fprintf(fp," switch (_c0) {\n"); | |
1130 fprintf(fp," case BoolTest::eq : return equal();\n"); | |
1131 fprintf(fp," case BoolTest::gt : return greater();\n"); | |
1132 fprintf(fp," case BoolTest::lt : return less();\n"); | |
1133 fprintf(fp," case BoolTest::ne : return not_equal();\n"); | |
1134 fprintf(fp," case BoolTest::le : return less_equal();\n"); | |
1135 fprintf(fp," case BoolTest::ge : return greater_equal();\n"); | |
1136 fprintf(fp," default : ShouldNotReachHere(); return 0;\n"); | |
1137 fprintf(fp," }\n"); | |
1138 fprintf(fp," };\n"); | |
1139 } | |
1140 | |
1141 // Support storage of the condition codes | |
1142 if( oper->is_ideal_bool() ) { | |
1143 fprintf(fp," virtual void negate() { \n"); | |
1144 fprintf(fp," _c0 = (BoolTest::mask)((int)_c0^0x4); \n"); | |
1145 fprintf(fp," };\n"); | |
1146 } | |
1147 | |
1148 // Declare constructor. | |
1149 // Parameters start with condition code, then all other constants | |
1150 // | |
1151 // (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn) | |
1152 // (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { } | |
1153 // | |
1154 Form::DataType constant_type = oper->simple_type(_globalNames); | |
1155 defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames), | |
1156 oper->_components, oper->is_ideal_bool(), | |
1157 constant_type, _globalNames); | |
1158 | |
1159 // Clone function | |
1160 fprintf(fp," virtual MachOper *clone(Compile* C) const;\n"); | |
1161 | |
1162 // Support setting a spill offset into a constant operand. | |
1163 // We only support setting an 'int' offset, while in the | |
1164 // LP64 build spill offsets are added with an AddP which | |
1165 // requires a long constant. Thus we don't support spilling | |
1166 // in frames larger than 4Gig. | |
1167 if( oper->has_conI(_globalNames) || | |
1168 oper->has_conL(_globalNames) ) | |
1169 fprintf(fp, " virtual void set_con( jint c0 ) { _c0 = c0; }\n"); | |
1170 | |
1171 // virtual functions for encoding and format | |
1172 // fprintf(fp," virtual void encode() const {\n %s }\n", | |
1173 // (oper->_encrule)?(oper->_encrule->_encrule):""); | |
1174 // Check the interface type, and generate the correct query functions | |
1175 // encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER. | |
1176 | |
1177 fprintf(fp," virtual uint opcode() const { return %s; }\n", | |
1178 machOperEnum(oper->_ident)); | |
1179 | |
1180 // virtual function to look up ideal return type of machine instruction | |
1181 // | |
1182 // (1) virtual const Type *type() const { return .....; } | |
1183 // | |
1184 if ((oper->_matrule) && (oper->_matrule->_lChild == NULL) && | |
1185 (oper->_matrule->_rChild == NULL)) { | |
1186 unsigned int position = 0; | |
1187 const char *opret, *opname, *optype; | |
1188 oper->_matrule->base_operand(position,_globalNames,opret,opname,optype); | |
1189 fprintf(fp," virtual const Type *type() const {"); | |
1190 const char *type = getIdealType(optype); | |
1191 if( type != NULL ) { | |
1192 Form::DataType data_type = oper->is_base_constant(_globalNames); | |
1193 // Check if we are an ideal pointer type | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1194 if( data_type == Form::idealP || data_type == Form::idealN ) { |
0 | 1195 // Return the ideal type we already have: <TypePtr *> |
1196 fprintf(fp," return _c0;"); | |
1197 } else { | |
1198 // Return the appropriate bottom type | |
1199 fprintf(fp," return %s;", getIdealType(optype)); | |
1200 } | |
1201 } else { | |
1202 fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;"); | |
1203 } | |
1204 fprintf(fp," }\n"); | |
1205 } else { | |
1206 // Check for user-defined stack slots, based upon sRegX | |
1207 Form::DataType data_type = oper->is_user_name_for_sReg(); | |
1208 if( data_type != Form::none ){ | |
1209 const char *type = NULL; | |
1210 switch( data_type ) { | |
1211 case Form::idealI: type = "TypeInt::INT"; break; | |
1212 case Form::idealP: type = "TypePtr::BOTTOM";break; | |
1213 case Form::idealF: type = "Type::FLOAT"; break; | |
1214 case Form::idealD: type = "Type::DOUBLE"; break; | |
1215 case Form::idealL: type = "TypeLong::LONG"; break; | |
1216 case Form::none: // fall through | |
1217 default: | |
1218 assert( false, "No support for this type of stackSlot"); | |
1219 } | |
1220 fprintf(fp," virtual const Type *type() const { return %s; } // stackSlotX\n", type); | |
1221 } | |
1222 } | |
1223 | |
1224 | |
1225 // | |
1226 // virtual functions for defining the encoding interface. | |
1227 // | |
1228 // Access the linearized ideal register mask, | |
1229 // map to physical register encoding | |
1230 if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) { | |
1231 // Just use the default virtual 'reg' call | |
1232 } else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) { | |
1233 // Special handling for operand 'sReg', a Stack Slot Register. | |
1234 // Map linearized ideal register mask to stack slot number | |
1235 fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node) const {\n"); | |
1236 fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n"); | |
1237 fprintf(fp," }\n"); | |
1238 fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n"); | |
1239 fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n"); | |
1240 fprintf(fp," }\n"); | |
1241 } | |
1242 | |
1243 // Output the operand specific access functions used by an enc_class | |
1244 // These are only defined when we want to override the default virtual func | |
1245 if (oper->_interface != NULL) { | |
1246 fprintf(fp,"\n"); | |
1247 // Check if it is a Memory Interface | |
1248 if ( oper->_interface->is_MemInterface() != NULL ) { | |
1249 MemInterface *mem_interface = oper->_interface->is_MemInterface(); | |
1250 const char *base = mem_interface->_base; | |
1251 if( base != NULL ) { | |
1252 define_oper_interface(fp, *oper, _globalNames, "base", base); | |
1253 } | |
1254 char *index = mem_interface->_index; | |
1255 if( index != NULL ) { | |
1256 define_oper_interface(fp, *oper, _globalNames, "index", index); | |
1257 } | |
1258 const char *scale = mem_interface->_scale; | |
1259 if( scale != NULL ) { | |
1260 define_oper_interface(fp, *oper, _globalNames, "scale", scale); | |
1261 } | |
1262 const char *disp = mem_interface->_disp; | |
1263 if( disp != NULL ) { | |
1264 define_oper_interface(fp, *oper, _globalNames, "disp", disp); | |
1265 oper->disp_is_oop(fp, _globalNames); | |
1266 } | |
1267 if( oper->stack_slots_only(_globalNames) ) { | |
1268 // should not call this: | |
1269 fprintf(fp," virtual int constant_disp() const { return Type::OffsetBot; }"); | |
1270 } else if ( disp != NULL ) { | |
1271 define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp); | |
1272 } | |
1273 } // end Memory Interface | |
1274 // Check if it is a Conditional Interface | |
1275 else if (oper->_interface->is_CondInterface() != NULL) { | |
1276 CondInterface *cInterface = oper->_interface->is_CondInterface(); | |
1277 const char *equal = cInterface->_equal; | |
1278 if( equal != NULL ) { | |
1279 define_oper_interface(fp, *oper, _globalNames, "equal", equal); | |
1280 } | |
1281 const char *not_equal = cInterface->_not_equal; | |
1282 if( not_equal != NULL ) { | |
1283 define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal); | |
1284 } | |
1285 const char *less = cInterface->_less; | |
1286 if( less != NULL ) { | |
1287 define_oper_interface(fp, *oper, _globalNames, "less", less); | |
1288 } | |
1289 const char *greater_equal = cInterface->_greater_equal; | |
1290 if( greater_equal != NULL ) { | |
1291 define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal); | |
1292 } | |
1293 const char *less_equal = cInterface->_less_equal; | |
1294 if( less_equal != NULL ) { | |
1295 define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal); | |
1296 } | |
1297 const char *greater = cInterface->_greater; | |
1298 if( greater != NULL ) { | |
1299 define_oper_interface(fp, *oper, _globalNames, "greater", greater); | |
1300 } | |
1301 } // end Conditional Interface | |
1302 // Check if it is a Constant Interface | |
1303 else if (oper->_interface->is_ConstInterface() != NULL ) { | |
1304 assert( oper->num_consts(_globalNames) == 1, | |
1305 "Must have one constant when using CONST_INTER encoding"); | |
1306 if (!strcmp(oper->ideal_type(_globalNames), "ConI")) { | |
1307 // Access the locally stored constant | |
1308 fprintf(fp," virtual intptr_t constant() const {"); | |
1309 fprintf(fp, " return (intptr_t)_c0;"); | |
1310 fprintf(fp," }\n"); | |
1311 } | |
1312 else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) { | |
1313 // Access the locally stored constant | |
1314 fprintf(fp," virtual intptr_t constant() const {"); | |
1315 fprintf(fp, " return _c0->get_con();"); | |
1316 fprintf(fp, " }\n"); | |
1317 // Generate query to determine if this pointer is an oop | |
1318 fprintf(fp," virtual bool constant_is_oop() const {"); | |
1319 fprintf(fp, " return _c0->isa_oop_ptr();"); | |
1320 fprintf(fp, " }\n"); | |
1321 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1322 else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1323 // Access the locally stored constant |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1324 fprintf(fp," virtual intptr_t constant() const {"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1325 fprintf(fp, " return _c0->make_oopptr()->get_con();"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1326 fprintf(fp, " }\n"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1327 // Generate query to determine if this pointer is an oop |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1328 fprintf(fp," virtual bool constant_is_oop() const {"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1329 fprintf(fp, " return _c0->make_oopptr()->isa_oop_ptr();"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1330 fprintf(fp, " }\n"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1331 } |
0 | 1332 else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) { |
1333 fprintf(fp," virtual intptr_t constant() const {"); | |
1334 // We don't support addressing modes with > 4Gig offsets. | |
1335 // Truncate to int. | |
1336 fprintf(fp, " return (intptr_t)_c0;"); | |
1337 fprintf(fp, " }\n"); | |
1338 fprintf(fp," virtual jlong constantL() const {"); | |
1339 fprintf(fp, " return _c0;"); | |
1340 fprintf(fp, " }\n"); | |
1341 } | |
1342 else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) { | |
1343 fprintf(fp," virtual intptr_t constant() const {"); | |
1344 fprintf(fp, " ShouldNotReachHere(); return 0; "); | |
1345 fprintf(fp, " }\n"); | |
1346 fprintf(fp," virtual jfloat constantF() const {"); | |
1347 fprintf(fp, " return (jfloat)_c0;"); | |
1348 fprintf(fp, " }\n"); | |
1349 } | |
1350 else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) { | |
1351 fprintf(fp," virtual intptr_t constant() const {"); | |
1352 fprintf(fp, " ShouldNotReachHere(); return 0; "); | |
1353 fprintf(fp, " }\n"); | |
1354 fprintf(fp," virtual jdouble constantD() const {"); | |
1355 fprintf(fp, " return _c0;"); | |
1356 fprintf(fp, " }\n"); | |
1357 } | |
1358 } | |
1359 else if (oper->_interface->is_RegInterface() != NULL) { | |
1360 // make sure that a fixed format string isn't used for an | |
1361 // operand which might be assiged to multiple registers. | |
1362 // Otherwise the opto assembly output could be misleading. | |
1363 if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) { | |
1364 syntax_err(oper->_linenum, | |
1365 "Only bound registers can have fixed formats: %s\n", | |
1366 oper->_ident); | |
1367 } | |
1368 } | |
1369 else { | |
1370 assert( false, "ShouldNotReachHere();"); | |
1371 } | |
1372 } | |
1373 | |
1374 fprintf(fp,"\n"); | |
1375 // // Currently all XXXOper::hash() methods are identical (990820) | |
1376 // declare_hash(fp); | |
1377 // // Currently all XXXOper::Cmp() methods are identical (990820) | |
1378 // declare_cmp(fp); | |
1379 | |
1380 // Do not place dump_spec() and Name() into PRODUCT code | |
1381 // int_format and ext_format are not needed in PRODUCT code either | |
1382 fprintf(fp, "#ifndef PRODUCT\n"); | |
1383 | |
1384 // Declare int_format() and ext_format() | |
1385 gen_oper_format(fp, _globalNames, *oper); | |
1386 | |
1387 // Machine independent print functionality for debugging | |
1388 // IF we have constants, create a dump_spec function for the derived class | |
1389 // | |
1390 // (1) virtual void dump_spec() const { | |
1391 // (2) st->print("#%d", _c#); // Constant != ConP | |
1392 // OR _c#->dump_on(st); // Type ConP | |
1393 // ... | |
1394 // (3) } | |
1395 uint num_consts = oper->num_consts(_globalNames); | |
1396 if( num_consts > 0 ) { | |
1397 // line (1) | |
1398 fprintf(fp, " virtual void dump_spec(outputStream *st) const {\n"); | |
1399 // generate format string for st->print | |
1400 // Iterate over the component list & spit out the right thing | |
1401 uint i = 0; | |
1402 const char *type = oper->ideal_type(_globalNames); | |
1403 Component *comp; | |
1404 oper->_components.reset(); | |
1405 if ((comp = oper->_components.iter()) == NULL) { | |
1406 assert(num_consts == 1, "Bad component list detected.\n"); | |
1407 i = dump_spec_constant( fp, type, i ); | |
1408 // Check that type actually matched | |
1409 assert( i != 0, "Non-constant operand lacks component list."); | |
1410 } // end if NULL | |
1411 else { | |
1412 // line (2) | |
1413 // dump all components | |
1414 oper->_components.reset(); | |
1415 while((comp = oper->_components.iter()) != NULL) { | |
1416 type = comp->base_type(_globalNames); | |
1417 i = dump_spec_constant( fp, type, i ); | |
1418 } | |
1419 } | |
1420 // finish line (3) | |
1421 fprintf(fp," }\n"); | |
1422 } | |
1423 | |
1424 fprintf(fp," virtual const char *Name() const { return \"%s\";}\n", | |
1425 oper->_ident); | |
1426 | |
1427 fprintf(fp,"#endif\n"); | |
1428 | |
1429 // Close definition of this XxxMachOper | |
1430 fprintf(fp,"};\n"); | |
1431 } | |
1432 | |
1433 | |
1434 // Generate Machine Classes for each instruction defined in AD file | |
1435 fprintf(fp,"\n"); | |
1436 fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n"); | |
1437 declare_pipe_classes(fp); | |
1438 | |
1439 // Generate Machine Classes for each instruction defined in AD file | |
1440 fprintf(fp,"\n"); | |
1441 fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n"); | |
1442 _instructions.reset(); | |
1443 InstructForm *instr; | |
1444 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { | |
1445 // Ensure this is a machine-world instruction | |
1446 if ( instr->ideal_only() ) continue; | |
1447 | |
1448 // Build class definition for this instruction | |
1449 fprintf(fp,"\n"); | |
1450 fprintf(fp,"class %sNode : public %s { \n", | |
1451 instr->_ident, instr->mach_base_class() ); | |
1452 fprintf(fp,"private:\n"); | |
1453 fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() ); | |
1454 if ( instr->is_ideal_jump() ) { | |
1455 fprintf(fp, " GrowableArray<Label*> _index2label;\n"); | |
1456 } | |
1457 fprintf(fp,"public:\n"); | |
1458 fprintf(fp," MachOper *opnd_array(uint operand_index) const { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); return _opnd_array[operand_index]; }\n"); | |
1459 fprintf(fp," void set_opnd_array(uint operand_index, MachOper *operand) { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); _opnd_array[operand_index] = operand; }\n"); | |
1460 fprintf(fp,"private:\n"); | |
1461 if ( instr->is_ideal_jump() ) { | |
1462 fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n"); | |
1463 fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);}\n"); | |
1464 } | |
1465 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) { | |
1466 fprintf(fp," const RegMask *_cisc_RegMask;\n"); | |
1467 } | |
1468 | |
1469 out_RegMask(fp); // output register mask | |
1470 fprintf(fp," virtual uint rule() const { return %s_rule; }\n", | |
1471 instr->_ident); | |
1472 | |
1473 // If this instruction contains a labelOper | |
1474 // Declare Node::methods that set operand Label's contents | |
1475 int label_position = instr->label_position(); | |
1476 if( label_position != -1 ) { | |
1477 // Set the label, stored in labelOper::_branch_label | |
1478 fprintf(fp," virtual void label_set( Label& label, uint block_num );\n"); | |
1479 } | |
1480 | |
1481 // If this instruction contains a methodOper | |
1482 // Declare Node::methods that set operand method's contents | |
1483 int method_position = instr->method_position(); | |
1484 if( method_position != -1 ) { | |
1485 // Set the address method, stored in methodOper::_method | |
1486 fprintf(fp," virtual void method_set( intptr_t method );\n"); | |
1487 } | |
1488 | |
1489 // virtual functions for attributes | |
1490 // | |
1491 // Each instruction attribute results in a virtual call of same name. | |
1492 // The ins_cost is not handled here. | |
1493 Attribute *attr = instr->_attribs; | |
1494 bool is_pc_relative = false; | |
1495 while (attr != NULL) { | |
1496 if (strcmp(attr->_ident,"ins_cost") && | |
1497 strcmp(attr->_ident,"ins_pc_relative")) { | |
1498 fprintf(fp," int %s() const { return %s; }\n", | |
1499 attr->_ident, attr->_val); | |
1500 } | |
1501 // Check value for ins_pc_relative, and if it is true (1), set the flag | |
1502 if (!strcmp(attr->_ident,"ins_pc_relative") && attr->int_val(*this) != 0) | |
1503 is_pc_relative = true; | |
1504 attr = (Attribute *)attr->_next; | |
1505 } | |
1506 | |
1507 // virtual functions for encode and format | |
1508 // | |
1509 // Output the opcode function and the encode function here using the | |
1510 // encoding class information in the _insencode slot. | |
1511 if ( instr->_insencode ) { | |
1512 fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n"); | |
1513 } | |
1514 | |
1515 // virtual function for getting the size of an instruction | |
1516 if ( instr->_size ) { | |
1517 fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n"); | |
1518 } | |
1519 | |
1520 // Return the top-level ideal opcode. | |
1521 // Use MachNode::ideal_Opcode() for nodes based on MachNode class | |
1522 // if the ideal_Opcode == Op_Node. | |
1523 if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 || | |
1524 strcmp("MachNode", instr->mach_base_class()) != 0 ) { | |
1525 fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n", | |
1526 instr->ideal_Opcode(_globalNames) ); | |
1527 } | |
1528 | |
1529 // Allow machine-independent optimization, invert the sense of the IF test | |
1530 if( instr->is_ideal_if() ) { | |
1531 fprintf(fp," virtual void negate() { \n"); | |
1532 // Identify which operand contains the negate(able) ideal condition code | |
1533 int idx = 0; | |
1534 instr->_components.reset(); | |
1535 for( Component *comp; (comp = instr->_components.iter()) != NULL; ) { | |
1536 // Check that component is an operand | |
1537 Form *form = (Form*)_globalNames[comp->_type]; | |
1538 OperandForm *opForm = form ? form->is_operand() : NULL; | |
1539 if( opForm == NULL ) continue; | |
1540 | |
1541 // Lookup the position of the operand in the instruction. | |
1542 if( opForm->is_ideal_bool() ) { | |
1543 idx = instr->operand_position(comp->_name, comp->_usedef); | |
1544 assert( idx != NameList::Not_in_list, "Did not find component in list that contained it."); | |
1545 break; | |
1546 } | |
1547 } | |
1548 fprintf(fp," opnd_array(%d)->negate();\n", idx); | |
1549 fprintf(fp," _prob = 1.0f - _prob;\n"); | |
1550 fprintf(fp," };\n"); | |
1551 } | |
1552 | |
1553 | |
1554 // Identify which input register matches the input register. | |
1555 uint matching_input = instr->two_address(_globalNames); | |
1556 | |
1557 // Generate the method if it returns != 0 otherwise use MachNode::two_adr() | |
1558 if( matching_input != 0 ) { | |
1559 fprintf(fp," virtual uint two_adr() const "); | |
1560 fprintf(fp,"{ return oper_input_base()"); | |
1561 for( uint i = 2; i <= matching_input; i++ ) | |
1562 fprintf(fp," + opnd_array(%d)->num_edges()",i-1); | |
1563 fprintf(fp,"; }\n"); | |
1564 } | |
1565 | |
1566 // Declare cisc_version, if applicable | |
1567 // MachNode *cisc_version( int offset /* ,... */ ); | |
1568 instr->declare_cisc_version(*this, fp); | |
1569 | |
1570 // If there is an explicit peephole rule, build it | |
1571 if ( instr->peepholes() != NULL ) { | |
1572 fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile *C);\n"); | |
1573 } | |
1574 | |
1575 // Output the declaration for number of relocation entries | |
1576 if ( instr->reloc(_globalNames) != 0 ) { | |
1577 fprintf(fp," virtual int reloc() const;\n"); | |
1578 } | |
1579 | |
1580 if (instr->alignment() != 1) { | |
1581 fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment()); | |
1582 fprintf(fp," virtual int compute_padding(int current_offset) const;\n"); | |
1583 } | |
1584 | |
1585 // Starting point for inputs matcher wants. | |
1586 // Use MachNode::oper_input_base() for nodes based on MachNode class | |
1587 // if the base == 1. | |
1588 if ( instr->oper_input_base(_globalNames) != 1 || | |
1589 strcmp("MachNode", instr->mach_base_class()) != 0 ) { | |
1590 fprintf(fp," virtual uint oper_input_base() const { return %d; }\n", | |
1591 instr->oper_input_base(_globalNames)); | |
1592 } | |
1593 | |
1594 // Make the constructor and following methods 'public:' | |
1595 fprintf(fp,"public:\n"); | |
1596 | |
1597 // Constructor | |
1598 if ( instr->is_ideal_jump() ) { | |
1599 fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident); | |
1600 } else { | |
1601 fprintf(fp," %sNode() { ", instr->_ident); | |
1602 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) { | |
1603 fprintf(fp,"_cisc_RegMask = NULL; "); | |
1604 } | |
1605 } | |
1606 | |
1607 fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds()); | |
1608 | |
1609 bool node_flags_set = false; | |
1610 // flag: if this instruction matches an ideal 'Goto' node | |
1611 if ( instr->is_ideal_goto() ) { | |
1612 fprintf(fp,"init_flags(Flag_is_Goto"); | |
1613 node_flags_set = true; | |
1614 } | |
1615 | |
1616 // flag: if this instruction matches an ideal 'Copy*' node | |
1617 if ( instr->is_ideal_copy() != 0 ) { | |
1618 if ( node_flags_set ) { | |
1619 fprintf(fp," | Flag_is_Copy"); | |
1620 } else { | |
1621 fprintf(fp,"init_flags(Flag_is_Copy"); | |
1622 node_flags_set = true; | |
1623 } | |
1624 } | |
1625 | |
1626 // Is an instruction is a constant? If so, get its type | |
1627 Form::DataType data_type; | |
1628 const char *opType = NULL; | |
1629 const char *result = NULL; | |
1630 data_type = instr->is_chain_of_constant(_globalNames, opType, result); | |
1631 // Check if this instruction is a constant | |
1632 if ( data_type != Form::none ) { | |
1633 if ( node_flags_set ) { | |
1634 fprintf(fp," | Flag_is_Con"); | |
1635 } else { | |
1636 fprintf(fp,"init_flags(Flag_is_Con"); | |
1637 node_flags_set = true; | |
1638 } | |
1639 } | |
1640 | |
1641 // flag: if instruction matches 'If' | 'Goto' | 'CountedLoopEnd | 'Jump' | |
1642 if ( instr->is_ideal_branch() ) { | |
1643 if ( node_flags_set ) { | |
1644 fprintf(fp," | Flag_is_Branch"); | |
1645 } else { | |
1646 fprintf(fp,"init_flags(Flag_is_Branch"); | |
1647 node_flags_set = true; | |
1648 } | |
1649 } | |
1650 | |
1651 // flag: if this instruction is cisc alternate | |
1652 if ( can_cisc_spill() && instr->is_cisc_alternate() ) { | |
1653 if ( node_flags_set ) { | |
1654 fprintf(fp," | Flag_is_cisc_alternate"); | |
1655 } else { | |
1656 fprintf(fp,"init_flags(Flag_is_cisc_alternate"); | |
1657 node_flags_set = true; | |
1658 } | |
1659 } | |
1660 | |
1661 // flag: if this instruction is pc relative | |
1662 if ( is_pc_relative ) { | |
1663 if ( node_flags_set ) { | |
1664 fprintf(fp," | Flag_is_pc_relative"); | |
1665 } else { | |
1666 fprintf(fp,"init_flags(Flag_is_pc_relative"); | |
1667 node_flags_set = true; | |
1668 } | |
1669 } | |
1670 | |
1671 // flag: if this instruction has short branch form | |
1672 if ( instr->has_short_branch_form() ) { | |
1673 if ( node_flags_set ) { | |
1674 fprintf(fp," | Flag_may_be_short_branch"); | |
1675 } else { | |
1676 fprintf(fp,"init_flags(Flag_may_be_short_branch"); | |
1677 node_flags_set = true; | |
1678 } | |
1679 } | |
1680 | |
1681 // Check if machine instructions that USE memory, but do not DEF memory, | |
1682 // depend upon a node that defines memory in machine-independent graph. | |
1683 if ( instr->needs_anti_dependence_check(_globalNames) ) { | |
1684 if ( node_flags_set ) { | |
1685 fprintf(fp," | Flag_needs_anti_dependence_check"); | |
1686 } else { | |
1687 fprintf(fp,"init_flags(Flag_needs_anti_dependence_check"); | |
1688 node_flags_set = true; | |
1689 } | |
1690 } | |
1691 | |
1692 if ( node_flags_set ) { | |
1693 fprintf(fp,"); "); | |
1694 } | |
1695 | |
1696 if (instr->is_ideal_unlock() || instr->is_ideal_call_leaf()) { | |
1697 fprintf(fp,"clear_flag(Flag_is_safepoint_node); "); | |
1698 } | |
1699 | |
1700 fprintf(fp,"}\n"); | |
1701 | |
1702 // size_of, used by base class's clone to obtain the correct size. | |
1703 fprintf(fp," virtual uint size_of() const {"); | |
1704 fprintf(fp, " return sizeof(%sNode);", instr->_ident); | |
1705 fprintf(fp, " }\n"); | |
1706 | |
1707 // Virtual methods which are only generated to override base class | |
1708 if( instr->expands() || instr->needs_projections() || | |
1709 instr->has_temps() || | |
1710 instr->_matrule != NULL && | |
1711 instr->num_opnds() != instr->num_unique_opnds() ) { | |
1712 fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list);\n"); | |
1713 } | |
1714 | |
1715 if (instr->is_pinned(_globalNames)) { | |
1716 fprintf(fp," virtual bool pinned() const { return "); | |
1717 if (instr->is_parm(_globalNames)) { | |
1718 fprintf(fp,"_in[0]->pinned();"); | |
1719 } else { | |
1720 fprintf(fp,"true;"); | |
1721 } | |
1722 fprintf(fp," }\n"); | |
1723 } | |
1724 if (instr->is_projection(_globalNames)) { | |
1725 fprintf(fp," virtual const Node *is_block_proj() const { return this; }\n"); | |
1726 } | |
1727 if ( instr->num_post_match_opnds() != 0 | |
1728 || instr->is_chain_of_constant(_globalNames) ) { | |
1729 fprintf(fp," friend MachNode *State::MachNodeGenerator(int opcode, Compile* C);\n"); | |
1730 } | |
1731 if ( instr->rematerialize(_globalNames, get_registers()) ) { | |
1732 fprintf(fp," // Rematerialize %s\n", instr->_ident); | |
1733 } | |
1734 | |
1735 // Declare short branch methods, if applicable | |
1736 instr->declare_short_branch_methods(fp); | |
1737 | |
1738 // Instructions containing a constant that will be entered into the | |
1739 // float/double table redefine the base virtual function | |
1740 #ifdef SPARC | |
1741 // Sparc doubles entries in the constant table require more space for | |
1742 // alignment. (expires 9/98) | |
1743 int table_entries = (3 * instr->num_consts( _globalNames, Form::idealD )) | |
1744 + instr->num_consts( _globalNames, Form::idealF ); | |
1745 #else | |
1746 int table_entries = instr->num_consts( _globalNames, Form::idealD ) | |
1747 + instr->num_consts( _globalNames, Form::idealF ); | |
1748 #endif | |
1749 if( table_entries != 0 ) { | |
1750 fprintf(fp," virtual int const_size() const {"); | |
1751 fprintf(fp, " return %d;", table_entries); | |
1752 fprintf(fp, " }\n"); | |
1753 } | |
1754 | |
1755 | |
1756 // See if there is an "ins_pipe" declaration for this instruction | |
1757 if (instr->_ins_pipe) { | |
1758 fprintf(fp," static const Pipeline *pipeline_class();\n"); | |
1759 fprintf(fp," virtual const Pipeline *pipeline() const;\n"); | |
1760 } | |
1761 | |
1762 // Generate virtual function for MachNodeX::bottom_type when necessary | |
1763 // | |
1764 // Note on accuracy: Pointer-types of machine nodes need to be accurate, | |
1765 // or else alias analysis on the matched graph may produce bad code. | |
1766 // Moreover, the aliasing decisions made on machine-node graph must be | |
1767 // no less accurate than those made on the ideal graph, or else the graph | |
1768 // may fail to schedule. (Reason: Memory ops which are reordered in | |
1769 // the ideal graph might look interdependent in the machine graph, | |
1770 // thereby removing degrees of scheduling freedom that the optimizer | |
1771 // assumed would be available.) | |
1772 // | |
1773 // %%% We should handle many of these cases with an explicit ADL clause: | |
1774 // instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %} | |
1775 if( data_type != Form::none ) { | |
1776 // A constant's bottom_type returns a Type containing its constant value | |
1777 | |
1778 // !!!!! | |
1779 // Convert all ints, floats, ... to machine-independent TypeXs | |
1780 // as is done for pointers | |
1781 // | |
1782 // Construct appropriate constant type containing the constant value. | |
1783 fprintf(fp," virtual const class Type *bottom_type() const{\n"); | |
1784 switch( data_type ) { | |
1785 case Form::idealI: | |
1786 fprintf(fp," return TypeInt::make(opnd_array(1)->constant());\n"); | |
1787 break; | |
1788 case Form::idealP: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1789 case Form::idealN: |
0 | 1790 fprintf(fp," return opnd_array(1)->type();\n",result); |
1791 break; | |
1792 case Form::idealD: | |
1793 fprintf(fp," return TypeD::make(opnd_array(1)->constantD());\n"); | |
1794 break; | |
1795 case Form::idealF: | |
1796 fprintf(fp," return TypeF::make(opnd_array(1)->constantF());\n"); | |
1797 break; | |
1798 case Form::idealL: | |
1799 fprintf(fp," return TypeLong::make(opnd_array(1)->constantL());\n"); | |
1800 break; | |
1801 default: | |
1802 assert( false, "Unimplemented()" ); | |
1803 break; | |
1804 } | |
1805 fprintf(fp," };\n"); | |
1806 } | |
1807 /* else if ( instr->_matrule && instr->_matrule->_rChild && | |
1808 ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0 | |
1809 || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) { | |
1810 // !!!!! !!!!! | |
1811 // Provide explicit bottom type for conversions to int | |
1812 // On Intel the result operand is a stackSlot, untyped. | |
1813 fprintf(fp," virtual const class Type *bottom_type() const{"); | |
1814 fprintf(fp, " return TypeInt::INT;"); | |
1815 fprintf(fp, " };\n"); | |
1816 }*/ | |
1817 else if( instr->is_ideal_copy() && | |
1818 !strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) { | |
1819 // !!!!! | |
1820 // Special hack for ideal Copy of pointer. Bottom type is oop or not depending on input. | |
1821 fprintf(fp," const Type *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n"); | |
1822 } | |
1823 else if( instr->is_ideal_loadPC() ) { | |
1824 // LoadPCNode provides the return address of a call to native code. | |
1825 // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM | |
1826 // since it is a pointer to an internal VM location and must have a zero offset. | |
1827 // Allocation detects derived pointers, in part, by their non-zero offsets. | |
1828 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n"); | |
1829 } | |
1830 else if( instr->is_ideal_box() ) { | |
1831 // BoxNode provides the address of a stack slot. | |
1832 // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM | |
1833 // This prevent s insert_anti_dependencies from complaining. It will | |
1834 // complain if it see that the pointer base is TypePtr::BOTTOM since | |
1835 // it doesn't understand what that might alias. | |
1836 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n"); | |
1837 } | |
1838 else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveP") ) { | |
1839 int offset = 1; | |
1840 // Special special hack to see if the Cmp? has been incorporated in the conditional move | |
1841 MatchNode *rl = instr->_matrule->_rChild->_lChild; | |
1842 if( rl && !strcmp(rl->_opType, "Binary") ) { | |
1843 MatchNode *rlr = rl->_rChild; | |
1844 if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0) | |
1845 offset = 2; | |
1846 } | |
1847 // Special hack for ideal CMoveP; ideal type depends on inputs | |
1848 fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveP\n", | |
1849 offset, offset+1, offset+1); | |
1850 } | |
293
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1851 else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) { |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1852 int offset = 1; |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1853 // Special special hack to see if the Cmp? has been incorporated in the conditional move |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1854 MatchNode *rl = instr->_matrule->_rChild->_lChild; |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1855 if( rl && !strcmp(rl->_opType, "Binary") ) { |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1856 MatchNode *rlr = rl->_rChild; |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1857 if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0) |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1858 offset = 2; |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1859 } |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1860 // Special hack for ideal CMoveN; ideal type depends on inputs |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1861 fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveN\n", |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1862 offset, offset+1, offset+1); |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
196
diff
changeset
|
1863 } |
0 | 1864 else if( instr->needs_base_oop_edge(_globalNames) ) { |
1865 // Special hack for ideal AddP. Bottom type is an oop IFF it has a | |
1866 // legal base-pointer input. Otherwise it is NOT an oop. | |
1867 fprintf(fp," const Type *bottom_type() const { return AddPNode::mach_bottom_type(this); } // AddP\n"); | |
1868 } | |
1869 else if (instr->is_tls_instruction()) { | |
1870 // Special hack for tlsLoadP | |
1871 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n"); | |
1872 } | |
1873 else if ( instr->is_ideal_if() ) { | |
1874 fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n"); | |
1875 } | |
1876 else if ( instr->is_ideal_membar() ) { | |
1877 fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n"); | |
1878 } | |
1879 | |
1880 // Check where 'ideal_type' must be customized | |
1881 /* | |
1882 if ( instr->_matrule && instr->_matrule->_rChild && | |
1883 ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0 | |
1884 || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) { | |
1885 fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n"); | |
1886 }*/ | |
1887 | |
1888 // Analyze machine instructions that either USE or DEF memory. | |
1889 int memory_operand = instr->memory_operand(_globalNames); | |
1890 // Some guys kill all of memory | |
1891 if ( instr->is_wide_memory_kill(_globalNames) ) { | |
1892 memory_operand = InstructForm::MANY_MEMORY_OPERANDS; | |
1893 } | |
1894 if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) { | |
1895 if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) { | |
1896 fprintf(fp," virtual const TypePtr *adr_type() const;\n"); | |
1897 } | |
1898 fprintf(fp," virtual const MachOper *memory_operand() const;\n"); | |
1899 } | |
1900 | |
1901 fprintf(fp, "#ifndef PRODUCT\n"); | |
1902 | |
1903 // virtual function for generating the user's assembler output | |
1904 gen_inst_format(fp, _globalNames,*instr); | |
1905 | |
1906 // Machine independent print functionality for debugging | |
1907 fprintf(fp," virtual const char *Name() const { return \"%s\";}\n", | |
1908 instr->_ident); | |
1909 | |
1910 fprintf(fp, "#endif\n"); | |
1911 | |
1912 // Close definition of this XxxMachNode | |
1913 fprintf(fp,"};\n"); | |
1914 }; | |
1915 | |
1916 } | |
1917 | |
1918 void ArchDesc::defineStateClass(FILE *fp) { | |
1919 static const char *state__valid = "_valid[((uint)index) >> 5] & (0x1 << (((uint)index) & 0x0001F))"; | |
1920 static const char *state__set_valid= "_valid[((uint)index) >> 5] |= (0x1 << (((uint)index) & 0x0001F))"; | |
1921 | |
1922 fprintf(fp,"\n"); | |
1923 fprintf(fp,"// MACROS to inline and constant fold State::valid(index)...\n"); | |
1924 fprintf(fp,"// when given a constant 'index' in dfa_<arch>.cpp\n"); | |
1925 fprintf(fp,"// uint word = index >> 5; // Shift out bit position\n"); | |
1926 fprintf(fp,"// uint bitpos = index & 0x0001F; // Mask off word bits\n"); | |
1927 fprintf(fp,"#define STATE__VALID(index) "); | |
1928 fprintf(fp," (%s)\n", state__valid); | |
1929 fprintf(fp,"\n"); | |
1930 fprintf(fp,"#define STATE__NOT_YET_VALID(index) "); | |
1931 fprintf(fp," ( (%s) == 0 )\n", state__valid); | |
1932 fprintf(fp,"\n"); | |
1933 fprintf(fp,"#define STATE__VALID_CHILD(state,index) "); | |
1934 fprintf(fp," ( state && (state->%s) )\n", state__valid); | |
1935 fprintf(fp,"\n"); | |
1936 fprintf(fp,"#define STATE__SET_VALID(index) "); | |
1937 fprintf(fp," (%s)\n", state__set_valid); | |
1938 fprintf(fp,"\n"); | |
1939 fprintf(fp, | |
1940 "//---------------------------State-------------------------------------------\n"); | |
1941 fprintf(fp,"// State contains an integral cost vector, indexed by machine operand opcodes,\n"); | |
1942 fprintf(fp,"// a rule vector consisting of machine operand/instruction opcodes, and also\n"); | |
1943 fprintf(fp,"// indexed by machine operand opcodes, pointers to the children in the label\n"); | |
1944 fprintf(fp,"// tree generated by the Label routines in ideal nodes (currently limited to\n"); | |
1945 fprintf(fp,"// two for convenience, but this could change).\n"); | |
1946 fprintf(fp,"class State : public ResourceObj {\n"); | |
1947 fprintf(fp,"public:\n"); | |
1948 fprintf(fp," int _id; // State identifier\n"); | |
1949 fprintf(fp," Node *_leaf; // Ideal (non-machine-node) leaf of match tree\n"); | |
1950 fprintf(fp," State *_kids[2]; // Children of state node in label tree\n"); | |
1951 fprintf(fp," unsigned int _cost[_LAST_MACH_OPER]; // Cost vector, indexed by operand opcodes\n"); | |
1952 fprintf(fp," unsigned int _rule[_LAST_MACH_OPER]; // Rule vector, indexed by operand opcodes\n"); | |
1953 fprintf(fp," unsigned int _valid[(_LAST_MACH_OPER/32)+1]; // Bit Map of valid Cost/Rule entries\n"); | |
1954 fprintf(fp,"\n"); | |
1955 fprintf(fp," State(void); // Constructor\n"); | |
1956 fprintf(fp," DEBUG_ONLY( ~State(void); ) // Destructor\n"); | |
1957 fprintf(fp,"\n"); | |
1958 fprintf(fp," // Methods created by ADLC and invoked by Reduce\n"); | |
1959 fprintf(fp," MachOper *MachOperGenerator( int opcode, Compile* C );\n"); | |
1960 fprintf(fp," MachNode *MachNodeGenerator( int opcode, Compile* C );\n"); | |
1961 fprintf(fp,"\n"); | |
1962 fprintf(fp," // Assign a state to a node, definition of method produced by ADLC\n"); | |
1963 fprintf(fp," bool DFA( int opcode, const Node *ideal );\n"); | |
1964 fprintf(fp,"\n"); | |
1965 fprintf(fp," // Access function for _valid bit vector\n"); | |
1966 fprintf(fp," bool valid(uint index) {\n"); | |
1967 fprintf(fp," return( STATE__VALID(index) != 0 );\n"); | |
1968 fprintf(fp," }\n"); | |
1969 fprintf(fp,"\n"); | |
1970 fprintf(fp," // Set function for _valid bit vector\n"); | |
1971 fprintf(fp," void set_valid(uint index) {\n"); | |
1972 fprintf(fp," STATE__SET_VALID(index);\n"); | |
1973 fprintf(fp," }\n"); | |
1974 fprintf(fp,"\n"); | |
1975 fprintf(fp,"#ifndef PRODUCT\n"); | |
1976 fprintf(fp," void dump(); // Debugging prints\n"); | |
1977 fprintf(fp," void dump(int depth);\n"); | |
1978 fprintf(fp,"#endif\n"); | |
1979 if (_dfa_small) { | |
1980 // Generate the routine name we'll need | |
1981 for (int i = 1; i < _last_opcode; i++) { | |
1982 if (_mlistab[i] == NULL) continue; | |
1983 fprintf(fp, " void _sub_Op_%s(const Node *n);\n", NodeClassNames[i]); | |
1984 } | |
1985 } | |
1986 fprintf(fp,"};\n"); | |
1987 fprintf(fp,"\n"); | |
1988 fprintf(fp,"\n"); | |
1989 | |
1990 } | |
1991 | |
1992 | |
1993 //---------------------------buildMachOperEnum--------------------------------- | |
1994 // Build enumeration for densely packed operands. | |
1995 // This enumeration is used to index into the arrays in the State objects | |
1996 // that indicate cost and a successfull rule match. | |
1997 | |
1998 // Information needed to generate the ReduceOp mapping for the DFA | |
1999 class OutputMachOperands : public OutputMap { | |
2000 public: | |
2001 OutputMachOperands(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
2002 : OutputMap(hpp, cpp, globals, AD) {}; | |
2003 | |
2004 void declaration() { } | |
2005 void definition() { fprintf(_cpp, "enum MachOperands {\n"); } | |
2006 void closing() { fprintf(_cpp, " _LAST_MACH_OPER\n"); | |
2007 OutputMap::closing(); | |
2008 } | |
2009 void map(OpClassForm &opc) { fprintf(_cpp, " %s", _AD.machOperEnum(opc._ident) ); } | |
2010 void map(OperandForm &oper) { fprintf(_cpp, " %s", _AD.machOperEnum(oper._ident) ); } | |
2011 void map(char *name) { fprintf(_cpp, " %s", _AD.machOperEnum(name)); } | |
2012 | |
2013 bool do_instructions() { return false; } | |
2014 void map(InstructForm &inst){ assert( false, "ShouldNotCallThis()"); } | |
2015 }; | |
2016 | |
2017 | |
2018 void ArchDesc::buildMachOperEnum(FILE *fp_hpp) { | |
2019 // Construct the table for MachOpcodes | |
2020 OutputMachOperands output_mach_operands(fp_hpp, fp_hpp, _globalNames, *this); | |
2021 build_map(output_mach_operands); | |
2022 } | |
2023 | |
2024 | |
2025 //---------------------------buildMachEnum---------------------------------- | |
2026 // Build enumeration for all MachOpers and all MachNodes | |
2027 | |
2028 // Information needed to generate the ReduceOp mapping for the DFA | |
2029 class OutputMachOpcodes : public OutputMap { | |
2030 int begin_inst_chain_rule; | |
2031 int end_inst_chain_rule; | |
2032 int begin_rematerialize; | |
2033 int end_rematerialize; | |
2034 int end_instructions; | |
2035 public: | |
2036 OutputMachOpcodes(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) | |
2037 : OutputMap(hpp, cpp, globals, AD), | |
2038 begin_inst_chain_rule(-1), end_inst_chain_rule(-1), end_instructions(-1) | |
2039 {}; | |
2040 | |
2041 void declaration() { } | |
2042 void definition() { fprintf(_cpp, "enum MachOpcodes {\n"); } | |
2043 void closing() { | |
2044 if( begin_inst_chain_rule != -1 ) | |
2045 fprintf(_cpp, " _BEGIN_INST_CHAIN_RULE = %d,\n", begin_inst_chain_rule); | |
2046 if( end_inst_chain_rule != -1 ) | |
2047 fprintf(_cpp, " _END_INST_CHAIN_RULE = %d,\n", end_inst_chain_rule); | |
2048 if( begin_rematerialize != -1 ) | |
2049 fprintf(_cpp, " _BEGIN_REMATERIALIZE = %d,\n", begin_rematerialize); | |
2050 if( end_rematerialize != -1 ) | |
2051 fprintf(_cpp, " _END_REMATERIALIZE = %d,\n", end_rematerialize); | |
2052 // always execute since do_instructions() is true, and avoids trailing comma | |
2053 fprintf(_cpp, " _last_Mach_Node = %d \n", end_instructions); | |
2054 OutputMap::closing(); | |
2055 } | |
2056 void map(OpClassForm &opc) { fprintf(_cpp, " %s_rule", opc._ident ); } | |
2057 void map(OperandForm &oper) { fprintf(_cpp, " %s_rule", oper._ident ); } | |
2058 void map(char *name) { if (name) fprintf(_cpp, " %s_rule", name); | |
2059 else fprintf(_cpp, " 0"); } | |
2060 void map(InstructForm &inst) {fprintf(_cpp, " %s_rule", inst._ident ); } | |
2061 | |
2062 void record_position(OutputMap::position place, int idx ) { | |
2063 switch(place) { | |
2064 case OutputMap::BEGIN_INST_CHAIN_RULES : | |
2065 begin_inst_chain_rule = idx; | |
2066 break; | |
2067 case OutputMap::END_INST_CHAIN_RULES : | |
2068 end_inst_chain_rule = idx; | |
2069 break; | |
2070 case OutputMap::BEGIN_REMATERIALIZE : | |
2071 begin_rematerialize = idx; | |
2072 break; | |
2073 case OutputMap::END_REMATERIALIZE : | |
2074 end_rematerialize = idx; | |
2075 break; | |
2076 case OutputMap::END_INSTRUCTIONS : | |
2077 end_instructions = idx; | |
2078 break; | |
2079 default: | |
2080 break; | |
2081 } | |
2082 } | |
2083 }; | |
2084 | |
2085 | |
2086 void ArchDesc::buildMachOpcodesEnum(FILE *fp_hpp) { | |
2087 // Construct the table for MachOpcodes | |
2088 OutputMachOpcodes output_mach_opcodes(fp_hpp, fp_hpp, _globalNames, *this); | |
2089 build_map(output_mach_opcodes); | |
2090 } | |
2091 | |
2092 | |
2093 // Generate an enumeration of the pipeline states, and both | |
2094 // the functional units (resources) and the masks for | |
2095 // specifying resources | |
2096 void ArchDesc::build_pipeline_enums(FILE *fp_hpp) { | |
2097 int stagelen = (int)strlen("undefined"); | |
2098 int stagenum = 0; | |
2099 | |
2100 if (_pipeline) { // Find max enum string length | |
2101 const char *stage; | |
2102 for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) { | |
2103 int len = (int)strlen(stage); | |
2104 if (stagelen < len) stagelen = len; | |
2105 } | |
2106 } | |
2107 | |
2108 // Generate a list of stages | |
2109 fprintf(fp_hpp, "\n"); | |
2110 fprintf(fp_hpp, "// Pipeline Stages\n"); | |
2111 fprintf(fp_hpp, "enum machPipelineStages {\n"); | |
2112 fprintf(fp_hpp, " stage_%-*s = 0,\n", stagelen, "undefined"); | |
2113 | |
2114 if( _pipeline ) { | |
2115 const char *stage; | |
2116 for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) | |
2117 fprintf(fp_hpp, " stage_%-*s = %d,\n", stagelen, stage, ++stagenum); | |
2118 } | |
2119 | |
2120 fprintf(fp_hpp, " stage_%-*s = %d\n", stagelen, "count", stagenum); | |
2121 fprintf(fp_hpp, "};\n"); | |
2122 | |
2123 fprintf(fp_hpp, "\n"); | |
2124 fprintf(fp_hpp, "// Pipeline Resources\n"); | |
2125 fprintf(fp_hpp, "enum machPipelineResources {\n"); | |
2126 int rescount = 0; | |
2127 | |
2128 if( _pipeline ) { | |
2129 const char *resource; | |
2130 int reslen = 0; | |
2131 | |
2132 // Generate a list of resources, and masks | |
2133 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { | |
2134 int len = (int)strlen(resource); | |
2135 if (reslen < len) | |
2136 reslen = len; | |
2137 } | |
2138 | |
2139 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { | |
2140 const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource(); | |
2141 int mask = resform->mask(); | |
2142 if ((mask & (mask-1)) == 0) | |
2143 fprintf(fp_hpp, " resource_%-*s = %d,\n", reslen, resource, rescount++); | |
2144 } | |
2145 fprintf(fp_hpp, "\n"); | |
2146 for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { | |
2147 const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource(); | |
2148 fprintf(fp_hpp, " res_mask_%-*s = 0x%08x,\n", reslen, resource, resform->mask()); | |
2149 } | |
2150 fprintf(fp_hpp, "\n"); | |
2151 } | |
2152 fprintf(fp_hpp, " resource_count = %d\n", rescount); | |
2153 fprintf(fp_hpp, "};\n"); | |
2154 } |