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