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