src/share/vm/adlc/output_h.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

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

mercurial