annotate src/hotspot/share/adlc/output_h.cpp @ 53789:b776653628c5

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