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