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