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