comparison src/share/vm/adlc/output_h.cpp @ 0:a61af66fc99e jdk7-b24

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