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