Mon, 09 Mar 2009 13:28:46 -0700
6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair
duke@435 | 1 | /* |
xdono@631 | 2 | * Copyright 1998-2008 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // output_c.cpp - Class CPP file output routines for architecture definition |
duke@435 | 26 | |
duke@435 | 27 | #include "adlc.hpp" |
duke@435 | 28 | |
duke@435 | 29 | // Utilities to characterize effect statements |
duke@435 | 30 | static bool is_def(int usedef) { |
duke@435 | 31 | switch(usedef) { |
duke@435 | 32 | case Component::DEF: |
duke@435 | 33 | case Component::USE_DEF: return true; break; |
duke@435 | 34 | } |
duke@435 | 35 | return false; |
duke@435 | 36 | } |
duke@435 | 37 | |
duke@435 | 38 | static bool is_use(int usedef) { |
duke@435 | 39 | switch(usedef) { |
duke@435 | 40 | case Component::USE: |
duke@435 | 41 | case Component::USE_DEF: |
duke@435 | 42 | case Component::USE_KILL: return true; break; |
duke@435 | 43 | } |
duke@435 | 44 | return false; |
duke@435 | 45 | } |
duke@435 | 46 | |
duke@435 | 47 | static bool is_kill(int usedef) { |
duke@435 | 48 | switch(usedef) { |
duke@435 | 49 | case Component::KILL: |
duke@435 | 50 | case Component::USE_KILL: return true; break; |
duke@435 | 51 | } |
duke@435 | 52 | return false; |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | // Define an array containing the machine register names, strings. |
duke@435 | 56 | static void defineRegNames(FILE *fp, RegisterForm *registers) { |
duke@435 | 57 | if (registers) { |
duke@435 | 58 | fprintf(fp,"\n"); |
duke@435 | 59 | fprintf(fp,"// An array of character pointers to machine register names.\n"); |
duke@435 | 60 | fprintf(fp,"const char *Matcher::regName[REG_COUNT] = {\n"); |
duke@435 | 61 | |
duke@435 | 62 | // Output the register name for each register in the allocation classes |
duke@435 | 63 | RegDef *reg_def = NULL; |
duke@435 | 64 | RegDef *next = NULL; |
duke@435 | 65 | registers->reset_RegDefs(); |
duke@435 | 66 | for( reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next ) { |
duke@435 | 67 | next = registers->iter_RegDefs(); |
duke@435 | 68 | const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
duke@435 | 69 | fprintf(fp," \"%s\"%s\n", |
duke@435 | 70 | reg_def->_regname, comma ); |
duke@435 | 71 | } |
duke@435 | 72 | |
duke@435 | 73 | // Finish defining enumeration |
duke@435 | 74 | fprintf(fp,"};\n"); |
duke@435 | 75 | |
duke@435 | 76 | fprintf(fp,"\n"); |
duke@435 | 77 | fprintf(fp,"// An array of character pointers to machine register names.\n"); |
duke@435 | 78 | fprintf(fp,"const VMReg OptoReg::opto2vm[REG_COUNT] = {\n"); |
duke@435 | 79 | reg_def = NULL; |
duke@435 | 80 | next = NULL; |
duke@435 | 81 | registers->reset_RegDefs(); |
duke@435 | 82 | for( reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next ) { |
duke@435 | 83 | next = registers->iter_RegDefs(); |
duke@435 | 84 | const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
duke@435 | 85 | fprintf(fp,"\t%s%s\n", reg_def->_concrete, comma ); |
duke@435 | 86 | } |
duke@435 | 87 | // Finish defining array |
duke@435 | 88 | fprintf(fp,"\t};\n"); |
duke@435 | 89 | fprintf(fp,"\n"); |
duke@435 | 90 | |
duke@435 | 91 | fprintf(fp," OptoReg::Name OptoReg::vm2opto[ConcreteRegisterImpl::number_of_registers];\n"); |
duke@435 | 92 | |
duke@435 | 93 | } |
duke@435 | 94 | } |
duke@435 | 95 | |
duke@435 | 96 | // Define an array containing the machine register encoding values |
duke@435 | 97 | static void defineRegEncodes(FILE *fp, RegisterForm *registers) { |
duke@435 | 98 | if (registers) { |
duke@435 | 99 | fprintf(fp,"\n"); |
duke@435 | 100 | fprintf(fp,"// An array of the machine register encode values\n"); |
duke@435 | 101 | fprintf(fp,"const unsigned char Matcher::_regEncode[REG_COUNT] = {\n"); |
duke@435 | 102 | |
duke@435 | 103 | // Output the register encoding for each register in the allocation classes |
duke@435 | 104 | RegDef *reg_def = NULL; |
duke@435 | 105 | RegDef *next = NULL; |
duke@435 | 106 | registers->reset_RegDefs(); |
duke@435 | 107 | for( reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next ) { |
duke@435 | 108 | next = registers->iter_RegDefs(); |
duke@435 | 109 | const char* register_encode = reg_def->register_encode(); |
duke@435 | 110 | const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
duke@435 | 111 | int encval; |
duke@435 | 112 | if (!ADLParser::is_int_token(register_encode, encval)) { |
duke@435 | 113 | fprintf(fp," %s%s // %s\n", |
duke@435 | 114 | register_encode, comma, reg_def->_regname ); |
duke@435 | 115 | } else { |
duke@435 | 116 | // Output known constants in hex char format (backward compatibility). |
duke@435 | 117 | assert(encval < 256, "Exceeded supported width for register encoding"); |
duke@435 | 118 | fprintf(fp," (unsigned char)'\\x%X'%s // %s\n", |
duke@435 | 119 | encval, comma, reg_def->_regname ); |
duke@435 | 120 | } |
duke@435 | 121 | } |
duke@435 | 122 | // Finish defining enumeration |
duke@435 | 123 | fprintf(fp,"};\n"); |
duke@435 | 124 | |
duke@435 | 125 | } // Done defining array |
duke@435 | 126 | } |
duke@435 | 127 | |
duke@435 | 128 | // Output an enumeration of register class names |
duke@435 | 129 | static void defineRegClassEnum(FILE *fp, RegisterForm *registers) { |
duke@435 | 130 | if (registers) { |
duke@435 | 131 | // Output an enumeration of register class names |
duke@435 | 132 | fprintf(fp,"\n"); |
duke@435 | 133 | fprintf(fp,"// Enumeration of register class names\n"); |
duke@435 | 134 | fprintf(fp, "enum machRegisterClass {\n"); |
duke@435 | 135 | registers->_rclasses.reset(); |
duke@435 | 136 | for( const char *class_name = NULL; |
duke@435 | 137 | (class_name = registers->_rclasses.iter()) != NULL; ) { |
duke@435 | 138 | fprintf(fp," %s,\n", toUpper( class_name )); |
duke@435 | 139 | } |
duke@435 | 140 | // Finish defining enumeration |
duke@435 | 141 | fprintf(fp, " _last_Mach_Reg_Class\n"); |
duke@435 | 142 | fprintf(fp, "};\n"); |
duke@435 | 143 | } |
duke@435 | 144 | } |
duke@435 | 145 | |
duke@435 | 146 | // Declare an enumeration of user-defined register classes |
duke@435 | 147 | // and a list of register masks, one for each class. |
duke@435 | 148 | void ArchDesc::declare_register_masks(FILE *fp_hpp) { |
duke@435 | 149 | const char *rc_name; |
duke@435 | 150 | |
duke@435 | 151 | if( _register ) { |
duke@435 | 152 | // Build enumeration of user-defined register classes. |
duke@435 | 153 | defineRegClassEnum(fp_hpp, _register); |
duke@435 | 154 | |
duke@435 | 155 | // Generate a list of register masks, one for each class. |
duke@435 | 156 | fprintf(fp_hpp,"\n"); |
duke@435 | 157 | fprintf(fp_hpp,"// Register masks, one for each register class.\n"); |
duke@435 | 158 | _register->_rclasses.reset(); |
duke@435 | 159 | for( rc_name = NULL; |
duke@435 | 160 | (rc_name = _register->_rclasses.iter()) != NULL; ) { |
duke@435 | 161 | const char *prefix = ""; |
duke@435 | 162 | RegClass *reg_class = _register->getRegClass(rc_name); |
duke@435 | 163 | assert( reg_class, "Using an undefined register class"); |
duke@435 | 164 | |
duke@435 | 165 | int len = RegisterForm::RegMask_Size(); |
duke@435 | 166 | fprintf(fp_hpp, "extern const RegMask %s%s_mask;\n", prefix, toUpper( rc_name ) ); |
duke@435 | 167 | |
duke@435 | 168 | if( reg_class->_stack_or_reg ) { |
duke@435 | 169 | fprintf(fp_hpp, "extern const RegMask %sSTACK_OR_%s_mask;\n", prefix, toUpper( rc_name ) ); |
duke@435 | 170 | } |
duke@435 | 171 | } |
duke@435 | 172 | } |
duke@435 | 173 | } |
duke@435 | 174 | |
duke@435 | 175 | // Generate an enumeration of user-defined register classes |
duke@435 | 176 | // and a list of register masks, one for each class. |
duke@435 | 177 | void ArchDesc::build_register_masks(FILE *fp_cpp) { |
duke@435 | 178 | const char *rc_name; |
duke@435 | 179 | |
duke@435 | 180 | if( _register ) { |
duke@435 | 181 | // Generate a list of register masks, one for each class. |
duke@435 | 182 | fprintf(fp_cpp,"\n"); |
duke@435 | 183 | fprintf(fp_cpp,"// Register masks, one for each register class.\n"); |
duke@435 | 184 | _register->_rclasses.reset(); |
duke@435 | 185 | for( rc_name = NULL; |
duke@435 | 186 | (rc_name = _register->_rclasses.iter()) != NULL; ) { |
duke@435 | 187 | const char *prefix = ""; |
duke@435 | 188 | RegClass *reg_class = _register->getRegClass(rc_name); |
duke@435 | 189 | assert( reg_class, "Using an undefined register class"); |
duke@435 | 190 | |
duke@435 | 191 | int len = RegisterForm::RegMask_Size(); |
duke@435 | 192 | fprintf(fp_cpp, "const RegMask %s%s_mask(", prefix, toUpper( rc_name ) ); |
duke@435 | 193 | { int i; |
duke@435 | 194 | for( i = 0; i < len-1; i++ ) |
duke@435 | 195 | fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i,false)); |
duke@435 | 196 | fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i,false)); |
duke@435 | 197 | } |
duke@435 | 198 | |
duke@435 | 199 | if( reg_class->_stack_or_reg ) { |
duke@435 | 200 | int i; |
duke@435 | 201 | fprintf(fp_cpp, "const RegMask %sSTACK_OR_%s_mask(", prefix, toUpper( rc_name ) ); |
duke@435 | 202 | for( i = 0; i < len-1; i++ ) |
duke@435 | 203 | fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i,true)); |
duke@435 | 204 | fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i,true)); |
duke@435 | 205 | } |
duke@435 | 206 | } |
duke@435 | 207 | } |
duke@435 | 208 | } |
duke@435 | 209 | |
duke@435 | 210 | // Compute an index for an array in the pipeline_reads_NNN arrays |
duke@435 | 211 | static int pipeline_reads_initializer(FILE *fp_cpp, NameList &pipeline_reads, PipeClassForm *pipeclass) |
duke@435 | 212 | { |
duke@435 | 213 | int templen = 1; |
duke@435 | 214 | int paramcount = 0; |
duke@435 | 215 | const char *paramname; |
duke@435 | 216 | |
duke@435 | 217 | if (pipeclass->_parameters.count() == 0) |
duke@435 | 218 | return -1; |
duke@435 | 219 | |
duke@435 | 220 | pipeclass->_parameters.reset(); |
duke@435 | 221 | paramname = pipeclass->_parameters.iter(); |
duke@435 | 222 | const PipeClassOperandForm *pipeopnd = |
duke@435 | 223 | (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
duke@435 | 224 | if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal")) |
duke@435 | 225 | pipeclass->_parameters.reset(); |
duke@435 | 226 | |
duke@435 | 227 | while ( (paramname = pipeclass->_parameters.iter()) != NULL ) { |
duke@435 | 228 | const PipeClassOperandForm *pipeopnd = |
duke@435 | 229 | (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
duke@435 | 230 | |
duke@435 | 231 | if (pipeopnd) |
duke@435 | 232 | templen += 10 + (int)strlen(pipeopnd->_stage); |
duke@435 | 233 | else |
duke@435 | 234 | templen += 19; |
duke@435 | 235 | |
duke@435 | 236 | paramcount++; |
duke@435 | 237 | } |
duke@435 | 238 | |
duke@435 | 239 | // See if the count is zero |
duke@435 | 240 | if (paramcount == 0) { |
duke@435 | 241 | return -1; |
duke@435 | 242 | } |
duke@435 | 243 | |
duke@435 | 244 | char *operand_stages = new char [templen]; |
duke@435 | 245 | operand_stages[0] = 0; |
duke@435 | 246 | int i = 0; |
duke@435 | 247 | templen = 0; |
duke@435 | 248 | |
duke@435 | 249 | pipeclass->_parameters.reset(); |
duke@435 | 250 | paramname = pipeclass->_parameters.iter(); |
duke@435 | 251 | pipeopnd = (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
duke@435 | 252 | if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal")) |
duke@435 | 253 | pipeclass->_parameters.reset(); |
duke@435 | 254 | |
duke@435 | 255 | while ( (paramname = pipeclass->_parameters.iter()) != NULL ) { |
duke@435 | 256 | const PipeClassOperandForm *pipeopnd = |
duke@435 | 257 | (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
duke@435 | 258 | templen += sprintf(&operand_stages[templen], " stage_%s%c\n", |
duke@435 | 259 | pipeopnd ? pipeopnd->_stage : "undefined", |
duke@435 | 260 | (++i < paramcount ? ',' : ' ') ); |
duke@435 | 261 | } |
duke@435 | 262 | |
duke@435 | 263 | // See if the same string is in the table |
duke@435 | 264 | int ndx = pipeline_reads.index(operand_stages); |
duke@435 | 265 | |
duke@435 | 266 | // No, add it to the table |
duke@435 | 267 | if (ndx < 0) { |
duke@435 | 268 | pipeline_reads.addName(operand_stages); |
duke@435 | 269 | ndx = pipeline_reads.index(operand_stages); |
duke@435 | 270 | |
duke@435 | 271 | fprintf(fp_cpp, "static const enum machPipelineStages pipeline_reads_%03d[%d] = {\n%s};\n\n", |
duke@435 | 272 | ndx+1, paramcount, operand_stages); |
duke@435 | 273 | } |
duke@435 | 274 | else |
duke@435 | 275 | delete [] operand_stages; |
duke@435 | 276 | |
duke@435 | 277 | return (ndx); |
duke@435 | 278 | } |
duke@435 | 279 | |
duke@435 | 280 | // Compute an index for an array in the pipeline_res_stages_NNN arrays |
duke@435 | 281 | static int pipeline_res_stages_initializer( |
duke@435 | 282 | FILE *fp_cpp, |
duke@435 | 283 | PipelineForm *pipeline, |
duke@435 | 284 | NameList &pipeline_res_stages, |
duke@435 | 285 | PipeClassForm *pipeclass) |
duke@435 | 286 | { |
duke@435 | 287 | const PipeClassResourceForm *piperesource; |
duke@435 | 288 | int * res_stages = new int [pipeline->_rescount]; |
duke@435 | 289 | int i; |
duke@435 | 290 | |
duke@435 | 291 | for (i = 0; i < pipeline->_rescount; i++) |
duke@435 | 292 | res_stages[i] = 0; |
duke@435 | 293 | |
duke@435 | 294 | for (pipeclass->_resUsage.reset(); |
duke@435 | 295 | (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) { |
duke@435 | 296 | int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); |
duke@435 | 297 | for (i = 0; i < pipeline->_rescount; i++) |
duke@435 | 298 | if ((1 << i) & used_mask) { |
duke@435 | 299 | int stage = pipeline->_stages.index(piperesource->_stage); |
duke@435 | 300 | if (res_stages[i] < stage+1) |
duke@435 | 301 | res_stages[i] = stage+1; |
duke@435 | 302 | } |
duke@435 | 303 | } |
duke@435 | 304 | |
duke@435 | 305 | // Compute the length needed for the resource list |
duke@435 | 306 | int commentlen = 0; |
duke@435 | 307 | int max_stage = 0; |
duke@435 | 308 | for (i = 0; i < pipeline->_rescount; i++) { |
duke@435 | 309 | if (res_stages[i] == 0) { |
duke@435 | 310 | if (max_stage < 9) |
duke@435 | 311 | max_stage = 9; |
duke@435 | 312 | } |
duke@435 | 313 | else { |
duke@435 | 314 | int stagelen = (int)strlen(pipeline->_stages.name(res_stages[i]-1)); |
duke@435 | 315 | if (max_stage < stagelen) |
duke@435 | 316 | max_stage = stagelen; |
duke@435 | 317 | } |
duke@435 | 318 | |
duke@435 | 319 | commentlen += (int)strlen(pipeline->_reslist.name(i)); |
duke@435 | 320 | } |
duke@435 | 321 | |
duke@435 | 322 | int templen = 1 + commentlen + pipeline->_rescount * (max_stage + 14); |
duke@435 | 323 | |
duke@435 | 324 | // Allocate space for the resource list |
duke@435 | 325 | char * resource_stages = new char [templen]; |
duke@435 | 326 | |
duke@435 | 327 | templen = 0; |
duke@435 | 328 | for (i = 0; i < pipeline->_rescount; i++) { |
duke@435 | 329 | const char * const resname = |
duke@435 | 330 | res_stages[i] == 0 ? "undefined" : pipeline->_stages.name(res_stages[i]-1); |
duke@435 | 331 | |
duke@435 | 332 | templen += sprintf(&resource_stages[templen], " stage_%s%-*s // %s\n", |
duke@435 | 333 | resname, max_stage - (int)strlen(resname) + 1, |
duke@435 | 334 | (i < pipeline->_rescount-1) ? "," : "", |
duke@435 | 335 | pipeline->_reslist.name(i)); |
duke@435 | 336 | } |
duke@435 | 337 | |
duke@435 | 338 | // See if the same string is in the table |
duke@435 | 339 | int ndx = pipeline_res_stages.index(resource_stages); |
duke@435 | 340 | |
duke@435 | 341 | // No, add it to the table |
duke@435 | 342 | if (ndx < 0) { |
duke@435 | 343 | pipeline_res_stages.addName(resource_stages); |
duke@435 | 344 | ndx = pipeline_res_stages.index(resource_stages); |
duke@435 | 345 | |
duke@435 | 346 | fprintf(fp_cpp, "static const enum machPipelineStages pipeline_res_stages_%03d[%d] = {\n%s};\n\n", |
duke@435 | 347 | ndx+1, pipeline->_rescount, resource_stages); |
duke@435 | 348 | } |
duke@435 | 349 | else |
duke@435 | 350 | delete [] resource_stages; |
duke@435 | 351 | |
duke@435 | 352 | delete [] res_stages; |
duke@435 | 353 | |
duke@435 | 354 | return (ndx); |
duke@435 | 355 | } |
duke@435 | 356 | |
duke@435 | 357 | // Compute an index for an array in the pipeline_res_cycles_NNN arrays |
duke@435 | 358 | static int pipeline_res_cycles_initializer( |
duke@435 | 359 | FILE *fp_cpp, |
duke@435 | 360 | PipelineForm *pipeline, |
duke@435 | 361 | NameList &pipeline_res_cycles, |
duke@435 | 362 | PipeClassForm *pipeclass) |
duke@435 | 363 | { |
duke@435 | 364 | const PipeClassResourceForm *piperesource; |
duke@435 | 365 | int * res_cycles = new int [pipeline->_rescount]; |
duke@435 | 366 | int i; |
duke@435 | 367 | |
duke@435 | 368 | for (i = 0; i < pipeline->_rescount; i++) |
duke@435 | 369 | res_cycles[i] = 0; |
duke@435 | 370 | |
duke@435 | 371 | for (pipeclass->_resUsage.reset(); |
duke@435 | 372 | (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) { |
duke@435 | 373 | int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); |
duke@435 | 374 | for (i = 0; i < pipeline->_rescount; i++) |
duke@435 | 375 | if ((1 << i) & used_mask) { |
duke@435 | 376 | int cycles = piperesource->_cycles; |
duke@435 | 377 | if (res_cycles[i] < cycles) |
duke@435 | 378 | res_cycles[i] = cycles; |
duke@435 | 379 | } |
duke@435 | 380 | } |
duke@435 | 381 | |
duke@435 | 382 | // Pre-compute the string length |
duke@435 | 383 | int templen; |
duke@435 | 384 | int cyclelen = 0, commentlen = 0; |
duke@435 | 385 | int max_cycles = 0; |
duke@435 | 386 | char temp[32]; |
duke@435 | 387 | |
duke@435 | 388 | for (i = 0; i < pipeline->_rescount; i++) { |
duke@435 | 389 | if (max_cycles < res_cycles[i]) |
duke@435 | 390 | max_cycles = res_cycles[i]; |
duke@435 | 391 | templen = sprintf(temp, "%d", res_cycles[i]); |
duke@435 | 392 | if (cyclelen < templen) |
duke@435 | 393 | cyclelen = templen; |
duke@435 | 394 | commentlen += (int)strlen(pipeline->_reslist.name(i)); |
duke@435 | 395 | } |
duke@435 | 396 | |
duke@435 | 397 | templen = 1 + commentlen + (cyclelen + 8) * pipeline->_rescount; |
duke@435 | 398 | |
duke@435 | 399 | // Allocate space for the resource list |
duke@435 | 400 | char * resource_cycles = new char [templen]; |
duke@435 | 401 | |
duke@435 | 402 | templen = 0; |
duke@435 | 403 | |
duke@435 | 404 | for (i = 0; i < pipeline->_rescount; i++) { |
duke@435 | 405 | templen += sprintf(&resource_cycles[templen], " %*d%c // %s\n", |
duke@435 | 406 | cyclelen, res_cycles[i], (i < pipeline->_rescount-1) ? ',' : ' ', pipeline->_reslist.name(i)); |
duke@435 | 407 | } |
duke@435 | 408 | |
duke@435 | 409 | // See if the same string is in the table |
duke@435 | 410 | int ndx = pipeline_res_cycles.index(resource_cycles); |
duke@435 | 411 | |
duke@435 | 412 | // No, add it to the table |
duke@435 | 413 | if (ndx < 0) { |
duke@435 | 414 | pipeline_res_cycles.addName(resource_cycles); |
duke@435 | 415 | ndx = pipeline_res_cycles.index(resource_cycles); |
duke@435 | 416 | |
duke@435 | 417 | fprintf(fp_cpp, "static const uint pipeline_res_cycles_%03d[%d] = {\n%s};\n\n", |
duke@435 | 418 | ndx+1, pipeline->_rescount, resource_cycles); |
duke@435 | 419 | } |
duke@435 | 420 | else |
duke@435 | 421 | delete [] resource_cycles; |
duke@435 | 422 | |
duke@435 | 423 | delete [] res_cycles; |
duke@435 | 424 | |
duke@435 | 425 | return (ndx); |
duke@435 | 426 | } |
duke@435 | 427 | |
duke@435 | 428 | //typedef unsigned long long uint64_t; |
duke@435 | 429 | |
duke@435 | 430 | // Compute an index for an array in the pipeline_res_mask_NNN arrays |
duke@435 | 431 | static int pipeline_res_mask_initializer( |
duke@435 | 432 | FILE *fp_cpp, |
duke@435 | 433 | PipelineForm *pipeline, |
duke@435 | 434 | NameList &pipeline_res_mask, |
duke@435 | 435 | NameList &pipeline_res_args, |
duke@435 | 436 | PipeClassForm *pipeclass) |
duke@435 | 437 | { |
duke@435 | 438 | const PipeClassResourceForm *piperesource; |
duke@435 | 439 | const uint rescount = pipeline->_rescount; |
duke@435 | 440 | const uint maxcycleused = pipeline->_maxcycleused; |
duke@435 | 441 | const uint cyclemasksize = (maxcycleused + 31) >> 5; |
duke@435 | 442 | |
duke@435 | 443 | int i, j; |
duke@435 | 444 | int element_count = 0; |
duke@435 | 445 | uint *res_mask = new uint [cyclemasksize]; |
duke@435 | 446 | uint resources_used = 0; |
duke@435 | 447 | uint resources_used_exclusively = 0; |
duke@435 | 448 | |
duke@435 | 449 | for (pipeclass->_resUsage.reset(); |
duke@435 | 450 | (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) |
duke@435 | 451 | element_count++; |
duke@435 | 452 | |
duke@435 | 453 | // Pre-compute the string length |
duke@435 | 454 | int templen; |
duke@435 | 455 | int commentlen = 0; |
duke@435 | 456 | int max_cycles = 0; |
duke@435 | 457 | |
duke@435 | 458 | int cyclelen = ((maxcycleused + 3) >> 2); |
duke@435 | 459 | int masklen = (rescount + 3) >> 2; |
duke@435 | 460 | |
duke@435 | 461 | int cycledigit = 0; |
duke@435 | 462 | for (i = maxcycleused; i > 0; i /= 10) |
duke@435 | 463 | cycledigit++; |
duke@435 | 464 | |
duke@435 | 465 | int maskdigit = 0; |
duke@435 | 466 | for (i = rescount; i > 0; i /= 10) |
duke@435 | 467 | maskdigit++; |
duke@435 | 468 | |
duke@435 | 469 | static const char * pipeline_use_cycle_mask = "Pipeline_Use_Cycle_Mask"; |
duke@435 | 470 | static const char * pipeline_use_element = "Pipeline_Use_Element"; |
duke@435 | 471 | |
duke@435 | 472 | templen = 1 + |
duke@435 | 473 | (int)(strlen(pipeline_use_cycle_mask) + (int)strlen(pipeline_use_element) + |
duke@435 | 474 | (cyclemasksize * 12) + masklen + (cycledigit * 2) + 30) * element_count; |
duke@435 | 475 | |
duke@435 | 476 | // Allocate space for the resource list |
duke@435 | 477 | char * resource_mask = new char [templen]; |
duke@435 | 478 | char * last_comma = NULL; |
duke@435 | 479 | |
duke@435 | 480 | templen = 0; |
duke@435 | 481 | |
duke@435 | 482 | for (pipeclass->_resUsage.reset(); |
duke@435 | 483 | (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) { |
duke@435 | 484 | int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); |
duke@435 | 485 | |
duke@435 | 486 | if (!used_mask) |
duke@435 | 487 | fprintf(stderr, "*** used_mask is 0 ***\n"); |
duke@435 | 488 | |
duke@435 | 489 | resources_used |= used_mask; |
duke@435 | 490 | |
duke@435 | 491 | uint lb, ub; |
duke@435 | 492 | |
duke@435 | 493 | for (lb = 0; (used_mask & (1 << lb)) == 0; lb++); |
duke@435 | 494 | for (ub = 31; (used_mask & (1 << ub)) == 0; ub--); |
duke@435 | 495 | |
duke@435 | 496 | if (lb == ub) |
duke@435 | 497 | resources_used_exclusively |= used_mask; |
duke@435 | 498 | |
duke@435 | 499 | int formatlen = |
duke@435 | 500 | sprintf(&resource_mask[templen], " %s(0x%0*x, %*d, %*d, %s %s(", |
duke@435 | 501 | pipeline_use_element, |
duke@435 | 502 | masklen, used_mask, |
duke@435 | 503 | cycledigit, lb, cycledigit, ub, |
duke@435 | 504 | ((used_mask & (used_mask-1)) != 0) ? "true, " : "false,", |
duke@435 | 505 | pipeline_use_cycle_mask); |
duke@435 | 506 | |
duke@435 | 507 | templen += formatlen; |
duke@435 | 508 | |
duke@435 | 509 | memset(res_mask, 0, cyclemasksize * sizeof(uint)); |
duke@435 | 510 | |
duke@435 | 511 | int cycles = piperesource->_cycles; |
duke@435 | 512 | uint stage = pipeline->_stages.index(piperesource->_stage); |
duke@435 | 513 | uint upper_limit = stage+cycles-1; |
duke@435 | 514 | uint lower_limit = stage-1; |
duke@435 | 515 | uint upper_idx = upper_limit >> 5; |
duke@435 | 516 | uint lower_idx = lower_limit >> 5; |
duke@435 | 517 | uint upper_position = upper_limit & 0x1f; |
duke@435 | 518 | uint lower_position = lower_limit & 0x1f; |
duke@435 | 519 | |
duke@435 | 520 | uint mask = (((uint)1) << upper_position) - 1; |
duke@435 | 521 | |
duke@435 | 522 | while ( upper_idx > lower_idx ) { |
duke@435 | 523 | res_mask[upper_idx--] |= mask; |
duke@435 | 524 | mask = (uint)-1; |
duke@435 | 525 | } |
duke@435 | 526 | |
duke@435 | 527 | mask -= (((uint)1) << lower_position) - 1; |
duke@435 | 528 | res_mask[upper_idx] |= mask; |
duke@435 | 529 | |
duke@435 | 530 | for (j = cyclemasksize-1; j >= 0; j--) { |
duke@435 | 531 | formatlen = |
duke@435 | 532 | sprintf(&resource_mask[templen], "0x%08x%s", res_mask[j], j > 0 ? ", " : ""); |
duke@435 | 533 | templen += formatlen; |
duke@435 | 534 | } |
duke@435 | 535 | |
duke@435 | 536 | resource_mask[templen++] = ')'; |
duke@435 | 537 | resource_mask[templen++] = ')'; |
duke@435 | 538 | last_comma = &resource_mask[templen]; |
duke@435 | 539 | resource_mask[templen++] = ','; |
duke@435 | 540 | resource_mask[templen++] = '\n'; |
duke@435 | 541 | } |
duke@435 | 542 | |
duke@435 | 543 | resource_mask[templen] = 0; |
duke@435 | 544 | if (last_comma) |
duke@435 | 545 | last_comma[0] = ' '; |
duke@435 | 546 | |
duke@435 | 547 | // See if the same string is in the table |
duke@435 | 548 | int ndx = pipeline_res_mask.index(resource_mask); |
duke@435 | 549 | |
duke@435 | 550 | // No, add it to the table |
duke@435 | 551 | if (ndx < 0) { |
duke@435 | 552 | pipeline_res_mask.addName(resource_mask); |
duke@435 | 553 | ndx = pipeline_res_mask.index(resource_mask); |
duke@435 | 554 | |
duke@435 | 555 | if (strlen(resource_mask) > 0) |
duke@435 | 556 | fprintf(fp_cpp, "static const Pipeline_Use_Element pipeline_res_mask_%03d[%d] = {\n%s};\n\n", |
duke@435 | 557 | ndx+1, element_count, resource_mask); |
duke@435 | 558 | |
duke@435 | 559 | char * args = new char [9 + 2*masklen + maskdigit]; |
duke@435 | 560 | |
duke@435 | 561 | sprintf(args, "0x%0*x, 0x%0*x, %*d", |
duke@435 | 562 | masklen, resources_used, |
duke@435 | 563 | masklen, resources_used_exclusively, |
duke@435 | 564 | maskdigit, element_count); |
duke@435 | 565 | |
duke@435 | 566 | pipeline_res_args.addName(args); |
duke@435 | 567 | } |
duke@435 | 568 | else |
duke@435 | 569 | delete [] resource_mask; |
duke@435 | 570 | |
duke@435 | 571 | delete [] res_mask; |
duke@435 | 572 | //delete [] res_masks; |
duke@435 | 573 | |
duke@435 | 574 | return (ndx); |
duke@435 | 575 | } |
duke@435 | 576 | |
duke@435 | 577 | void ArchDesc::build_pipe_classes(FILE *fp_cpp) { |
duke@435 | 578 | const char *classname; |
duke@435 | 579 | const char *resourcename; |
duke@435 | 580 | int resourcenamelen = 0; |
duke@435 | 581 | NameList pipeline_reads; |
duke@435 | 582 | NameList pipeline_res_stages; |
duke@435 | 583 | NameList pipeline_res_cycles; |
duke@435 | 584 | NameList pipeline_res_masks; |
duke@435 | 585 | NameList pipeline_res_args; |
duke@435 | 586 | const int default_latency = 1; |
duke@435 | 587 | const int non_operand_latency = 0; |
duke@435 | 588 | const int node_latency = 0; |
duke@435 | 589 | |
duke@435 | 590 | if (!_pipeline) { |
duke@435 | 591 | fprintf(fp_cpp, "uint Node::latency(uint i) const {\n"); |
duke@435 | 592 | fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n"); |
duke@435 | 593 | fprintf(fp_cpp, " return %d;\n", non_operand_latency); |
duke@435 | 594 | fprintf(fp_cpp, "}\n"); |
duke@435 | 595 | return; |
duke@435 | 596 | } |
duke@435 | 597 | |
duke@435 | 598 | fprintf(fp_cpp, "\n"); |
duke@435 | 599 | fprintf(fp_cpp, "//------------------Pipeline Methods-----------------------------------------\n"); |
duke@435 | 600 | fprintf(fp_cpp, "#ifndef PRODUCT\n"); |
duke@435 | 601 | fprintf(fp_cpp, "const char * Pipeline::stageName(uint s) {\n"); |
duke@435 | 602 | fprintf(fp_cpp, " static const char * const _stage_names[] = {\n"); |
duke@435 | 603 | fprintf(fp_cpp, " \"undefined\""); |
duke@435 | 604 | |
duke@435 | 605 | for (int s = 0; s < _pipeline->_stagecnt; s++) |
duke@435 | 606 | fprintf(fp_cpp, ", \"%s\"", _pipeline->_stages.name(s)); |
duke@435 | 607 | |
duke@435 | 608 | fprintf(fp_cpp, "\n };\n\n"); |
duke@435 | 609 | fprintf(fp_cpp, " return (s <= %d ? _stage_names[s] : \"???\");\n", |
duke@435 | 610 | _pipeline->_stagecnt); |
duke@435 | 611 | fprintf(fp_cpp, "}\n"); |
duke@435 | 612 | fprintf(fp_cpp, "#endif\n\n"); |
duke@435 | 613 | |
duke@435 | 614 | fprintf(fp_cpp, "uint Pipeline::functional_unit_latency(uint start, const Pipeline *pred) const {\n"); |
duke@435 | 615 | fprintf(fp_cpp, " // See if the functional units overlap\n"); |
duke@435 | 616 | #if 0 |
duke@435 | 617 | fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); |
duke@435 | 618 | fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); |
duke@435 | 619 | fprintf(fp_cpp, " tty->print(\"# functional_unit_latency: start == %%d, this->exclusively == 0x%%03x, pred->exclusively == 0x%%03x\\n\", start, resourcesUsedExclusively(), pred->resourcesUsedExclusively());\n"); |
duke@435 | 620 | fprintf(fp_cpp, " }\n"); |
duke@435 | 621 | fprintf(fp_cpp, "#endif\n\n"); |
duke@435 | 622 | #endif |
duke@435 | 623 | fprintf(fp_cpp, " uint mask = resourcesUsedExclusively() & pred->resourcesUsedExclusively();\n"); |
duke@435 | 624 | fprintf(fp_cpp, " if (mask == 0)\n return (start);\n\n"); |
duke@435 | 625 | #if 0 |
duke@435 | 626 | fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); |
duke@435 | 627 | fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); |
duke@435 | 628 | fprintf(fp_cpp, " tty->print(\"# functional_unit_latency: mask == 0x%%x\\n\", mask);\n"); |
duke@435 | 629 | fprintf(fp_cpp, " }\n"); |
duke@435 | 630 | fprintf(fp_cpp, "#endif\n\n"); |
duke@435 | 631 | #endif |
duke@435 | 632 | fprintf(fp_cpp, " for (uint i = 0; i < pred->resourceUseCount(); i++) {\n"); |
duke@435 | 633 | fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred->resourceUseElement(i);\n"); |
duke@435 | 634 | fprintf(fp_cpp, " if (predUse->multiple())\n"); |
duke@435 | 635 | fprintf(fp_cpp, " continue;\n\n"); |
duke@435 | 636 | fprintf(fp_cpp, " for (uint j = 0; j < resourceUseCount(); j++) {\n"); |
duke@435 | 637 | fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = resourceUseElement(j);\n"); |
duke@435 | 638 | fprintf(fp_cpp, " if (currUse->multiple())\n"); |
duke@435 | 639 | fprintf(fp_cpp, " continue;\n\n"); |
duke@435 | 640 | fprintf(fp_cpp, " if (predUse->used() & currUse->used()) {\n"); |
duke@435 | 641 | fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->mask();\n"); |
duke@435 | 642 | fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->mask();\n\n"); |
duke@435 | 643 | fprintf(fp_cpp, " for ( y <<= start; x.overlaps(y); start++ )\n"); |
duke@435 | 644 | fprintf(fp_cpp, " y <<= 1;\n"); |
duke@435 | 645 | fprintf(fp_cpp, " }\n"); |
duke@435 | 646 | fprintf(fp_cpp, " }\n"); |
duke@435 | 647 | fprintf(fp_cpp, " }\n\n"); |
duke@435 | 648 | fprintf(fp_cpp, " // There is the potential for overlap\n"); |
duke@435 | 649 | fprintf(fp_cpp, " return (start);\n"); |
duke@435 | 650 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 651 | fprintf(fp_cpp, "// The following two routines assume that the root Pipeline_Use entity\n"); |
duke@435 | 652 | fprintf(fp_cpp, "// consists of exactly 1 element for each functional unit\n"); |
duke@435 | 653 | fprintf(fp_cpp, "// start is relative to the current cycle; used for latency-based info\n"); |
duke@435 | 654 | fprintf(fp_cpp, "uint Pipeline_Use::full_latency(uint delay, const Pipeline_Use &pred) const {\n"); |
duke@435 | 655 | fprintf(fp_cpp, " for (uint i = 0; i < pred._count; i++) {\n"); |
duke@435 | 656 | fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred.element(i);\n"); |
duke@435 | 657 | fprintf(fp_cpp, " if (predUse->_multiple) {\n"); |
duke@435 | 658 | fprintf(fp_cpp, " uint min_delay = %d;\n", |
duke@435 | 659 | _pipeline->_maxcycleused+1); |
duke@435 | 660 | fprintf(fp_cpp, " // Multiple possible functional units, choose first unused one\n"); |
duke@435 | 661 | fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); |
duke@435 | 662 | fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = element(j);\n"); |
duke@435 | 663 | fprintf(fp_cpp, " uint curr_delay = delay;\n"); |
duke@435 | 664 | fprintf(fp_cpp, " if (predUse->_used & currUse->_used) {\n"); |
duke@435 | 665 | fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->_mask;\n"); |
duke@435 | 666 | fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n"); |
duke@435 | 667 | fprintf(fp_cpp, " for ( y <<= curr_delay; x.overlaps(y); curr_delay++ )\n"); |
duke@435 | 668 | fprintf(fp_cpp, " y <<= 1;\n"); |
duke@435 | 669 | fprintf(fp_cpp, " }\n"); |
duke@435 | 670 | fprintf(fp_cpp, " if (min_delay > curr_delay)\n min_delay = curr_delay;\n"); |
duke@435 | 671 | fprintf(fp_cpp, " }\n"); |
duke@435 | 672 | fprintf(fp_cpp, " if (delay < min_delay)\n delay = min_delay;\n"); |
duke@435 | 673 | fprintf(fp_cpp, " }\n"); |
duke@435 | 674 | fprintf(fp_cpp, " else {\n"); |
duke@435 | 675 | fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); |
duke@435 | 676 | fprintf(fp_cpp, " const Pipeline_Use_Element *currUse = element(j);\n"); |
duke@435 | 677 | fprintf(fp_cpp, " if (predUse->_used & currUse->_used) {\n"); |
duke@435 | 678 | fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask x = predUse->_mask;\n"); |
duke@435 | 679 | fprintf(fp_cpp, " Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n"); |
duke@435 | 680 | fprintf(fp_cpp, " for ( y <<= delay; x.overlaps(y); delay++ )\n"); |
duke@435 | 681 | fprintf(fp_cpp, " y <<= 1;\n"); |
duke@435 | 682 | fprintf(fp_cpp, " }\n"); |
duke@435 | 683 | fprintf(fp_cpp, " }\n"); |
duke@435 | 684 | fprintf(fp_cpp, " }\n"); |
duke@435 | 685 | fprintf(fp_cpp, " }\n\n"); |
duke@435 | 686 | fprintf(fp_cpp, " return (delay);\n"); |
duke@435 | 687 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 688 | fprintf(fp_cpp, "void Pipeline_Use::add_usage(const Pipeline_Use &pred) {\n"); |
duke@435 | 689 | fprintf(fp_cpp, " for (uint i = 0; i < pred._count; i++) {\n"); |
duke@435 | 690 | fprintf(fp_cpp, " const Pipeline_Use_Element *predUse = pred.element(i);\n"); |
duke@435 | 691 | fprintf(fp_cpp, " if (predUse->_multiple) {\n"); |
duke@435 | 692 | fprintf(fp_cpp, " // Multiple possible functional units, choose first unused one\n"); |
duke@435 | 693 | fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); |
duke@435 | 694 | fprintf(fp_cpp, " Pipeline_Use_Element *currUse = element(j);\n"); |
duke@435 | 695 | fprintf(fp_cpp, " if ( !predUse->_mask.overlaps(currUse->_mask) ) {\n"); |
duke@435 | 696 | fprintf(fp_cpp, " currUse->_used |= (1 << j);\n"); |
duke@435 | 697 | fprintf(fp_cpp, " _resources_used |= (1 << j);\n"); |
duke@435 | 698 | fprintf(fp_cpp, " currUse->_mask.Or(predUse->_mask);\n"); |
duke@435 | 699 | fprintf(fp_cpp, " break;\n"); |
duke@435 | 700 | fprintf(fp_cpp, " }\n"); |
duke@435 | 701 | fprintf(fp_cpp, " }\n"); |
duke@435 | 702 | fprintf(fp_cpp, " }\n"); |
duke@435 | 703 | fprintf(fp_cpp, " else {\n"); |
duke@435 | 704 | fprintf(fp_cpp, " for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n"); |
duke@435 | 705 | fprintf(fp_cpp, " Pipeline_Use_Element *currUse = element(j);\n"); |
duke@435 | 706 | fprintf(fp_cpp, " currUse->_used |= (1 << j);\n"); |
duke@435 | 707 | fprintf(fp_cpp, " _resources_used |= (1 << j);\n"); |
duke@435 | 708 | fprintf(fp_cpp, " currUse->_mask.Or(predUse->_mask);\n"); |
duke@435 | 709 | fprintf(fp_cpp, " }\n"); |
duke@435 | 710 | fprintf(fp_cpp, " }\n"); |
duke@435 | 711 | fprintf(fp_cpp, " }\n"); |
duke@435 | 712 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 713 | |
duke@435 | 714 | fprintf(fp_cpp, "uint Pipeline::operand_latency(uint opnd, const Pipeline *pred) const {\n"); |
duke@435 | 715 | fprintf(fp_cpp, " int const default_latency = 1;\n"); |
duke@435 | 716 | fprintf(fp_cpp, "\n"); |
duke@435 | 717 | #if 0 |
duke@435 | 718 | fprintf(fp_cpp, "#ifndef PRODUCT\n"); |
duke@435 | 719 | fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); |
duke@435 | 720 | fprintf(fp_cpp, " tty->print(\"# operand_latency(%%d), _read_stage_count = %%d\\n\", opnd, _read_stage_count);\n"); |
duke@435 | 721 | fprintf(fp_cpp, " }\n"); |
duke@435 | 722 | fprintf(fp_cpp, "#endif\n\n"); |
duke@435 | 723 | #endif |
duke@435 | 724 | fprintf(fp_cpp, " assert(this, \"NULL pipeline info\")\n"); |
duke@435 | 725 | fprintf(fp_cpp, " assert(pred, \"NULL predecessor pipline info\")\n\n"); |
duke@435 | 726 | fprintf(fp_cpp, " if (pred->hasFixedLatency())\n return (pred->fixedLatency());\n\n"); |
duke@435 | 727 | fprintf(fp_cpp, " // If this is not an operand, then assume a dependence with 0 latency\n"); |
duke@435 | 728 | fprintf(fp_cpp, " if (opnd > _read_stage_count)\n return (0);\n\n"); |
duke@435 | 729 | fprintf(fp_cpp, " uint writeStage = pred->_write_stage;\n"); |
duke@435 | 730 | fprintf(fp_cpp, " uint readStage = _read_stages[opnd-1];\n"); |
duke@435 | 731 | #if 0 |
duke@435 | 732 | fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); |
duke@435 | 733 | fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); |
duke@435 | 734 | fprintf(fp_cpp, " tty->print(\"# operand_latency: writeStage=%%s readStage=%%s, opnd=%%d\\n\", stageName(writeStage), stageName(readStage), opnd);\n"); |
duke@435 | 735 | fprintf(fp_cpp, " }\n"); |
duke@435 | 736 | fprintf(fp_cpp, "#endif\n\n"); |
duke@435 | 737 | #endif |
duke@435 | 738 | fprintf(fp_cpp, "\n"); |
duke@435 | 739 | fprintf(fp_cpp, " if (writeStage == stage_undefined || readStage == stage_undefined)\n"); |
duke@435 | 740 | fprintf(fp_cpp, " return (default_latency);\n"); |
duke@435 | 741 | fprintf(fp_cpp, "\n"); |
duke@435 | 742 | fprintf(fp_cpp, " int delta = writeStage - readStage;\n"); |
duke@435 | 743 | fprintf(fp_cpp, " if (delta < 0) delta = 0;\n\n"); |
duke@435 | 744 | #if 0 |
duke@435 | 745 | fprintf(fp_cpp, "\n#ifndef PRODUCT\n"); |
duke@435 | 746 | fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); |
duke@435 | 747 | fprintf(fp_cpp, " tty->print(\"# operand_latency: delta=%%d\\n\", delta);\n"); |
duke@435 | 748 | fprintf(fp_cpp, " }\n"); |
duke@435 | 749 | fprintf(fp_cpp, "#endif\n\n"); |
duke@435 | 750 | #endif |
duke@435 | 751 | fprintf(fp_cpp, " return (delta);\n"); |
duke@435 | 752 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 753 | |
duke@435 | 754 | if (!_pipeline) |
duke@435 | 755 | /* Do Nothing */; |
duke@435 | 756 | |
duke@435 | 757 | else if (_pipeline->_maxcycleused <= |
duke@435 | 758 | #ifdef SPARC |
duke@435 | 759 | 64 |
duke@435 | 760 | #else |
duke@435 | 761 | 32 |
duke@435 | 762 | #endif |
duke@435 | 763 | ) { |
duke@435 | 764 | fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); |
duke@435 | 765 | fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(in1._mask & in2._mask);\n"); |
duke@435 | 766 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 767 | fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); |
duke@435 | 768 | fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask(in1._mask | in2._mask);\n"); |
duke@435 | 769 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 770 | } |
duke@435 | 771 | else { |
duke@435 | 772 | uint l; |
duke@435 | 773 | uint masklen = (_pipeline->_maxcycleused + 31) >> 5; |
duke@435 | 774 | fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); |
duke@435 | 775 | fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask("); |
duke@435 | 776 | for (l = 1; l <= masklen; l++) |
duke@435 | 777 | fprintf(fp_cpp, "in1._mask%d & in2._mask%d%s\n", l, l, l < masklen ? ", " : ""); |
duke@435 | 778 | fprintf(fp_cpp, ");\n"); |
duke@435 | 779 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 780 | fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n"); |
duke@435 | 781 | fprintf(fp_cpp, " return Pipeline_Use_Cycle_Mask("); |
duke@435 | 782 | for (l = 1; l <= masklen; l++) |
duke@435 | 783 | fprintf(fp_cpp, "in1._mask%d | in2._mask%d%s", l, l, l < masklen ? ", " : ""); |
duke@435 | 784 | fprintf(fp_cpp, ");\n"); |
duke@435 | 785 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 786 | fprintf(fp_cpp, "void Pipeline_Use_Cycle_Mask::Or(const Pipeline_Use_Cycle_Mask &in2) {\n "); |
duke@435 | 787 | for (l = 1; l <= masklen; l++) |
duke@435 | 788 | fprintf(fp_cpp, " _mask%d |= in2._mask%d;", l, l); |
duke@435 | 789 | fprintf(fp_cpp, "\n}\n\n"); |
duke@435 | 790 | } |
duke@435 | 791 | |
duke@435 | 792 | /* Get the length of all the resource names */ |
duke@435 | 793 | for (_pipeline->_reslist.reset(), resourcenamelen = 0; |
duke@435 | 794 | (resourcename = _pipeline->_reslist.iter()) != NULL; |
duke@435 | 795 | resourcenamelen += (int)strlen(resourcename)); |
duke@435 | 796 | |
duke@435 | 797 | // Create the pipeline class description |
duke@435 | 798 | |
duke@435 | 799 | fprintf(fp_cpp, "static const Pipeline pipeline_class_Zero_Instructions(0, 0, true, 0, 0, false, false, false, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n"); |
duke@435 | 800 | fprintf(fp_cpp, "static const Pipeline pipeline_class_Unknown_Instructions(0, 0, true, 0, 0, false, true, true, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n"); |
duke@435 | 801 | |
duke@435 | 802 | fprintf(fp_cpp, "const Pipeline_Use_Element Pipeline_Use::elaborated_elements[%d] = {\n", _pipeline->_rescount); |
duke@435 | 803 | for (int i1 = 0; i1 < _pipeline->_rescount; i1++) { |
duke@435 | 804 | fprintf(fp_cpp, " Pipeline_Use_Element(0, %d, %d, false, Pipeline_Use_Cycle_Mask(", i1, i1); |
duke@435 | 805 | uint masklen = (_pipeline->_maxcycleused + 31) >> 5; |
duke@435 | 806 | for (int i2 = masklen-1; i2 >= 0; i2--) |
duke@435 | 807 | fprintf(fp_cpp, "0%s", i2 > 0 ? ", " : ""); |
duke@435 | 808 | fprintf(fp_cpp, "))%s\n", i1 < (_pipeline->_rescount-1) ? "," : ""); |
duke@435 | 809 | } |
duke@435 | 810 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 811 | |
duke@435 | 812 | fprintf(fp_cpp, "const Pipeline_Use Pipeline_Use::elaborated_use(0, 0, %d, (Pipeline_Use_Element *)&elaborated_elements[0]);\n\n", |
duke@435 | 813 | _pipeline->_rescount); |
duke@435 | 814 | |
duke@435 | 815 | for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) { |
duke@435 | 816 | fprintf(fp_cpp, "\n"); |
duke@435 | 817 | fprintf(fp_cpp, "// Pipeline Class \"%s\"\n", classname); |
duke@435 | 818 | PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass(); |
duke@435 | 819 | int maxWriteStage = -1; |
duke@435 | 820 | int maxMoreInstrs = 0; |
duke@435 | 821 | int paramcount = 0; |
duke@435 | 822 | int i = 0; |
duke@435 | 823 | const char *paramname; |
duke@435 | 824 | int resource_count = (_pipeline->_rescount + 3) >> 2; |
duke@435 | 825 | |
duke@435 | 826 | // Scan the operands, looking for last output stage and number of inputs |
duke@435 | 827 | for (pipeclass->_parameters.reset(); (paramname = pipeclass->_parameters.iter()) != NULL; ) { |
duke@435 | 828 | const PipeClassOperandForm *pipeopnd = |
duke@435 | 829 | (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
duke@435 | 830 | if (pipeopnd) { |
duke@435 | 831 | if (pipeopnd->_iswrite) { |
duke@435 | 832 | int stagenum = _pipeline->_stages.index(pipeopnd->_stage); |
duke@435 | 833 | int moreinsts = pipeopnd->_more_instrs; |
duke@435 | 834 | if ((maxWriteStage+maxMoreInstrs) < (stagenum+moreinsts)) { |
duke@435 | 835 | maxWriteStage = stagenum; |
duke@435 | 836 | maxMoreInstrs = moreinsts; |
duke@435 | 837 | } |
duke@435 | 838 | } |
duke@435 | 839 | } |
duke@435 | 840 | |
duke@435 | 841 | if (i++ > 0 || (pipeopnd && !pipeopnd->isWrite())) |
duke@435 | 842 | paramcount++; |
duke@435 | 843 | } |
duke@435 | 844 | |
duke@435 | 845 | // Create the list of stages for the operands that are read |
duke@435 | 846 | // Note that we will build a NameList to reduce the number of copies |
duke@435 | 847 | |
duke@435 | 848 | int pipeline_reads_index = pipeline_reads_initializer(fp_cpp, pipeline_reads, pipeclass); |
duke@435 | 849 | |
duke@435 | 850 | int pipeline_res_stages_index = pipeline_res_stages_initializer( |
duke@435 | 851 | fp_cpp, _pipeline, pipeline_res_stages, pipeclass); |
duke@435 | 852 | |
duke@435 | 853 | int pipeline_res_cycles_index = pipeline_res_cycles_initializer( |
duke@435 | 854 | fp_cpp, _pipeline, pipeline_res_cycles, pipeclass); |
duke@435 | 855 | |
duke@435 | 856 | int pipeline_res_mask_index = pipeline_res_mask_initializer( |
duke@435 | 857 | fp_cpp, _pipeline, pipeline_res_masks, pipeline_res_args, pipeclass); |
duke@435 | 858 | |
duke@435 | 859 | #if 0 |
duke@435 | 860 | // Process the Resources |
duke@435 | 861 | const PipeClassResourceForm *piperesource; |
duke@435 | 862 | |
duke@435 | 863 | unsigned resources_used = 0; |
duke@435 | 864 | unsigned exclusive_resources_used = 0; |
duke@435 | 865 | unsigned resource_groups = 0; |
duke@435 | 866 | for (pipeclass->_resUsage.reset(); |
duke@435 | 867 | (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) { |
duke@435 | 868 | int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); |
duke@435 | 869 | if (used_mask) |
duke@435 | 870 | resource_groups++; |
duke@435 | 871 | resources_used |= used_mask; |
duke@435 | 872 | if ((used_mask & (used_mask-1)) == 0) |
duke@435 | 873 | exclusive_resources_used |= used_mask; |
duke@435 | 874 | } |
duke@435 | 875 | |
duke@435 | 876 | if (resource_groups > 0) { |
duke@435 | 877 | fprintf(fp_cpp, "static const uint pipeline_res_or_masks_%03d[%d] = {", |
duke@435 | 878 | pipeclass->_num, resource_groups); |
duke@435 | 879 | for (pipeclass->_resUsage.reset(), i = 1; |
duke@435 | 880 | (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; |
duke@435 | 881 | i++ ) { |
duke@435 | 882 | int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask(); |
duke@435 | 883 | if (used_mask) { |
duke@435 | 884 | fprintf(fp_cpp, " 0x%0*x%c", resource_count, used_mask, i < (int)resource_groups ? ',' : ' '); |
duke@435 | 885 | } |
duke@435 | 886 | } |
duke@435 | 887 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 888 | } |
duke@435 | 889 | #endif |
duke@435 | 890 | |
duke@435 | 891 | // Create the pipeline class description |
duke@435 | 892 | fprintf(fp_cpp, "static const Pipeline pipeline_class_%03d(", |
duke@435 | 893 | pipeclass->_num); |
duke@435 | 894 | if (maxWriteStage < 0) |
duke@435 | 895 | fprintf(fp_cpp, "(uint)stage_undefined"); |
duke@435 | 896 | else if (maxMoreInstrs == 0) |
duke@435 | 897 | fprintf(fp_cpp, "(uint)stage_%s", _pipeline->_stages.name(maxWriteStage)); |
duke@435 | 898 | else |
duke@435 | 899 | fprintf(fp_cpp, "((uint)stage_%s)+%d", _pipeline->_stages.name(maxWriteStage), maxMoreInstrs); |
duke@435 | 900 | fprintf(fp_cpp, ", %d, %s, %d, %d, %s, %s, %s, %s,\n", |
duke@435 | 901 | paramcount, |
duke@435 | 902 | pipeclass->hasFixedLatency() ? "true" : "false", |
duke@435 | 903 | pipeclass->fixedLatency(), |
duke@435 | 904 | pipeclass->InstructionCount(), |
duke@435 | 905 | pipeclass->hasBranchDelay() ? "true" : "false", |
duke@435 | 906 | pipeclass->hasMultipleBundles() ? "true" : "false", |
duke@435 | 907 | pipeclass->forceSerialization() ? "true" : "false", |
duke@435 | 908 | pipeclass->mayHaveNoCode() ? "true" : "false" ); |
duke@435 | 909 | if (paramcount > 0) { |
duke@435 | 910 | fprintf(fp_cpp, "\n (enum machPipelineStages * const) pipeline_reads_%03d,\n ", |
duke@435 | 911 | pipeline_reads_index+1); |
duke@435 | 912 | } |
duke@435 | 913 | else |
duke@435 | 914 | fprintf(fp_cpp, " NULL,"); |
duke@435 | 915 | fprintf(fp_cpp, " (enum machPipelineStages * const) pipeline_res_stages_%03d,\n", |
duke@435 | 916 | pipeline_res_stages_index+1); |
duke@435 | 917 | fprintf(fp_cpp, " (uint * const) pipeline_res_cycles_%03d,\n", |
duke@435 | 918 | pipeline_res_cycles_index+1); |
duke@435 | 919 | fprintf(fp_cpp, " Pipeline_Use(%s, (Pipeline_Use_Element *)", |
duke@435 | 920 | pipeline_res_args.name(pipeline_res_mask_index)); |
duke@435 | 921 | if (strlen(pipeline_res_masks.name(pipeline_res_mask_index)) > 0) |
duke@435 | 922 | fprintf(fp_cpp, "&pipeline_res_mask_%03d[0]", |
duke@435 | 923 | pipeline_res_mask_index+1); |
duke@435 | 924 | else |
duke@435 | 925 | fprintf(fp_cpp, "NULL"); |
duke@435 | 926 | fprintf(fp_cpp, "));\n"); |
duke@435 | 927 | } |
duke@435 | 928 | |
duke@435 | 929 | // Generate the Node::latency method if _pipeline defined |
duke@435 | 930 | fprintf(fp_cpp, "\n"); |
duke@435 | 931 | fprintf(fp_cpp, "//------------------Inter-Instruction Latency--------------------------------\n"); |
duke@435 | 932 | fprintf(fp_cpp, "uint Node::latency(uint i) {\n"); |
duke@435 | 933 | if (_pipeline) { |
duke@435 | 934 | #if 0 |
duke@435 | 935 | fprintf(fp_cpp, "#ifndef PRODUCT\n"); |
duke@435 | 936 | fprintf(fp_cpp, " if (TraceOptoOutput) {\n"); |
duke@435 | 937 | fprintf(fp_cpp, " tty->print(\"# %%4d->latency(%%d)\\n\", _idx, i);\n"); |
duke@435 | 938 | fprintf(fp_cpp, " }\n"); |
duke@435 | 939 | fprintf(fp_cpp, "#endif\n"); |
duke@435 | 940 | #endif |
duke@435 | 941 | fprintf(fp_cpp, " uint j;\n"); |
duke@435 | 942 | fprintf(fp_cpp, " // verify in legal range for inputs\n"); |
duke@435 | 943 | fprintf(fp_cpp, " assert(i < len(), \"index not in range\");\n\n"); |
duke@435 | 944 | fprintf(fp_cpp, " // verify input is not null\n"); |
duke@435 | 945 | fprintf(fp_cpp, " Node *pred = in(i);\n"); |
duke@435 | 946 | fprintf(fp_cpp, " if (!pred)\n return %d;\n\n", |
duke@435 | 947 | non_operand_latency); |
duke@435 | 948 | fprintf(fp_cpp, " if (pred->is_Proj())\n pred = pred->in(0);\n\n"); |
duke@435 | 949 | fprintf(fp_cpp, " // if either node does not have pipeline info, use default\n"); |
duke@435 | 950 | fprintf(fp_cpp, " const Pipeline *predpipe = pred->pipeline();\n"); |
duke@435 | 951 | fprintf(fp_cpp, " assert(predpipe, \"no predecessor pipeline info\");\n\n"); |
duke@435 | 952 | fprintf(fp_cpp, " if (predpipe->hasFixedLatency())\n return predpipe->fixedLatency();\n\n"); |
duke@435 | 953 | fprintf(fp_cpp, " const Pipeline *currpipe = pipeline();\n"); |
duke@435 | 954 | fprintf(fp_cpp, " assert(currpipe, \"no pipeline info\");\n\n"); |
duke@435 | 955 | fprintf(fp_cpp, " if (!is_Mach())\n return %d;\n\n", |
duke@435 | 956 | node_latency); |
duke@435 | 957 | fprintf(fp_cpp, " const MachNode *m = as_Mach();\n"); |
duke@435 | 958 | fprintf(fp_cpp, " j = m->oper_input_base();\n"); |
duke@435 | 959 | fprintf(fp_cpp, " if (i < j)\n return currpipe->functional_unit_latency(%d, predpipe);\n\n", |
duke@435 | 960 | non_operand_latency); |
duke@435 | 961 | fprintf(fp_cpp, " // determine which operand this is in\n"); |
duke@435 | 962 | fprintf(fp_cpp, " uint n = m->num_opnds();\n"); |
duke@435 | 963 | fprintf(fp_cpp, " int delta = %d;\n\n", |
duke@435 | 964 | non_operand_latency); |
duke@435 | 965 | fprintf(fp_cpp, " uint k;\n"); |
duke@435 | 966 | fprintf(fp_cpp, " for (k = 1; k < n; k++) {\n"); |
duke@435 | 967 | fprintf(fp_cpp, " j += m->_opnds[k]->num_edges();\n"); |
duke@435 | 968 | fprintf(fp_cpp, " if (i < j)\n"); |
duke@435 | 969 | fprintf(fp_cpp, " break;\n"); |
duke@435 | 970 | fprintf(fp_cpp, " }\n"); |
duke@435 | 971 | fprintf(fp_cpp, " if (k < n)\n"); |
duke@435 | 972 | fprintf(fp_cpp, " delta = currpipe->operand_latency(k,predpipe);\n\n"); |
duke@435 | 973 | fprintf(fp_cpp, " return currpipe->functional_unit_latency(delta, predpipe);\n"); |
duke@435 | 974 | } |
duke@435 | 975 | else { |
duke@435 | 976 | fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n"); |
duke@435 | 977 | fprintf(fp_cpp, " return %d;\n", |
duke@435 | 978 | non_operand_latency); |
duke@435 | 979 | } |
duke@435 | 980 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 981 | |
duke@435 | 982 | // Output the list of nop nodes |
duke@435 | 983 | fprintf(fp_cpp, "// Descriptions for emitting different functional unit nops\n"); |
duke@435 | 984 | const char *nop; |
duke@435 | 985 | int nopcnt = 0; |
duke@435 | 986 | for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; nopcnt++ ); |
duke@435 | 987 | |
duke@435 | 988 | fprintf(fp_cpp, "void Bundle::initialize_nops(MachNode * nop_list[%d], Compile *C) {\n", nopcnt); |
duke@435 | 989 | int i = 0; |
duke@435 | 990 | for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; i++ ) { |
duke@435 | 991 | fprintf(fp_cpp, " nop_list[%d] = (MachNode *) new (C) %sNode();\n", i, nop); |
duke@435 | 992 | } |
duke@435 | 993 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 994 | fprintf(fp_cpp, "#ifndef PRODUCT\n"); |
duke@435 | 995 | fprintf(fp_cpp, "void Bundle::dump() const {\n"); |
duke@435 | 996 | fprintf(fp_cpp, " static const char * bundle_flags[] = {\n"); |
duke@435 | 997 | fprintf(fp_cpp, " \"\",\n"); |
duke@435 | 998 | fprintf(fp_cpp, " \"use nop delay\",\n"); |
duke@435 | 999 | fprintf(fp_cpp, " \"use unconditional delay\",\n"); |
duke@435 | 1000 | fprintf(fp_cpp, " \"use conditional delay\",\n"); |
duke@435 | 1001 | fprintf(fp_cpp, " \"used in conditional delay\",\n"); |
duke@435 | 1002 | fprintf(fp_cpp, " \"used in unconditional delay\",\n"); |
duke@435 | 1003 | fprintf(fp_cpp, " \"used in all conditional delays\",\n"); |
duke@435 | 1004 | fprintf(fp_cpp, " };\n\n"); |
duke@435 | 1005 | |
duke@435 | 1006 | fprintf(fp_cpp, " static const char *resource_names[%d] = {", _pipeline->_rescount); |
duke@435 | 1007 | for (i = 0; i < _pipeline->_rescount; i++) |
duke@435 | 1008 | fprintf(fp_cpp, " \"%s\"%c", _pipeline->_reslist.name(i), i < _pipeline->_rescount-1 ? ',' : ' '); |
duke@435 | 1009 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 1010 | |
duke@435 | 1011 | // See if the same string is in the table |
duke@435 | 1012 | fprintf(fp_cpp, " bool needs_comma = false;\n\n"); |
duke@435 | 1013 | fprintf(fp_cpp, " if (_flags) {\n"); |
duke@435 | 1014 | fprintf(fp_cpp, " tty->print(\"%%s\", bundle_flags[_flags]);\n"); |
duke@435 | 1015 | fprintf(fp_cpp, " needs_comma = true;\n"); |
duke@435 | 1016 | fprintf(fp_cpp, " };\n"); |
duke@435 | 1017 | fprintf(fp_cpp, " if (instr_count()) {\n"); |
duke@435 | 1018 | fprintf(fp_cpp, " tty->print(\"%%s%%d instr%%s\", needs_comma ? \", \" : \"\", instr_count(), instr_count() != 1 ? \"s\" : \"\");\n"); |
duke@435 | 1019 | fprintf(fp_cpp, " needs_comma = true;\n"); |
duke@435 | 1020 | fprintf(fp_cpp, " };\n"); |
duke@435 | 1021 | fprintf(fp_cpp, " uint r = resources_used();\n"); |
duke@435 | 1022 | fprintf(fp_cpp, " if (r) {\n"); |
duke@435 | 1023 | fprintf(fp_cpp, " tty->print(\"%%sresource%%s:\", needs_comma ? \", \" : \"\", (r & (r-1)) != 0 ? \"s\" : \"\");\n"); |
duke@435 | 1024 | fprintf(fp_cpp, " for (uint i = 0; i < %d; i++)\n", _pipeline->_rescount); |
duke@435 | 1025 | fprintf(fp_cpp, " if ((r & (1 << i)) != 0)\n"); |
duke@435 | 1026 | fprintf(fp_cpp, " tty->print(\" %%s\", resource_names[i]);\n"); |
duke@435 | 1027 | fprintf(fp_cpp, " needs_comma = true;\n"); |
duke@435 | 1028 | fprintf(fp_cpp, " };\n"); |
duke@435 | 1029 | fprintf(fp_cpp, " tty->print(\"\\n\");\n"); |
duke@435 | 1030 | fprintf(fp_cpp, "}\n"); |
duke@435 | 1031 | fprintf(fp_cpp, "#endif\n"); |
duke@435 | 1032 | } |
duke@435 | 1033 | |
duke@435 | 1034 | // --------------------------------------------------------------------------- |
duke@435 | 1035 | //------------------------------Utilities to build Instruction Classes-------- |
duke@435 | 1036 | // --------------------------------------------------------------------------- |
duke@435 | 1037 | |
duke@435 | 1038 | static void defineOut_RegMask(FILE *fp, const char *node, const char *regMask) { |
duke@435 | 1039 | fprintf(fp,"const RegMask &%sNode::out_RegMask() const { return (%s); }\n", |
duke@435 | 1040 | node, regMask); |
duke@435 | 1041 | } |
duke@435 | 1042 | |
duke@435 | 1043 | // Scan the peepmatch and output a test for each instruction |
duke@435 | 1044 | static void check_peepmatch_instruction_tree(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) { |
duke@435 | 1045 | intptr_t parent = -1; |
duke@435 | 1046 | intptr_t inst_position = 0; |
duke@435 | 1047 | const char *inst_name = NULL; |
duke@435 | 1048 | intptr_t input = 0; |
duke@435 | 1049 | fprintf(fp, " // Check instruction sub-tree\n"); |
duke@435 | 1050 | pmatch->reset(); |
duke@435 | 1051 | for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
duke@435 | 1052 | inst_name != NULL; |
duke@435 | 1053 | pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
duke@435 | 1054 | // If this is not a placeholder |
duke@435 | 1055 | if( ! pmatch->is_placeholder() ) { |
duke@435 | 1056 | // Define temporaries 'inst#', based on parent and parent's input index |
duke@435 | 1057 | if( parent != -1 ) { // root was initialized |
duke@435 | 1058 | fprintf(fp, " inst%ld = inst%ld->in(%ld);\n", |
duke@435 | 1059 | inst_position, parent, input); |
duke@435 | 1060 | } |
duke@435 | 1061 | |
duke@435 | 1062 | // When not the root |
duke@435 | 1063 | // Test we have the correct instruction by comparing the rule |
duke@435 | 1064 | if( parent != -1 ) { |
duke@435 | 1065 | fprintf(fp, " matches = matches && ( inst%ld->rule() == %s_rule );", |
duke@435 | 1066 | inst_position, inst_name); |
duke@435 | 1067 | } |
duke@435 | 1068 | } else { |
duke@435 | 1069 | // Check that user did not try to constrain a placeholder |
duke@435 | 1070 | assert( ! pconstraint->constrains_instruction(inst_position), |
duke@435 | 1071 | "fatal(): Can not constrain a placeholder instruction"); |
duke@435 | 1072 | } |
duke@435 | 1073 | } |
duke@435 | 1074 | } |
duke@435 | 1075 | |
duke@435 | 1076 | static void print_block_index(FILE *fp, intptr_t inst_position) { |
duke@435 | 1077 | assert( inst_position >= 0, "Instruction number less than zero"); |
duke@435 | 1078 | fprintf(fp, "block_index"); |
duke@435 | 1079 | if( inst_position != 0 ) { |
duke@435 | 1080 | fprintf(fp, " - %ld", inst_position); |
duke@435 | 1081 | } |
duke@435 | 1082 | } |
duke@435 | 1083 | |
duke@435 | 1084 | // Scan the peepmatch and output a test for each instruction |
duke@435 | 1085 | static void check_peepmatch_instruction_sequence(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) { |
duke@435 | 1086 | intptr_t parent = -1; |
duke@435 | 1087 | intptr_t inst_position = 0; |
duke@435 | 1088 | const char *inst_name = NULL; |
duke@435 | 1089 | intptr_t input = 0; |
duke@435 | 1090 | fprintf(fp, " // Check instruction sub-tree\n"); |
duke@435 | 1091 | pmatch->reset(); |
duke@435 | 1092 | for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
duke@435 | 1093 | inst_name != NULL; |
duke@435 | 1094 | pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
duke@435 | 1095 | // If this is not a placeholder |
duke@435 | 1096 | if( ! pmatch->is_placeholder() ) { |
duke@435 | 1097 | // Define temporaries 'inst#', based on parent and parent's input index |
duke@435 | 1098 | if( parent != -1 ) { // root was initialized |
duke@435 | 1099 | fprintf(fp, " // Identify previous instruction if inside this block\n"); |
duke@435 | 1100 | fprintf(fp, " if( "); |
duke@435 | 1101 | print_block_index(fp, inst_position); |
duke@435 | 1102 | fprintf(fp, " > 0 ) {\n Node *n = block->_nodes.at("); |
duke@435 | 1103 | print_block_index(fp, inst_position); |
duke@435 | 1104 | fprintf(fp, ");\n inst%ld = (n->is_Mach()) ? ", inst_position); |
duke@435 | 1105 | fprintf(fp, "n->as_Mach() : NULL;\n }\n"); |
duke@435 | 1106 | } |
duke@435 | 1107 | |
duke@435 | 1108 | // When not the root |
duke@435 | 1109 | // Test we have the correct instruction by comparing the rule. |
duke@435 | 1110 | if( parent != -1 ) { |
duke@435 | 1111 | fprintf(fp, " matches = matches && (inst%ld != NULL) && (inst%ld->rule() == %s_rule);\n", |
duke@435 | 1112 | inst_position, inst_position, inst_name); |
duke@435 | 1113 | } |
duke@435 | 1114 | } else { |
duke@435 | 1115 | // Check that user did not try to constrain a placeholder |
duke@435 | 1116 | assert( ! pconstraint->constrains_instruction(inst_position), |
duke@435 | 1117 | "fatal(): Can not constrain a placeholder instruction"); |
duke@435 | 1118 | } |
duke@435 | 1119 | } |
duke@435 | 1120 | } |
duke@435 | 1121 | |
duke@435 | 1122 | // Build mapping for register indices, num_edges to input |
duke@435 | 1123 | static void build_instruction_index_mapping( FILE *fp, FormDict &globals, PeepMatch *pmatch ) { |
duke@435 | 1124 | intptr_t parent = -1; |
duke@435 | 1125 | intptr_t inst_position = 0; |
duke@435 | 1126 | const char *inst_name = NULL; |
duke@435 | 1127 | intptr_t input = 0; |
duke@435 | 1128 | fprintf(fp, " // Build map to register info\n"); |
duke@435 | 1129 | pmatch->reset(); |
duke@435 | 1130 | for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
duke@435 | 1131 | inst_name != NULL; |
duke@435 | 1132 | pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
duke@435 | 1133 | // If this is not a placeholder |
duke@435 | 1134 | if( ! pmatch->is_placeholder() ) { |
duke@435 | 1135 | // Define temporaries 'inst#', based on self's inst_position |
duke@435 | 1136 | InstructForm *inst = globals[inst_name]->is_instruction(); |
duke@435 | 1137 | if( inst != NULL ) { |
duke@435 | 1138 | char inst_prefix[] = "instXXXX_"; |
duke@435 | 1139 | sprintf(inst_prefix, "inst%ld_", inst_position); |
duke@435 | 1140 | char receiver[] = "instXXXX->"; |
duke@435 | 1141 | sprintf(receiver, "inst%ld->", inst_position); |
duke@435 | 1142 | inst->index_temps( fp, globals, inst_prefix, receiver ); |
duke@435 | 1143 | } |
duke@435 | 1144 | } |
duke@435 | 1145 | } |
duke@435 | 1146 | } |
duke@435 | 1147 | |
duke@435 | 1148 | // Generate tests for the constraints |
duke@435 | 1149 | static void check_peepconstraints(FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint) { |
duke@435 | 1150 | fprintf(fp, "\n"); |
duke@435 | 1151 | fprintf(fp, " // Check constraints on sub-tree-leaves\n"); |
duke@435 | 1152 | |
duke@435 | 1153 | // Build mapping from num_edges to local variables |
duke@435 | 1154 | build_instruction_index_mapping( fp, globals, pmatch ); |
duke@435 | 1155 | |
duke@435 | 1156 | // Build constraint tests |
duke@435 | 1157 | if( pconstraint != NULL ) { |
duke@435 | 1158 | fprintf(fp, " matches = matches &&"); |
duke@435 | 1159 | bool first_constraint = true; |
duke@435 | 1160 | while( pconstraint != NULL ) { |
duke@435 | 1161 | // indentation and connecting '&&' |
duke@435 | 1162 | const char *indentation = " "; |
duke@435 | 1163 | fprintf(fp, "\n%s%s", indentation, (!first_constraint ? "&& " : " ")); |
duke@435 | 1164 | |
duke@435 | 1165 | // Only have '==' relation implemented |
duke@435 | 1166 | if( strcmp(pconstraint->_relation,"==") != 0 ) { |
duke@435 | 1167 | assert( false, "Unimplemented()" ); |
duke@435 | 1168 | } |
duke@435 | 1169 | |
duke@435 | 1170 | // LEFT |
duke@435 | 1171 | intptr_t left_index = pconstraint->_left_inst; |
duke@435 | 1172 | const char *left_op = pconstraint->_left_op; |
duke@435 | 1173 | // Access info on the instructions whose operands are compared |
duke@435 | 1174 | InstructForm *inst_left = globals[pmatch->instruction_name(left_index)]->is_instruction(); |
duke@435 | 1175 | assert( inst_left, "Parser should guaranty this is an instruction"); |
duke@435 | 1176 | int left_op_base = inst_left->oper_input_base(globals); |
duke@435 | 1177 | // Access info on the operands being compared |
duke@435 | 1178 | int left_op_index = inst_left->operand_position(left_op, Component::USE); |
duke@435 | 1179 | if( left_op_index == -1 ) { |
duke@435 | 1180 | left_op_index = inst_left->operand_position(left_op, Component::DEF); |
duke@435 | 1181 | if( left_op_index == -1 ) { |
duke@435 | 1182 | left_op_index = inst_left->operand_position(left_op, Component::USE_DEF); |
duke@435 | 1183 | } |
duke@435 | 1184 | } |
duke@435 | 1185 | assert( left_op_index != NameList::Not_in_list, "Did not find operand in instruction"); |
duke@435 | 1186 | ComponentList components_left = inst_left->_components; |
duke@435 | 1187 | const char *left_comp_type = components_left.at(left_op_index)->_type; |
duke@435 | 1188 | OpClassForm *left_opclass = globals[left_comp_type]->is_opclass(); |
duke@435 | 1189 | Form::InterfaceType left_interface_type = left_opclass->interface_type(globals); |
duke@435 | 1190 | |
duke@435 | 1191 | |
duke@435 | 1192 | // RIGHT |
duke@435 | 1193 | int right_op_index = -1; |
duke@435 | 1194 | intptr_t right_index = pconstraint->_right_inst; |
duke@435 | 1195 | const char *right_op = pconstraint->_right_op; |
duke@435 | 1196 | if( right_index != -1 ) { // Match operand |
duke@435 | 1197 | // Access info on the instructions whose operands are compared |
duke@435 | 1198 | InstructForm *inst_right = globals[pmatch->instruction_name(right_index)]->is_instruction(); |
duke@435 | 1199 | assert( inst_right, "Parser should guaranty this is an instruction"); |
duke@435 | 1200 | int right_op_base = inst_right->oper_input_base(globals); |
duke@435 | 1201 | // Access info on the operands being compared |
duke@435 | 1202 | right_op_index = inst_right->operand_position(right_op, Component::USE); |
duke@435 | 1203 | if( right_op_index == -1 ) { |
duke@435 | 1204 | right_op_index = inst_right->operand_position(right_op, Component::DEF); |
duke@435 | 1205 | if( right_op_index == -1 ) { |
duke@435 | 1206 | right_op_index = inst_right->operand_position(right_op, Component::USE_DEF); |
duke@435 | 1207 | } |
duke@435 | 1208 | } |
duke@435 | 1209 | assert( right_op_index != NameList::Not_in_list, "Did not find operand in instruction"); |
duke@435 | 1210 | ComponentList components_right = inst_right->_components; |
duke@435 | 1211 | const char *right_comp_type = components_right.at(right_op_index)->_type; |
duke@435 | 1212 | OpClassForm *right_opclass = globals[right_comp_type]->is_opclass(); |
duke@435 | 1213 | Form::InterfaceType right_interface_type = right_opclass->interface_type(globals); |
duke@435 | 1214 | assert( right_interface_type == left_interface_type, "Both must be same interface"); |
duke@435 | 1215 | |
duke@435 | 1216 | } else { // Else match register |
duke@435 | 1217 | // assert( false, "should be a register" ); |
duke@435 | 1218 | } |
duke@435 | 1219 | |
duke@435 | 1220 | // |
duke@435 | 1221 | // Check for equivalence |
duke@435 | 1222 | // |
duke@435 | 1223 | // fprintf(fp, "phase->eqv( "); |
duke@435 | 1224 | // fprintf(fp, "inst%d->in(%d+%d) /* %s */, inst%d->in(%d+%d) /* %s */", |
duke@435 | 1225 | // left_index, left_op_base, left_op_index, left_op, |
duke@435 | 1226 | // right_index, right_op_base, right_op_index, right_op ); |
duke@435 | 1227 | // fprintf(fp, ")"); |
duke@435 | 1228 | // |
duke@435 | 1229 | switch( left_interface_type ) { |
duke@435 | 1230 | case Form::register_interface: { |
duke@435 | 1231 | // Check that they are allocated to the same register |
duke@435 | 1232 | // Need parameter for index position if not result operand |
duke@435 | 1233 | char left_reg_index[] = ",instXXXX_idxXXXX"; |
duke@435 | 1234 | if( left_op_index != 0 ) { |
duke@435 | 1235 | assert( (left_index <= 9999) && (left_op_index <= 9999), "exceed string size"); |
duke@435 | 1236 | // Must have index into operands |
duke@435 | 1237 | sprintf(left_reg_index,",inst%d_idx%d", left_index, left_op_index); |
duke@435 | 1238 | } else { |
duke@435 | 1239 | strcpy(left_reg_index, ""); |
duke@435 | 1240 | } |
duke@435 | 1241 | fprintf(fp, "(inst%d->_opnds[%d]->reg(ra_,inst%d%s) /* %d.%s */", |
duke@435 | 1242 | left_index, left_op_index, left_index, left_reg_index, left_index, left_op ); |
duke@435 | 1243 | fprintf(fp, " == "); |
duke@435 | 1244 | |
duke@435 | 1245 | if( right_index != -1 ) { |
duke@435 | 1246 | char right_reg_index[18] = ",instXXXX_idxXXXX"; |
duke@435 | 1247 | if( right_op_index != 0 ) { |
duke@435 | 1248 | assert( (right_index <= 9999) && (right_op_index <= 9999), "exceed string size"); |
duke@435 | 1249 | // Must have index into operands |
duke@435 | 1250 | sprintf(right_reg_index,",inst%d_idx%d", right_index, right_op_index); |
duke@435 | 1251 | } else { |
duke@435 | 1252 | strcpy(right_reg_index, ""); |
duke@435 | 1253 | } |
duke@435 | 1254 | fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->reg(ra_,inst%d%s)", |
duke@435 | 1255 | right_index, right_op, right_index, right_op_index, right_index, right_reg_index ); |
duke@435 | 1256 | } else { |
duke@435 | 1257 | fprintf(fp, "%s_enc", right_op ); |
duke@435 | 1258 | } |
duke@435 | 1259 | fprintf(fp,")"); |
duke@435 | 1260 | break; |
duke@435 | 1261 | } |
duke@435 | 1262 | case Form::constant_interface: { |
duke@435 | 1263 | // Compare the '->constant()' values |
duke@435 | 1264 | fprintf(fp, "(inst%d->_opnds[%d]->constant() /* %d.%s */", |
duke@435 | 1265 | left_index, left_op_index, left_index, left_op ); |
duke@435 | 1266 | fprintf(fp, " == "); |
duke@435 | 1267 | fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->constant())", |
duke@435 | 1268 | right_index, right_op, right_index, right_op_index ); |
duke@435 | 1269 | break; |
duke@435 | 1270 | } |
duke@435 | 1271 | case Form::memory_interface: { |
duke@435 | 1272 | // Compare 'base', 'index', 'scale', and 'disp' |
duke@435 | 1273 | // base |
duke@435 | 1274 | fprintf(fp, "( \n"); |
duke@435 | 1275 | fprintf(fp, " (inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d) /* %d.%s$$base */", |
duke@435 | 1276 | left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op ); |
duke@435 | 1277 | fprintf(fp, " == "); |
duke@435 | 1278 | fprintf(fp, "/* %d.%s$$base */ inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d)) &&\n", |
duke@435 | 1279 | right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index ); |
duke@435 | 1280 | // index |
duke@435 | 1281 | fprintf(fp, " (inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d) /* %d.%s$$index */", |
duke@435 | 1282 | left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op ); |
duke@435 | 1283 | fprintf(fp, " == "); |
duke@435 | 1284 | fprintf(fp, "/* %d.%s$$index */ inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d)) &&\n", |
duke@435 | 1285 | right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index ); |
duke@435 | 1286 | // scale |
duke@435 | 1287 | fprintf(fp, " (inst%d->_opnds[%d]->scale() /* %d.%s$$scale */", |
duke@435 | 1288 | left_index, left_op_index, left_index, left_op ); |
duke@435 | 1289 | fprintf(fp, " == "); |
duke@435 | 1290 | fprintf(fp, "/* %d.%s$$scale */ inst%d->_opnds[%d]->scale()) &&\n", |
duke@435 | 1291 | right_index, right_op, right_index, right_op_index ); |
duke@435 | 1292 | // disp |
duke@435 | 1293 | fprintf(fp, " (inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d) /* %d.%s$$disp */", |
duke@435 | 1294 | left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op ); |
duke@435 | 1295 | fprintf(fp, " == "); |
duke@435 | 1296 | fprintf(fp, "/* %d.%s$$disp */ inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d))\n", |
duke@435 | 1297 | right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index ); |
duke@435 | 1298 | fprintf(fp, ") \n"); |
duke@435 | 1299 | break; |
duke@435 | 1300 | } |
duke@435 | 1301 | case Form::conditional_interface: { |
duke@435 | 1302 | // Compare the condition code being tested |
duke@435 | 1303 | assert( false, "Unimplemented()" ); |
duke@435 | 1304 | break; |
duke@435 | 1305 | } |
duke@435 | 1306 | default: { |
duke@435 | 1307 | assert( false, "ShouldNotReachHere()" ); |
duke@435 | 1308 | break; |
duke@435 | 1309 | } |
duke@435 | 1310 | } |
duke@435 | 1311 | |
duke@435 | 1312 | // Advance to next constraint |
duke@435 | 1313 | pconstraint = pconstraint->next(); |
duke@435 | 1314 | first_constraint = false; |
duke@435 | 1315 | } |
duke@435 | 1316 | |
duke@435 | 1317 | fprintf(fp, ";\n"); |
duke@435 | 1318 | } |
duke@435 | 1319 | } |
duke@435 | 1320 | |
duke@435 | 1321 | // // EXPERIMENTAL -- TEMPORARY code |
duke@435 | 1322 | // static Form::DataType get_operand_type(FormDict &globals, InstructForm *instr, const char *op_name ) { |
duke@435 | 1323 | // int op_index = instr->operand_position(op_name, Component::USE); |
duke@435 | 1324 | // if( op_index == -1 ) { |
duke@435 | 1325 | // op_index = instr->operand_position(op_name, Component::DEF); |
duke@435 | 1326 | // if( op_index == -1 ) { |
duke@435 | 1327 | // op_index = instr->operand_position(op_name, Component::USE_DEF); |
duke@435 | 1328 | // } |
duke@435 | 1329 | // } |
duke@435 | 1330 | // assert( op_index != NameList::Not_in_list, "Did not find operand in instruction"); |
duke@435 | 1331 | // |
duke@435 | 1332 | // ComponentList components_right = instr->_components; |
duke@435 | 1333 | // char *right_comp_type = components_right.at(op_index)->_type; |
duke@435 | 1334 | // OpClassForm *right_opclass = globals[right_comp_type]->is_opclass(); |
duke@435 | 1335 | // Form::InterfaceType right_interface_type = right_opclass->interface_type(globals); |
duke@435 | 1336 | // |
duke@435 | 1337 | // return; |
duke@435 | 1338 | // } |
duke@435 | 1339 | |
duke@435 | 1340 | // Construct the new sub-tree |
duke@435 | 1341 | static void generate_peepreplace( FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint, PeepReplace *preplace, int max_position ) { |
duke@435 | 1342 | fprintf(fp, " // IF instructions and constraints matched\n"); |
duke@435 | 1343 | fprintf(fp, " if( matches ) {\n"); |
duke@435 | 1344 | fprintf(fp, " // generate the new sub-tree\n"); |
duke@435 | 1345 | fprintf(fp, " assert( true, \"Debug stopping point\");\n"); |
duke@435 | 1346 | if( preplace != NULL ) { |
duke@435 | 1347 | // Get the root of the new sub-tree |
duke@435 | 1348 | const char *root_inst = NULL; |
duke@435 | 1349 | preplace->next_instruction(root_inst); |
duke@435 | 1350 | InstructForm *root_form = globals[root_inst]->is_instruction(); |
duke@435 | 1351 | assert( root_form != NULL, "Replacement instruction was not previously defined"); |
duke@435 | 1352 | fprintf(fp, " %sNode *root = new (C) %sNode();\n", root_inst, root_inst); |
duke@435 | 1353 | |
duke@435 | 1354 | intptr_t inst_num; |
duke@435 | 1355 | const char *op_name; |
duke@435 | 1356 | int opnds_index = 0; // define result operand |
duke@435 | 1357 | // Then install the use-operands for the new sub-tree |
duke@435 | 1358 | // preplace->reset(); // reset breaks iteration |
duke@435 | 1359 | for( preplace->next_operand( inst_num, op_name ); |
duke@435 | 1360 | op_name != NULL; |
duke@435 | 1361 | preplace->next_operand( inst_num, op_name ) ) { |
duke@435 | 1362 | InstructForm *inst_form; |
duke@435 | 1363 | inst_form = globals[pmatch->instruction_name(inst_num)]->is_instruction(); |
duke@435 | 1364 | assert( inst_form, "Parser should guaranty this is an instruction"); |
duke@435 | 1365 | int op_base = inst_form->oper_input_base(globals); |
duke@435 | 1366 | int inst_op_num = inst_form->operand_position(op_name, Component::USE); |
duke@435 | 1367 | if( inst_op_num == NameList::Not_in_list ) |
duke@435 | 1368 | inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF); |
duke@435 | 1369 | assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE"); |
duke@435 | 1370 | // find the name of the OperandForm from the local name |
duke@435 | 1371 | const Form *form = inst_form->_localNames[op_name]; |
duke@435 | 1372 | OperandForm *op_form = form->is_operand(); |
duke@435 | 1373 | if( opnds_index == 0 ) { |
duke@435 | 1374 | // Initial setup of new instruction |
duke@435 | 1375 | fprintf(fp, " // ----- Initial setup -----\n"); |
duke@435 | 1376 | // |
duke@435 | 1377 | // Add control edge for this node |
duke@435 | 1378 | fprintf(fp, " root->add_req(_in[0]); // control edge\n"); |
duke@435 | 1379 | // Add unmatched edges from root of match tree |
duke@435 | 1380 | int op_base = root_form->oper_input_base(globals); |
duke@435 | 1381 | for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) { |
duke@435 | 1382 | fprintf(fp, " root->add_req(inst%ld->in(%d)); // unmatched ideal edge\n", |
duke@435 | 1383 | inst_num, unmatched_edge); |
duke@435 | 1384 | } |
duke@435 | 1385 | // If new instruction captures bottom type |
duke@435 | 1386 | if( root_form->captures_bottom_type() ) { |
duke@435 | 1387 | // Get bottom type from instruction whose result we are replacing |
duke@435 | 1388 | fprintf(fp, " root->_bottom_type = inst%ld->bottom_type();\n", inst_num); |
duke@435 | 1389 | } |
duke@435 | 1390 | // Define result register and result operand |
duke@435 | 1391 | fprintf(fp, " ra_->add_reference(root, inst%ld);\n", inst_num); |
duke@435 | 1392 | fprintf(fp, " ra_->set_oop (root, ra_->is_oop(inst%ld));\n", inst_num); |
duke@435 | 1393 | fprintf(fp, " ra_->set_pair(root->_idx, ra_->get_reg_second(inst%ld), ra_->get_reg_first(inst%ld));\n", inst_num, inst_num); |
duke@435 | 1394 | fprintf(fp, " root->_opnds[0] = inst%ld->_opnds[0]->clone(C); // result\n", inst_num); |
duke@435 | 1395 | fprintf(fp, " // ----- Done with initial setup -----\n"); |
duke@435 | 1396 | } else { |
duke@435 | 1397 | if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) { |
duke@435 | 1398 | // Do not have ideal edges for constants after matching |
duke@435 | 1399 | fprintf(fp, " for( unsigned x%d = inst%ld_idx%d; x%d < inst%ld_idx%d; x%d++ )\n", |
duke@435 | 1400 | inst_op_num, inst_num, inst_op_num, |
duke@435 | 1401 | inst_op_num, inst_num, inst_op_num+1, inst_op_num ); |
duke@435 | 1402 | fprintf(fp, " root->add_req( inst%ld->in(x%d) );\n", |
duke@435 | 1403 | inst_num, inst_op_num ); |
duke@435 | 1404 | } else { |
duke@435 | 1405 | fprintf(fp, " // no ideal edge for constants after matching\n"); |
duke@435 | 1406 | } |
duke@435 | 1407 | fprintf(fp, " root->_opnds[%d] = inst%ld->_opnds[%d]->clone(C);\n", |
duke@435 | 1408 | opnds_index, inst_num, inst_op_num ); |
duke@435 | 1409 | } |
duke@435 | 1410 | ++opnds_index; |
duke@435 | 1411 | } |
duke@435 | 1412 | }else { |
duke@435 | 1413 | // Replacing subtree with empty-tree |
duke@435 | 1414 | assert( false, "ShouldNotReachHere();"); |
duke@435 | 1415 | } |
duke@435 | 1416 | |
duke@435 | 1417 | // Return the new sub-tree |
duke@435 | 1418 | fprintf(fp, " deleted = %d;\n", max_position+1 /*zero to one based*/); |
duke@435 | 1419 | fprintf(fp, " return root; // return new root;\n"); |
duke@435 | 1420 | fprintf(fp, " }\n"); |
duke@435 | 1421 | } |
duke@435 | 1422 | |
duke@435 | 1423 | |
duke@435 | 1424 | // Define the Peephole method for an instruction node |
duke@435 | 1425 | void ArchDesc::definePeephole(FILE *fp, InstructForm *node) { |
duke@435 | 1426 | // Generate Peephole function header |
duke@435 | 1427 | fprintf(fp, "MachNode *%sNode::peephole( Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile* C ) {\n", node->_ident); |
duke@435 | 1428 | fprintf(fp, " bool matches = true;\n"); |
duke@435 | 1429 | |
duke@435 | 1430 | // Identify the maximum instruction position, |
duke@435 | 1431 | // generate temporaries that hold current instruction |
duke@435 | 1432 | // |
duke@435 | 1433 | // MachNode *inst0 = NULL; |
duke@435 | 1434 | // ... |
duke@435 | 1435 | // MachNode *instMAX = NULL; |
duke@435 | 1436 | // |
duke@435 | 1437 | int max_position = 0; |
duke@435 | 1438 | Peephole *peep; |
duke@435 | 1439 | for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) { |
duke@435 | 1440 | PeepMatch *pmatch = peep->match(); |
duke@435 | 1441 | assert( pmatch != NULL, "fatal(), missing peepmatch rule"); |
duke@435 | 1442 | if( max_position < pmatch->max_position() ) max_position = pmatch->max_position(); |
duke@435 | 1443 | } |
duke@435 | 1444 | for( int i = 0; i <= max_position; ++i ) { |
duke@435 | 1445 | if( i == 0 ) { |
duke@435 | 1446 | fprintf(fp, " MachNode *inst0 = this;\n", i); |
duke@435 | 1447 | } else { |
duke@435 | 1448 | fprintf(fp, " MachNode *inst%d = NULL;\n", i); |
duke@435 | 1449 | } |
duke@435 | 1450 | } |
duke@435 | 1451 | |
duke@435 | 1452 | // For each peephole rule in architecture description |
duke@435 | 1453 | // Construct a test for the desired instruction sub-tree |
duke@435 | 1454 | // then check the constraints |
duke@435 | 1455 | // If these match, Generate the new subtree |
duke@435 | 1456 | for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) { |
duke@435 | 1457 | int peephole_number = peep->peephole_number(); |
duke@435 | 1458 | PeepMatch *pmatch = peep->match(); |
duke@435 | 1459 | PeepConstraint *pconstraint = peep->constraints(); |
duke@435 | 1460 | PeepReplace *preplace = peep->replacement(); |
duke@435 | 1461 | |
duke@435 | 1462 | // Root of this peephole is the current MachNode |
duke@435 | 1463 | assert( true, // %%name?%% strcmp( node->_ident, pmatch->name(0) ) == 0, |
duke@435 | 1464 | "root of PeepMatch does not match instruction"); |
duke@435 | 1465 | |
duke@435 | 1466 | // Make each peephole rule individually selectable |
duke@435 | 1467 | fprintf(fp, " if( (OptoPeepholeAt == -1) || (OptoPeepholeAt==%d) ) {\n", peephole_number); |
duke@435 | 1468 | fprintf(fp, " matches = true;\n"); |
duke@435 | 1469 | // Scan the peepmatch and output a test for each instruction |
duke@435 | 1470 | check_peepmatch_instruction_sequence( fp, pmatch, pconstraint ); |
duke@435 | 1471 | |
duke@435 | 1472 | // Check constraints and build replacement inside scope |
duke@435 | 1473 | fprintf(fp, " // If instruction subtree matches\n"); |
duke@435 | 1474 | fprintf(fp, " if( matches ) {\n"); |
duke@435 | 1475 | |
duke@435 | 1476 | // Generate tests for the constraints |
duke@435 | 1477 | check_peepconstraints( fp, _globalNames, pmatch, pconstraint ); |
duke@435 | 1478 | |
duke@435 | 1479 | // Construct the new sub-tree |
duke@435 | 1480 | generate_peepreplace( fp, _globalNames, pmatch, pconstraint, preplace, max_position ); |
duke@435 | 1481 | |
duke@435 | 1482 | // End of scope for this peephole's constraints |
duke@435 | 1483 | fprintf(fp, " }\n"); |
duke@435 | 1484 | // Closing brace '}' to make each peephole rule individually selectable |
duke@435 | 1485 | fprintf(fp, " } // end of peephole rule #%d\n", peephole_number); |
duke@435 | 1486 | fprintf(fp, "\n"); |
duke@435 | 1487 | } |
duke@435 | 1488 | |
duke@435 | 1489 | fprintf(fp, " return NULL; // No peephole rules matched\n"); |
duke@435 | 1490 | fprintf(fp, "}\n"); |
duke@435 | 1491 | fprintf(fp, "\n"); |
duke@435 | 1492 | } |
duke@435 | 1493 | |
duke@435 | 1494 | // Define the Expand method for an instruction node |
duke@435 | 1495 | void ArchDesc::defineExpand(FILE *fp, InstructForm *node) { |
duke@435 | 1496 | unsigned cnt = 0; // Count nodes we have expand into |
duke@435 | 1497 | unsigned i; |
duke@435 | 1498 | |
duke@435 | 1499 | // Generate Expand function header |
duke@435 | 1500 | fprintf(fp,"MachNode *%sNode::Expand(State *state, Node_List &proj_list) {\n", node->_ident); |
duke@435 | 1501 | fprintf(fp,"Compile* C = Compile::current();\n"); |
duke@435 | 1502 | // Generate expand code |
duke@435 | 1503 | if( node->expands() ) { |
duke@435 | 1504 | const char *opid; |
duke@435 | 1505 | int new_pos, exp_pos; |
duke@435 | 1506 | const char *new_id = NULL; |
duke@435 | 1507 | const Form *frm = NULL; |
duke@435 | 1508 | InstructForm *new_inst = NULL; |
duke@435 | 1509 | OperandForm *new_oper = NULL; |
duke@435 | 1510 | unsigned numo = node->num_opnds() + |
duke@435 | 1511 | node->_exprule->_newopers.count(); |
duke@435 | 1512 | |
duke@435 | 1513 | // If necessary, generate any operands created in expand rule |
duke@435 | 1514 | if (node->_exprule->_newopers.count()) { |
duke@435 | 1515 | for(node->_exprule->_newopers.reset(); |
duke@435 | 1516 | (new_id = node->_exprule->_newopers.iter()) != NULL; cnt++) { |
duke@435 | 1517 | frm = node->_localNames[new_id]; |
duke@435 | 1518 | assert(frm, "Invalid entry in new operands list of expand rule"); |
duke@435 | 1519 | new_oper = frm->is_operand(); |
duke@435 | 1520 | char *tmp = (char *)node->_exprule->_newopconst[new_id]; |
duke@435 | 1521 | if (tmp == NULL) { |
duke@435 | 1522 | fprintf(fp," MachOper *op%d = new (C) %sOper();\n", |
duke@435 | 1523 | cnt, new_oper->_ident); |
duke@435 | 1524 | } |
duke@435 | 1525 | else { |
duke@435 | 1526 | fprintf(fp," MachOper *op%d = new (C) %sOper(%s);\n", |
duke@435 | 1527 | cnt, new_oper->_ident, tmp); |
duke@435 | 1528 | } |
duke@435 | 1529 | } |
duke@435 | 1530 | } |
duke@435 | 1531 | cnt = 0; |
duke@435 | 1532 | // Generate the temps to use for DAG building |
duke@435 | 1533 | for(i = 0; i < numo; i++) { |
duke@435 | 1534 | if (i < node->num_opnds()) { |
duke@435 | 1535 | fprintf(fp," MachNode *tmp%d = this;\n", i); |
duke@435 | 1536 | } |
duke@435 | 1537 | else { |
duke@435 | 1538 | fprintf(fp," MachNode *tmp%d = NULL;\n", i); |
duke@435 | 1539 | } |
duke@435 | 1540 | } |
duke@435 | 1541 | // Build mapping from num_edges to local variables |
duke@435 | 1542 | fprintf(fp," unsigned num0 = 0;\n"); |
duke@435 | 1543 | for( i = 1; i < node->num_opnds(); i++ ) { |
duke@435 | 1544 | fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();\n",i,i); |
duke@435 | 1545 | } |
duke@435 | 1546 | |
duke@435 | 1547 | // Build a mapping from operand index to input edges |
duke@435 | 1548 | fprintf(fp," unsigned idx0 = oper_input_base();\n"); |
coleenp@548 | 1549 | |
coleenp@548 | 1550 | // The order in which inputs are added to a node is very |
coleenp@548 | 1551 | // strange. Store nodes get a memory input before Expand is |
coleenp@548 | 1552 | // called and all other nodes get it afterwards so |
coleenp@548 | 1553 | // oper_input_base is wrong during expansion. This code adjusts |
coleenp@548 | 1554 | // is so that expansion will work correctly. |
coleenp@548 | 1555 | bool missing_memory_edge = node->_matrule->needs_ideal_memory_edge(_globalNames) && |
coleenp@548 | 1556 | node->is_ideal_store() == Form::none; |
coleenp@548 | 1557 | if (missing_memory_edge) { |
coleenp@548 | 1558 | fprintf(fp," idx0--; // Adjust base because memory edge hasn't been inserted yet\n"); |
coleenp@548 | 1559 | } |
coleenp@548 | 1560 | |
duke@435 | 1561 | for( i = 0; i < node->num_opnds(); i++ ) { |
duke@435 | 1562 | fprintf(fp," unsigned idx%d = idx%d + num%d;\n", |
duke@435 | 1563 | i+1,i,i); |
duke@435 | 1564 | } |
duke@435 | 1565 | |
duke@435 | 1566 | // Declare variable to hold root of expansion |
duke@435 | 1567 | fprintf(fp," MachNode *result = NULL;\n"); |
duke@435 | 1568 | |
duke@435 | 1569 | // Iterate over the instructions 'node' expands into |
duke@435 | 1570 | ExpandRule *expand = node->_exprule; |
duke@435 | 1571 | NameAndList *expand_instr = NULL; |
duke@435 | 1572 | for(expand->reset_instructions(); |
duke@435 | 1573 | (expand_instr = expand->iter_instructions()) != NULL; cnt++) { |
duke@435 | 1574 | new_id = expand_instr->name(); |
duke@435 | 1575 | |
duke@435 | 1576 | InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id]; |
duke@435 | 1577 | if (expand_instruction->has_temps()) { |
duke@435 | 1578 | globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s", |
duke@435 | 1579 | node->_ident, new_id); |
duke@435 | 1580 | } |
duke@435 | 1581 | |
duke@435 | 1582 | // Build the node for the instruction |
duke@435 | 1583 | fprintf(fp,"\n %sNode *n%d = new (C) %sNode();\n", new_id, cnt, new_id); |
duke@435 | 1584 | // Add control edge for this node |
duke@435 | 1585 | fprintf(fp," n%d->add_req(_in[0]);\n", cnt); |
duke@435 | 1586 | // Build the operand for the value this node defines. |
duke@435 | 1587 | Form *form = (Form*)_globalNames[new_id]; |
duke@435 | 1588 | assert( form, "'new_id' must be a defined form name"); |
duke@435 | 1589 | // Grab the InstructForm for the new instruction |
duke@435 | 1590 | new_inst = form->is_instruction(); |
duke@435 | 1591 | assert( new_inst, "'new_id' must be an instruction name"); |
duke@435 | 1592 | if( node->is_ideal_if() && new_inst->is_ideal_if() ) { |
duke@435 | 1593 | fprintf(fp, " ((MachIfNode*)n%d)->_prob = _prob;\n",cnt); |
duke@435 | 1594 | fprintf(fp, " ((MachIfNode*)n%d)->_fcnt = _fcnt;\n",cnt); |
duke@435 | 1595 | } |
duke@435 | 1596 | |
duke@435 | 1597 | if( node->is_ideal_fastlock() && new_inst->is_ideal_fastlock() ) { |
duke@435 | 1598 | fprintf(fp, " ((MachFastLockNode*)n%d)->_counters = _counters;\n",cnt); |
duke@435 | 1599 | } |
duke@435 | 1600 | |
duke@435 | 1601 | const char *resultOper = new_inst->reduce_result(); |
duke@435 | 1602 | fprintf(fp," n%d->set_opnd_array(0, state->MachOperGenerator( %s, C ));\n", |
duke@435 | 1603 | cnt, machOperEnum(resultOper)); |
duke@435 | 1604 | |
duke@435 | 1605 | // get the formal operand NameList |
duke@435 | 1606 | NameList *formal_lst = &new_inst->_parameters; |
duke@435 | 1607 | formal_lst->reset(); |
duke@435 | 1608 | |
duke@435 | 1609 | // Handle any memory operand |
duke@435 | 1610 | int memory_operand = new_inst->memory_operand(_globalNames); |
duke@435 | 1611 | if( memory_operand != InstructForm::NO_MEMORY_OPERAND ) { |
duke@435 | 1612 | int node_mem_op = node->memory_operand(_globalNames); |
duke@435 | 1613 | assert( node_mem_op != InstructForm::NO_MEMORY_OPERAND, |
duke@435 | 1614 | "expand rule member needs memory but top-level inst doesn't have any" ); |
coleenp@548 | 1615 | if (!missing_memory_edge) { |
coleenp@548 | 1616 | // Copy memory edge |
coleenp@548 | 1617 | fprintf(fp," n%d->add_req(_in[1]);\t// Add memory edge\n", cnt); |
coleenp@548 | 1618 | } |
duke@435 | 1619 | } |
duke@435 | 1620 | |
duke@435 | 1621 | // Iterate over the new instruction's operands |
never@850 | 1622 | int prev_pos = -1; |
duke@435 | 1623 | for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) { |
duke@435 | 1624 | // Use 'parameter' at current position in list of new instruction's formals |
duke@435 | 1625 | // instead of 'opid' when looking up info internal to new_inst |
duke@435 | 1626 | const char *parameter = formal_lst->iter(); |
duke@435 | 1627 | // Check for an operand which is created in the expand rule |
duke@435 | 1628 | if ((exp_pos = node->_exprule->_newopers.index(opid)) != -1) { |
duke@435 | 1629 | new_pos = new_inst->operand_position(parameter,Component::USE); |
duke@435 | 1630 | exp_pos += node->num_opnds(); |
duke@435 | 1631 | // If there is no use of the created operand, just skip it |
duke@435 | 1632 | if (new_pos != -1) { |
duke@435 | 1633 | //Copy the operand from the original made above |
duke@435 | 1634 | fprintf(fp," n%d->set_opnd_array(%d, op%d->clone(C)); // %s\n", |
duke@435 | 1635 | cnt, new_pos, exp_pos-node->num_opnds(), opid); |
duke@435 | 1636 | // Check for who defines this operand & add edge if needed |
duke@435 | 1637 | fprintf(fp," if(tmp%d != NULL)\n", exp_pos); |
duke@435 | 1638 | fprintf(fp," n%d->add_req(tmp%d);\n", cnt, exp_pos); |
duke@435 | 1639 | } |
duke@435 | 1640 | } |
duke@435 | 1641 | else { |
duke@435 | 1642 | // Use operand name to get an index into instruction component list |
duke@435 | 1643 | // ins = (InstructForm *) _globalNames[new_id]; |
duke@435 | 1644 | exp_pos = node->operand_position_format(opid); |
duke@435 | 1645 | assert(exp_pos != -1, "Bad expand rule"); |
never@850 | 1646 | if (prev_pos > exp_pos && expand_instruction->_matrule != NULL) { |
never@850 | 1647 | // For the add_req calls below to work correctly they need |
never@850 | 1648 | // to added in the same order that a match would add them. |
never@850 | 1649 | // This means that they would need to be in the order of |
never@850 | 1650 | // the components list instead of the formal parameters. |
never@850 | 1651 | // This is a sort of hidden invariant that previously |
never@850 | 1652 | // wasn't checked and could lead to incorrectly |
never@850 | 1653 | // constructed nodes. |
never@850 | 1654 | syntax_err(node->_linenum, "For expand in %s to work, parameter declaration order in %s must follow matchrule\n", |
never@850 | 1655 | node->_ident, new_inst->_ident); |
never@850 | 1656 | } |
never@850 | 1657 | prev_pos = exp_pos; |
duke@435 | 1658 | |
duke@435 | 1659 | new_pos = new_inst->operand_position(parameter,Component::USE); |
duke@435 | 1660 | if (new_pos != -1) { |
duke@435 | 1661 | // Copy the operand from the ExpandNode to the new node |
duke@435 | 1662 | fprintf(fp," n%d->set_opnd_array(%d, opnd_array(%d)->clone(C)); // %s\n", |
duke@435 | 1663 | cnt, new_pos, exp_pos, opid); |
duke@435 | 1664 | // For each operand add appropriate input edges by looking at tmp's |
duke@435 | 1665 | fprintf(fp," if(tmp%d == this) {\n", exp_pos); |
duke@435 | 1666 | // Grab corresponding edges from ExpandNode and insert them here |
duke@435 | 1667 | fprintf(fp," for(unsigned i = 0; i < num%d; i++) {\n", exp_pos); |
duke@435 | 1668 | fprintf(fp," n%d->add_req(_in[i + idx%d]);\n", cnt, exp_pos); |
duke@435 | 1669 | fprintf(fp," }\n"); |
duke@435 | 1670 | fprintf(fp," }\n"); |
duke@435 | 1671 | // This value is generated by one of the new instructions |
duke@435 | 1672 | fprintf(fp," else n%d->add_req(tmp%d);\n", cnt, exp_pos); |
duke@435 | 1673 | } |
duke@435 | 1674 | } |
duke@435 | 1675 | |
duke@435 | 1676 | // Update the DAG tmp's for values defined by this instruction |
duke@435 | 1677 | int new_def_pos = new_inst->operand_position(parameter,Component::DEF); |
duke@435 | 1678 | Effect *eform = (Effect *)new_inst->_effects[parameter]; |
duke@435 | 1679 | // If this operand is a definition in either an effects rule |
duke@435 | 1680 | // or a match rule |
duke@435 | 1681 | if((eform) && (is_def(eform->_use_def))) { |
duke@435 | 1682 | // Update the temp associated with this operand |
duke@435 | 1683 | fprintf(fp," tmp%d = n%d;\n", exp_pos, cnt); |
duke@435 | 1684 | } |
duke@435 | 1685 | else if( new_def_pos != -1 ) { |
duke@435 | 1686 | // Instruction defines a value but user did not declare it |
duke@435 | 1687 | // in the 'effect' clause |
duke@435 | 1688 | fprintf(fp," tmp%d = n%d;\n", exp_pos, cnt); |
duke@435 | 1689 | } |
duke@435 | 1690 | } // done iterating over a new instruction's operands |
duke@435 | 1691 | |
duke@435 | 1692 | // Invoke Expand() for the newly created instruction. |
duke@435 | 1693 | fprintf(fp," result = n%d->Expand( state, proj_list );\n", cnt); |
duke@435 | 1694 | assert( !new_inst->expands(), "Do not have complete support for recursive expansion"); |
duke@435 | 1695 | } // done iterating over new instructions |
duke@435 | 1696 | fprintf(fp,"\n"); |
duke@435 | 1697 | } // done generating expand rule |
duke@435 | 1698 | |
duke@435 | 1699 | else if( node->_matrule != NULL ) { |
duke@435 | 1700 | // Remove duplicated operands and inputs which use the same name. |
duke@435 | 1701 | // Seach through match operands for the same name usage. |
duke@435 | 1702 | uint cur_num_opnds = node->num_opnds(); |
duke@435 | 1703 | if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) { |
duke@435 | 1704 | Component *comp = NULL; |
duke@435 | 1705 | // Build mapping from num_edges to local variables |
duke@435 | 1706 | fprintf(fp," unsigned num0 = 0;\n"); |
duke@435 | 1707 | for( i = 1; i < cur_num_opnds; i++ ) { |
duke@435 | 1708 | fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();\n",i,i); |
duke@435 | 1709 | } |
duke@435 | 1710 | // Build a mapping from operand index to input edges |
duke@435 | 1711 | fprintf(fp," unsigned idx0 = oper_input_base();\n"); |
duke@435 | 1712 | for( i = 0; i < cur_num_opnds; i++ ) { |
duke@435 | 1713 | fprintf(fp," unsigned idx%d = idx%d + num%d;\n", |
duke@435 | 1714 | i+1,i,i); |
duke@435 | 1715 | } |
duke@435 | 1716 | |
duke@435 | 1717 | uint new_num_opnds = 1; |
duke@435 | 1718 | node->_components.reset(); |
duke@435 | 1719 | // Skip first unique operands. |
duke@435 | 1720 | for( i = 1; i < cur_num_opnds; i++ ) { |
duke@435 | 1721 | comp = node->_components.iter(); |
duke@435 | 1722 | if( (int)i != node->unique_opnds_idx(i) ) { |
duke@435 | 1723 | break; |
duke@435 | 1724 | } |
duke@435 | 1725 | new_num_opnds++; |
duke@435 | 1726 | } |
duke@435 | 1727 | // Replace not unique operands with next unique operands. |
duke@435 | 1728 | for( ; i < cur_num_opnds; i++ ) { |
duke@435 | 1729 | comp = node->_components.iter(); |
duke@435 | 1730 | int j = node->unique_opnds_idx(i); |
duke@435 | 1731 | // unique_opnds_idx(i) is unique if unique_opnds_idx(j) is not unique. |
duke@435 | 1732 | if( j != node->unique_opnds_idx(j) ) { |
duke@435 | 1733 | fprintf(fp," set_opnd_array(%d, opnd_array(%d)->clone(C)); // %s\n", |
duke@435 | 1734 | new_num_opnds, i, comp->_name); |
duke@435 | 1735 | // delete not unique edges here |
duke@435 | 1736 | fprintf(fp," for(unsigned i = 0; i < num%d; i++) {\n", i); |
duke@435 | 1737 | fprintf(fp," set_req(i + idx%d, _in[i + idx%d]);\n", new_num_opnds, i); |
duke@435 | 1738 | fprintf(fp," }\n"); |
duke@435 | 1739 | fprintf(fp," num%d = num%d;\n", new_num_opnds, i); |
duke@435 | 1740 | fprintf(fp," idx%d = idx%d + num%d;\n", new_num_opnds+1, new_num_opnds, new_num_opnds); |
duke@435 | 1741 | new_num_opnds++; |
duke@435 | 1742 | } |
duke@435 | 1743 | } |
duke@435 | 1744 | // delete the rest of edges |
duke@435 | 1745 | fprintf(fp," for(int i = idx%d - 1; i >= (int)idx%d; i--) {\n", cur_num_opnds, new_num_opnds); |
duke@435 | 1746 | fprintf(fp," del_req(i);\n", i); |
duke@435 | 1747 | fprintf(fp," }\n"); |
duke@435 | 1748 | fprintf(fp," _num_opnds = %d;\n", new_num_opnds); |
duke@435 | 1749 | } |
duke@435 | 1750 | } |
duke@435 | 1751 | |
duke@435 | 1752 | |
duke@435 | 1753 | // Generate projections for instruction's additional DEFs and KILLs |
duke@435 | 1754 | if( ! node->expands() && (node->needs_projections() || node->has_temps())) { |
duke@435 | 1755 | // Get string representing the MachNode that projections point at |
duke@435 | 1756 | const char *machNode = "this"; |
duke@435 | 1757 | // Generate the projections |
duke@435 | 1758 | fprintf(fp," // Add projection edges for additional defs or kills\n"); |
duke@435 | 1759 | |
duke@435 | 1760 | // Examine each component to see if it is a DEF or KILL |
duke@435 | 1761 | node->_components.reset(); |
duke@435 | 1762 | // Skip the first component, if already handled as (SET dst (...)) |
duke@435 | 1763 | Component *comp = NULL; |
duke@435 | 1764 | // For kills, the choice of projection numbers is arbitrary |
duke@435 | 1765 | int proj_no = 1; |
duke@435 | 1766 | bool declared_def = false; |
duke@435 | 1767 | bool declared_kill = false; |
duke@435 | 1768 | |
duke@435 | 1769 | while( (comp = node->_components.iter()) != NULL ) { |
duke@435 | 1770 | // Lookup register class associated with operand type |
duke@435 | 1771 | Form *form = (Form*)_globalNames[comp->_type]; |
duke@435 | 1772 | assert( form, "component type must be a defined form"); |
duke@435 | 1773 | OperandForm *op = form->is_operand(); |
duke@435 | 1774 | |
duke@435 | 1775 | if (comp->is(Component::TEMP)) { |
duke@435 | 1776 | fprintf(fp, " // TEMP %s\n", comp->_name); |
duke@435 | 1777 | if (!declared_def) { |
duke@435 | 1778 | // Define the variable "def" to hold new MachProjNodes |
duke@435 | 1779 | fprintf(fp, " MachTempNode *def;\n"); |
duke@435 | 1780 | declared_def = true; |
duke@435 | 1781 | } |
duke@435 | 1782 | if (op && op->_interface && op->_interface->is_RegInterface()) { |
duke@435 | 1783 | fprintf(fp," def = new (C) MachTempNode(state->MachOperGenerator( %s, C ));\n", |
duke@435 | 1784 | machOperEnum(op->_ident)); |
duke@435 | 1785 | fprintf(fp," add_req(def);\n"); |
duke@435 | 1786 | int idx = node->operand_position_format(comp->_name); |
duke@435 | 1787 | fprintf(fp," set_opnd_array(%d, state->MachOperGenerator( %s, C ));\n", |
duke@435 | 1788 | idx, machOperEnum(op->_ident)); |
duke@435 | 1789 | } else { |
duke@435 | 1790 | assert(false, "can't have temps which aren't registers"); |
duke@435 | 1791 | } |
duke@435 | 1792 | } else if (comp->isa(Component::KILL)) { |
duke@435 | 1793 | fprintf(fp, " // DEF/KILL %s\n", comp->_name); |
duke@435 | 1794 | |
duke@435 | 1795 | if (!declared_kill) { |
duke@435 | 1796 | // Define the variable "kill" to hold new MachProjNodes |
duke@435 | 1797 | fprintf(fp, " MachProjNode *kill;\n"); |
duke@435 | 1798 | declared_kill = true; |
duke@435 | 1799 | } |
duke@435 | 1800 | |
duke@435 | 1801 | assert( op, "Support additional KILLS for base operands"); |
duke@435 | 1802 | const char *regmask = reg_mask(*op); |
duke@435 | 1803 | const char *ideal_type = op->ideal_type(_globalNames, _register); |
duke@435 | 1804 | |
duke@435 | 1805 | if (!op->is_bound_register()) { |
duke@435 | 1806 | syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n", |
duke@435 | 1807 | node->_ident, comp->_type, comp->_name); |
duke@435 | 1808 | } |
duke@435 | 1809 | |
duke@435 | 1810 | fprintf(fp," kill = "); |
duke@435 | 1811 | fprintf(fp,"new (C, 1) MachProjNode( %s, %d, (%s), Op_%s );\n", |
duke@435 | 1812 | machNode, proj_no++, regmask, ideal_type); |
duke@435 | 1813 | fprintf(fp," proj_list.push(kill);\n"); |
duke@435 | 1814 | } |
duke@435 | 1815 | } |
duke@435 | 1816 | } |
duke@435 | 1817 | |
duke@435 | 1818 | fprintf(fp,"\n"); |
duke@435 | 1819 | if( node->expands() ) { |
duke@435 | 1820 | fprintf(fp," return result;\n",cnt-1); |
duke@435 | 1821 | } else { |
duke@435 | 1822 | fprintf(fp," return this;\n"); |
duke@435 | 1823 | } |
duke@435 | 1824 | fprintf(fp,"}\n"); |
duke@435 | 1825 | fprintf(fp,"\n"); |
duke@435 | 1826 | } |
duke@435 | 1827 | |
duke@435 | 1828 | |
duke@435 | 1829 | //------------------------------Emit Routines---------------------------------- |
duke@435 | 1830 | // Special classes and routines for defining node emit routines which output |
duke@435 | 1831 | // target specific instruction object encodings. |
duke@435 | 1832 | // Define the ___Node::emit() routine |
duke@435 | 1833 | // |
duke@435 | 1834 | // (1) void ___Node::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { |
duke@435 | 1835 | // (2) // ... encoding defined by user |
duke@435 | 1836 | // (3) |
duke@435 | 1837 | // (4) } |
duke@435 | 1838 | // |
duke@435 | 1839 | |
duke@435 | 1840 | class DefineEmitState { |
duke@435 | 1841 | private: |
duke@435 | 1842 | enum reloc_format { RELOC_NONE = -1, |
duke@435 | 1843 | RELOC_IMMEDIATE = 0, |
duke@435 | 1844 | RELOC_DISP = 1, |
duke@435 | 1845 | RELOC_CALL_DISP = 2 }; |
duke@435 | 1846 | enum literal_status{ LITERAL_NOT_SEEN = 0, |
duke@435 | 1847 | LITERAL_SEEN = 1, |
duke@435 | 1848 | LITERAL_ACCESSED = 2, |
duke@435 | 1849 | LITERAL_OUTPUT = 3 }; |
duke@435 | 1850 | // Temporaries that describe current operand |
duke@435 | 1851 | bool _cleared; |
duke@435 | 1852 | OpClassForm *_opclass; |
duke@435 | 1853 | OperandForm *_operand; |
duke@435 | 1854 | int _operand_idx; |
duke@435 | 1855 | const char *_local_name; |
duke@435 | 1856 | const char *_operand_name; |
duke@435 | 1857 | bool _doing_disp; |
duke@435 | 1858 | bool _doing_constant; |
duke@435 | 1859 | Form::DataType _constant_type; |
duke@435 | 1860 | DefineEmitState::literal_status _constant_status; |
duke@435 | 1861 | DefineEmitState::literal_status _reg_status; |
duke@435 | 1862 | bool _doing_emit8; |
duke@435 | 1863 | bool _doing_emit_d32; |
duke@435 | 1864 | bool _doing_emit_d16; |
duke@435 | 1865 | bool _doing_emit_hi; |
duke@435 | 1866 | bool _doing_emit_lo; |
duke@435 | 1867 | bool _may_reloc; |
duke@435 | 1868 | bool _must_reloc; |
duke@435 | 1869 | reloc_format _reloc_form; |
duke@435 | 1870 | const char * _reloc_type; |
duke@435 | 1871 | bool _processing_noninput; |
duke@435 | 1872 | |
duke@435 | 1873 | NameList _strings_to_emit; |
duke@435 | 1874 | |
duke@435 | 1875 | // Stable state, set by constructor |
duke@435 | 1876 | ArchDesc &_AD; |
duke@435 | 1877 | FILE *_fp; |
duke@435 | 1878 | EncClass &_encoding; |
duke@435 | 1879 | InsEncode &_ins_encode; |
duke@435 | 1880 | InstructForm &_inst; |
duke@435 | 1881 | |
duke@435 | 1882 | public: |
duke@435 | 1883 | DefineEmitState(FILE *fp, ArchDesc &AD, EncClass &encoding, |
duke@435 | 1884 | InsEncode &ins_encode, InstructForm &inst) |
duke@435 | 1885 | : _AD(AD), _fp(fp), _encoding(encoding), _ins_encode(ins_encode), _inst(inst) { |
duke@435 | 1886 | clear(); |
duke@435 | 1887 | } |
duke@435 | 1888 | |
duke@435 | 1889 | void clear() { |
duke@435 | 1890 | _cleared = true; |
duke@435 | 1891 | _opclass = NULL; |
duke@435 | 1892 | _operand = NULL; |
duke@435 | 1893 | _operand_idx = 0; |
duke@435 | 1894 | _local_name = ""; |
duke@435 | 1895 | _operand_name = ""; |
duke@435 | 1896 | _doing_disp = false; |
duke@435 | 1897 | _doing_constant= false; |
duke@435 | 1898 | _constant_type = Form::none; |
duke@435 | 1899 | _constant_status = LITERAL_NOT_SEEN; |
duke@435 | 1900 | _reg_status = LITERAL_NOT_SEEN; |
duke@435 | 1901 | _doing_emit8 = false; |
duke@435 | 1902 | _doing_emit_d32= false; |
duke@435 | 1903 | _doing_emit_d16= false; |
duke@435 | 1904 | _doing_emit_hi = false; |
duke@435 | 1905 | _doing_emit_lo = false; |
duke@435 | 1906 | _may_reloc = false; |
duke@435 | 1907 | _must_reloc = false; |
duke@435 | 1908 | _reloc_form = RELOC_NONE; |
duke@435 | 1909 | _reloc_type = AdlcVMDeps::none_reloc_type(); |
duke@435 | 1910 | _strings_to_emit.clear(); |
duke@435 | 1911 | } |
duke@435 | 1912 | |
duke@435 | 1913 | // Track necessary state when identifying a replacement variable |
duke@435 | 1914 | void update_state(const char *rep_var) { |
duke@435 | 1915 | // A replacement variable or one of its subfields |
duke@435 | 1916 | // Obtain replacement variable from list |
duke@435 | 1917 | if ( (*rep_var) != '$' ) { |
duke@435 | 1918 | // A replacement variable, '$' prefix |
duke@435 | 1919 | // check_rep_var( rep_var ); |
duke@435 | 1920 | if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) { |
duke@435 | 1921 | // No state needed. |
duke@435 | 1922 | assert( _opclass == NULL, |
duke@435 | 1923 | "'primary', 'secondary' and 'tertiary' don't follow operand."); |
duke@435 | 1924 | } else { |
duke@435 | 1925 | // Lookup its position in parameter list |
duke@435 | 1926 | int param_no = _encoding.rep_var_index(rep_var); |
duke@435 | 1927 | if ( param_no == -1 ) { |
duke@435 | 1928 | _AD.syntax_err( _encoding._linenum, |
duke@435 | 1929 | "Replacement variable %s not found in enc_class %s.\n", |
duke@435 | 1930 | rep_var, _encoding._name); |
duke@435 | 1931 | } |
duke@435 | 1932 | |
duke@435 | 1933 | // Lookup the corresponding ins_encode parameter |
duke@435 | 1934 | const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no); |
duke@435 | 1935 | if (inst_rep_var == NULL) { |
duke@435 | 1936 | _AD.syntax_err( _ins_encode._linenum, |
duke@435 | 1937 | "Parameter %s not passed to enc_class %s from instruct %s.\n", |
duke@435 | 1938 | rep_var, _encoding._name, _inst._ident); |
duke@435 | 1939 | } |
duke@435 | 1940 | |
duke@435 | 1941 | // Check if instruction's actual parameter is a local name in the instruction |
duke@435 | 1942 | const Form *local = _inst._localNames[inst_rep_var]; |
duke@435 | 1943 | OpClassForm *opc = (local != NULL) ? local->is_opclass() : NULL; |
duke@435 | 1944 | // Note: assert removed to allow constant and symbolic parameters |
duke@435 | 1945 | // assert( opc, "replacement variable was not found in local names"); |
duke@435 | 1946 | // Lookup the index position iff the replacement variable is a localName |
duke@435 | 1947 | int idx = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1; |
duke@435 | 1948 | |
duke@435 | 1949 | if ( idx != -1 ) { |
duke@435 | 1950 | // This is a local in the instruction |
duke@435 | 1951 | // Update local state info. |
duke@435 | 1952 | _opclass = opc; |
duke@435 | 1953 | _operand_idx = idx; |
duke@435 | 1954 | _local_name = rep_var; |
duke@435 | 1955 | _operand_name = inst_rep_var; |
duke@435 | 1956 | |
duke@435 | 1957 | // !!!!! |
duke@435 | 1958 | // Do not support consecutive operands. |
duke@435 | 1959 | assert( _operand == NULL, "Unimplemented()"); |
duke@435 | 1960 | _operand = opc->is_operand(); |
duke@435 | 1961 | } |
duke@435 | 1962 | else if( ADLParser::is_literal_constant(inst_rep_var) ) { |
duke@435 | 1963 | // Instruction provided a constant expression |
duke@435 | 1964 | // Check later that encoding specifies $$$constant to resolve as constant |
duke@435 | 1965 | _constant_status = LITERAL_SEEN; |
duke@435 | 1966 | } |
duke@435 | 1967 | else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) { |
duke@435 | 1968 | // Instruction provided an opcode: "primary", "secondary", "tertiary" |
duke@435 | 1969 | // Check later that encoding specifies $$$constant to resolve as constant |
duke@435 | 1970 | _constant_status = LITERAL_SEEN; |
duke@435 | 1971 | } |
duke@435 | 1972 | else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) { |
duke@435 | 1973 | // Instruction provided a literal register name for this parameter |
duke@435 | 1974 | // Check that encoding specifies $$$reg to resolve.as register. |
duke@435 | 1975 | _reg_status = LITERAL_SEEN; |
duke@435 | 1976 | } |
duke@435 | 1977 | else { |
duke@435 | 1978 | // Check for unimplemented functionality before hard failure |
duke@435 | 1979 | assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label"); |
duke@435 | 1980 | assert( false, "ShouldNotReachHere()"); |
duke@435 | 1981 | } |
duke@435 | 1982 | } // done checking which operand this is. |
duke@435 | 1983 | } else { |
duke@435 | 1984 | // |
duke@435 | 1985 | // A subfield variable, '$$' prefix |
duke@435 | 1986 | // Check for fields that may require relocation information. |
duke@435 | 1987 | // Then check that literal register parameters are accessed with 'reg' or 'constant' |
duke@435 | 1988 | // |
duke@435 | 1989 | if ( strcmp(rep_var,"$disp") == 0 ) { |
duke@435 | 1990 | _doing_disp = true; |
duke@435 | 1991 | assert( _opclass, "Must use operand or operand class before '$disp'"); |
duke@435 | 1992 | if( _operand == NULL ) { |
duke@435 | 1993 | // Only have an operand class, generate run-time check for relocation |
duke@435 | 1994 | _may_reloc = true; |
duke@435 | 1995 | _reloc_form = RELOC_DISP; |
duke@435 | 1996 | _reloc_type = AdlcVMDeps::oop_reloc_type(); |
duke@435 | 1997 | } else { |
duke@435 | 1998 | // Do precise check on operand: is it a ConP or not |
duke@435 | 1999 | // |
duke@435 | 2000 | // Check interface for value of displacement |
duke@435 | 2001 | assert( ( _operand->_interface != NULL ), |
duke@435 | 2002 | "$disp can only follow memory interface operand"); |
duke@435 | 2003 | MemInterface *mem_interface= _operand->_interface->is_MemInterface(); |
duke@435 | 2004 | assert( mem_interface != NULL, |
duke@435 | 2005 | "$disp can only follow memory interface operand"); |
duke@435 | 2006 | const char *disp = mem_interface->_disp; |
duke@435 | 2007 | |
duke@435 | 2008 | if( disp != NULL && (*disp == '$') ) { |
duke@435 | 2009 | // MemInterface::disp contains a replacement variable, |
duke@435 | 2010 | // Check if this matches a ConP |
duke@435 | 2011 | // |
duke@435 | 2012 | // Lookup replacement variable, in operand's component list |
duke@435 | 2013 | const char *rep_var_name = disp + 1; // Skip '$' |
duke@435 | 2014 | const Component *comp = _operand->_components.search(rep_var_name); |
duke@435 | 2015 | assert( comp != NULL,"Replacement variable not found in components"); |
duke@435 | 2016 | const char *type = comp->_type; |
duke@435 | 2017 | // Lookup operand form for replacement variable's type |
duke@435 | 2018 | const Form *form = _AD.globalNames()[type]; |
duke@435 | 2019 | assert( form != NULL, "Replacement variable's type not found"); |
duke@435 | 2020 | OperandForm *op = form->is_operand(); |
duke@435 | 2021 | assert( op, "Attempting to emit a non-register or non-constant"); |
duke@435 | 2022 | // Check if this is a constant |
duke@435 | 2023 | if (op->_matrule && op->_matrule->is_base_constant(_AD.globalNames())) { |
duke@435 | 2024 | // Check which constant this name maps to: _c0, _c1, ..., _cn |
duke@435 | 2025 | // const int idx = _operand.constant_position(_AD.globalNames(), comp); |
duke@435 | 2026 | // assert( idx != -1, "Constant component not found in operand"); |
duke@435 | 2027 | Form::DataType dtype = op->is_base_constant(_AD.globalNames()); |
duke@435 | 2028 | if ( dtype == Form::idealP ) { |
duke@435 | 2029 | _may_reloc = true; |
duke@435 | 2030 | // No longer true that idealP is always an oop |
duke@435 | 2031 | _reloc_form = RELOC_DISP; |
duke@435 | 2032 | _reloc_type = AdlcVMDeps::oop_reloc_type(); |
duke@435 | 2033 | } |
duke@435 | 2034 | } |
duke@435 | 2035 | |
duke@435 | 2036 | else if( _operand->is_user_name_for_sReg() != Form::none ) { |
duke@435 | 2037 | // The only non-constant allowed access to disp is an operand sRegX in a stackSlotX |
duke@435 | 2038 | assert( op->ideal_to_sReg_type(type) != Form::none, "StackSlots access displacements using 'sRegs'"); |
duke@435 | 2039 | _may_reloc = false; |
duke@435 | 2040 | } else { |
duke@435 | 2041 | assert( false, "fatal(); Only stackSlots can access a non-constant using 'disp'"); |
duke@435 | 2042 | } |
duke@435 | 2043 | } |
duke@435 | 2044 | } // finished with precise check of operand for relocation. |
duke@435 | 2045 | } // finished with subfield variable |
duke@435 | 2046 | else if ( strcmp(rep_var,"$constant") == 0 ) { |
duke@435 | 2047 | _doing_constant = true; |
duke@435 | 2048 | if ( _constant_status == LITERAL_NOT_SEEN ) { |
duke@435 | 2049 | // Check operand for type of constant |
duke@435 | 2050 | assert( _operand, "Must use operand before '$$constant'"); |
duke@435 | 2051 | Form::DataType dtype = _operand->is_base_constant(_AD.globalNames()); |
duke@435 | 2052 | _constant_type = dtype; |
duke@435 | 2053 | if ( dtype == Form::idealP ) { |
duke@435 | 2054 | _may_reloc = true; |
duke@435 | 2055 | // No longer true that idealP is always an oop |
duke@435 | 2056 | // // _must_reloc = true; |
duke@435 | 2057 | _reloc_form = RELOC_IMMEDIATE; |
duke@435 | 2058 | _reloc_type = AdlcVMDeps::oop_reloc_type(); |
duke@435 | 2059 | } else { |
duke@435 | 2060 | // No relocation information needed |
duke@435 | 2061 | } |
duke@435 | 2062 | } else { |
duke@435 | 2063 | // User-provided literals may not require relocation information !!!!! |
duke@435 | 2064 | assert( _constant_status == LITERAL_SEEN, "Must know we are processing a user-provided literal"); |
duke@435 | 2065 | } |
duke@435 | 2066 | } |
duke@435 | 2067 | else if ( strcmp(rep_var,"$label") == 0 ) { |
duke@435 | 2068 | // Calls containing labels require relocation |
duke@435 | 2069 | if ( _inst.is_ideal_call() ) { |
duke@435 | 2070 | _may_reloc = true; |
duke@435 | 2071 | // !!!!! !!!!! |
duke@435 | 2072 | _reloc_type = AdlcVMDeps::none_reloc_type(); |
duke@435 | 2073 | } |
duke@435 | 2074 | } |
duke@435 | 2075 | |
duke@435 | 2076 | // literal register parameter must be accessed as a 'reg' field. |
duke@435 | 2077 | if ( _reg_status != LITERAL_NOT_SEEN ) { |
duke@435 | 2078 | assert( _reg_status == LITERAL_SEEN, "Must have seen register literal before now"); |
duke@435 | 2079 | if (strcmp(rep_var,"$reg") == 0 || reg_conversion(rep_var) != NULL) { |
duke@435 | 2080 | _reg_status = LITERAL_ACCESSED; |
duke@435 | 2081 | } else { |
duke@435 | 2082 | assert( false, "invalid access to literal register parameter"); |
duke@435 | 2083 | } |
duke@435 | 2084 | } |
duke@435 | 2085 | // literal constant parameters must be accessed as a 'constant' field |
duke@435 | 2086 | if ( _constant_status != LITERAL_NOT_SEEN ) { |
duke@435 | 2087 | assert( _constant_status == LITERAL_SEEN, "Must have seen constant literal before now"); |
duke@435 | 2088 | if( strcmp(rep_var,"$constant") == 0 ) { |
duke@435 | 2089 | _constant_status = LITERAL_ACCESSED; |
duke@435 | 2090 | } else { |
duke@435 | 2091 | assert( false, "invalid access to literal constant parameter"); |
duke@435 | 2092 | } |
duke@435 | 2093 | } |
duke@435 | 2094 | } // end replacement and/or subfield |
duke@435 | 2095 | |
duke@435 | 2096 | } |
duke@435 | 2097 | |
duke@435 | 2098 | void add_rep_var(const char *rep_var) { |
duke@435 | 2099 | // Handle subfield and replacement variables. |
duke@435 | 2100 | if ( ( *rep_var == '$' ) && ( *(rep_var+1) == '$' ) ) { |
duke@435 | 2101 | // Check for emit prefix, '$$emit32' |
duke@435 | 2102 | assert( _cleared, "Can not nest $$$emit32"); |
duke@435 | 2103 | if ( strcmp(rep_var,"$$emit32") == 0 ) { |
duke@435 | 2104 | _doing_emit_d32 = true; |
duke@435 | 2105 | } |
duke@435 | 2106 | else if ( strcmp(rep_var,"$$emit16") == 0 ) { |
duke@435 | 2107 | _doing_emit_d16 = true; |
duke@435 | 2108 | } |
duke@435 | 2109 | else if ( strcmp(rep_var,"$$emit_hi") == 0 ) { |
duke@435 | 2110 | _doing_emit_hi = true; |
duke@435 | 2111 | } |
duke@435 | 2112 | else if ( strcmp(rep_var,"$$emit_lo") == 0 ) { |
duke@435 | 2113 | _doing_emit_lo = true; |
duke@435 | 2114 | } |
duke@435 | 2115 | else if ( strcmp(rep_var,"$$emit8") == 0 ) { |
duke@435 | 2116 | _doing_emit8 = true; |
duke@435 | 2117 | } |
duke@435 | 2118 | else { |
duke@435 | 2119 | _AD.syntax_err(_encoding._linenum, "Unsupported $$operation '%s'\n",rep_var); |
duke@435 | 2120 | assert( false, "fatal();"); |
duke@435 | 2121 | } |
duke@435 | 2122 | } |
duke@435 | 2123 | else { |
duke@435 | 2124 | // Update state for replacement variables |
duke@435 | 2125 | update_state( rep_var ); |
duke@435 | 2126 | _strings_to_emit.addName(rep_var); |
duke@435 | 2127 | } |
duke@435 | 2128 | _cleared = false; |
duke@435 | 2129 | } |
duke@435 | 2130 | |
duke@435 | 2131 | void emit_replacement() { |
duke@435 | 2132 | // A replacement variable or one of its subfields |
duke@435 | 2133 | // Obtain replacement variable from list |
duke@435 | 2134 | // const char *ec_rep_var = encoding->_rep_vars.iter(); |
duke@435 | 2135 | const char *rep_var; |
duke@435 | 2136 | _strings_to_emit.reset(); |
duke@435 | 2137 | while ( (rep_var = _strings_to_emit.iter()) != NULL ) { |
duke@435 | 2138 | |
duke@435 | 2139 | if ( (*rep_var) == '$' ) { |
duke@435 | 2140 | // A subfield variable, '$$' prefix |
duke@435 | 2141 | emit_field( rep_var ); |
duke@435 | 2142 | } else { |
duke@435 | 2143 | // A replacement variable, '$' prefix |
duke@435 | 2144 | emit_rep_var( rep_var ); |
duke@435 | 2145 | } // end replacement and/or subfield |
duke@435 | 2146 | } |
duke@435 | 2147 | } |
duke@435 | 2148 | |
duke@435 | 2149 | void emit_reloc_type(const char* type) { |
duke@435 | 2150 | fprintf(_fp, "%s", type) |
duke@435 | 2151 | ; |
duke@435 | 2152 | } |
duke@435 | 2153 | |
duke@435 | 2154 | |
duke@435 | 2155 | void gen_emit_x_reloc(const char *d32_lo_hi ) { |
duke@435 | 2156 | fprintf(_fp,"emit_%s_reloc(cbuf, ", d32_lo_hi ); |
duke@435 | 2157 | emit_replacement(); fprintf(_fp,", "); |
duke@435 | 2158 | emit_reloc_type( _reloc_type ); fprintf(_fp,", "); |
duke@435 | 2159 | fprintf(_fp, "%d", _reloc_form);fprintf(_fp, ");"); |
duke@435 | 2160 | } |
duke@435 | 2161 | |
duke@435 | 2162 | |
duke@435 | 2163 | void emit() { |
duke@435 | 2164 | // |
duke@435 | 2165 | // "emit_d32_reloc(" or "emit_hi_reloc" or "emit_lo_reloc" |
duke@435 | 2166 | // |
duke@435 | 2167 | // Emit the function name when generating an emit function |
duke@435 | 2168 | if ( _doing_emit_d32 || _doing_emit_hi || _doing_emit_lo ) { |
duke@435 | 2169 | const char *d32_hi_lo = _doing_emit_d32 ? "d32" : (_doing_emit_hi ? "hi" : "lo"); |
duke@435 | 2170 | // In general, relocatable isn't known at compiler compile time. |
duke@435 | 2171 | // Check results of prior scan |
duke@435 | 2172 | if ( ! _may_reloc ) { |
duke@435 | 2173 | // Definitely don't need relocation information |
duke@435 | 2174 | fprintf( _fp, "emit_%s(cbuf, ", d32_hi_lo ); |
duke@435 | 2175 | emit_replacement(); fprintf(_fp, ")"); |
duke@435 | 2176 | } |
duke@435 | 2177 | else if ( _must_reloc ) { |
duke@435 | 2178 | // Must emit relocation information |
duke@435 | 2179 | gen_emit_x_reloc( d32_hi_lo ); |
duke@435 | 2180 | } |
duke@435 | 2181 | else { |
duke@435 | 2182 | // Emit RUNTIME CHECK to see if value needs relocation info |
duke@435 | 2183 | // If emitting a relocatable address, use 'emit_d32_reloc' |
duke@435 | 2184 | const char *disp_constant = _doing_disp ? "disp" : _doing_constant ? "constant" : "INVALID"; |
duke@435 | 2185 | assert( (_doing_disp || _doing_constant) |
duke@435 | 2186 | && !(_doing_disp && _doing_constant), |
duke@435 | 2187 | "Must be emitting either a displacement or a constant"); |
duke@435 | 2188 | fprintf(_fp,"\n"); |
duke@435 | 2189 | fprintf(_fp,"if ( opnd_array(%d)->%s_is_oop() ) {\n", |
duke@435 | 2190 | _operand_idx, disp_constant); |
duke@435 | 2191 | fprintf(_fp," "); |
duke@435 | 2192 | gen_emit_x_reloc( d32_hi_lo ); fprintf(_fp,"\n"); |
duke@435 | 2193 | fprintf(_fp,"} else {\n"); |
duke@435 | 2194 | fprintf(_fp," emit_%s(cbuf, ", d32_hi_lo); |
duke@435 | 2195 | emit_replacement(); fprintf(_fp, ");\n"); fprintf(_fp,"}"); |
duke@435 | 2196 | } |
duke@435 | 2197 | } |
duke@435 | 2198 | else if ( _doing_emit_d16 ) { |
duke@435 | 2199 | // Relocation of 16-bit values is not supported |
duke@435 | 2200 | fprintf(_fp,"emit_d16(cbuf, "); |
duke@435 | 2201 | emit_replacement(); fprintf(_fp, ")"); |
duke@435 | 2202 | // No relocation done for 16-bit values |
duke@435 | 2203 | } |
duke@435 | 2204 | else if ( _doing_emit8 ) { |
duke@435 | 2205 | // Relocation of 8-bit values is not supported |
duke@435 | 2206 | fprintf(_fp,"emit_d8(cbuf, "); |
duke@435 | 2207 | emit_replacement(); fprintf(_fp, ")"); |
duke@435 | 2208 | // No relocation done for 8-bit values |
duke@435 | 2209 | } |
duke@435 | 2210 | else { |
duke@435 | 2211 | // Not an emit# command, just output the replacement string. |
duke@435 | 2212 | emit_replacement(); |
duke@435 | 2213 | } |
duke@435 | 2214 | |
duke@435 | 2215 | // Get ready for next state collection. |
duke@435 | 2216 | clear(); |
duke@435 | 2217 | } |
duke@435 | 2218 | |
duke@435 | 2219 | private: |
duke@435 | 2220 | |
duke@435 | 2221 | // recognizes names which represent MacroAssembler register types |
duke@435 | 2222 | // and return the conversion function to build them from OptoReg |
duke@435 | 2223 | const char* reg_conversion(const char* rep_var) { |
duke@435 | 2224 | if (strcmp(rep_var,"$Register") == 0) return "as_Register"; |
duke@435 | 2225 | if (strcmp(rep_var,"$FloatRegister") == 0) return "as_FloatRegister"; |
duke@435 | 2226 | #if defined(IA32) || defined(AMD64) |
duke@435 | 2227 | if (strcmp(rep_var,"$XMMRegister") == 0) return "as_XMMRegister"; |
duke@435 | 2228 | #endif |
duke@435 | 2229 | return NULL; |
duke@435 | 2230 | } |
duke@435 | 2231 | |
duke@435 | 2232 | void emit_field(const char *rep_var) { |
duke@435 | 2233 | const char* reg_convert = reg_conversion(rep_var); |
duke@435 | 2234 | |
duke@435 | 2235 | // A subfield variable, '$$subfield' |
duke@435 | 2236 | if ( strcmp(rep_var, "$reg") == 0 || reg_convert != NULL) { |
duke@435 | 2237 | // $reg form or the $Register MacroAssembler type conversions |
duke@435 | 2238 | assert( _operand_idx != -1, |
duke@435 | 2239 | "Must use this subfield after operand"); |
duke@435 | 2240 | if( _reg_status == LITERAL_NOT_SEEN ) { |
duke@435 | 2241 | if (_processing_noninput) { |
duke@435 | 2242 | const Form *local = _inst._localNames[_operand_name]; |
duke@435 | 2243 | OperandForm *oper = local->is_operand(); |
duke@435 | 2244 | const RegDef* first = oper->get_RegClass()->find_first_elem(); |
duke@435 | 2245 | if (reg_convert != NULL) { |
duke@435 | 2246 | fprintf(_fp, "%s(%s_enc)", reg_convert, first->_regname); |
duke@435 | 2247 | } else { |
duke@435 | 2248 | fprintf(_fp, "%s_enc", first->_regname); |
duke@435 | 2249 | } |
duke@435 | 2250 | } else { |
duke@435 | 2251 | fprintf(_fp,"->%s(ra_,this", reg_convert != NULL ? reg_convert : "reg"); |
duke@435 | 2252 | // Add parameter for index position, if not result operand |
duke@435 | 2253 | if( _operand_idx != 0 ) fprintf(_fp,",idx%d", _operand_idx); |
duke@435 | 2254 | fprintf(_fp,")"); |
duke@435 | 2255 | } |
duke@435 | 2256 | } else { |
duke@435 | 2257 | assert( _reg_status == LITERAL_OUTPUT, "should have output register literal in emit_rep_var"); |
duke@435 | 2258 | // Register literal has already been sent to output file, nothing more needed |
duke@435 | 2259 | } |
duke@435 | 2260 | } |
duke@435 | 2261 | else if ( strcmp(rep_var,"$base") == 0 ) { |
duke@435 | 2262 | assert( _operand_idx != -1, |
duke@435 | 2263 | "Must use this subfield after operand"); |
duke@435 | 2264 | assert( ! _may_reloc, "UnImplemented()"); |
duke@435 | 2265 | fprintf(_fp,"->base(ra_,this,idx%d)", _operand_idx); |
duke@435 | 2266 | } |
duke@435 | 2267 | else if ( strcmp(rep_var,"$index") == 0 ) { |
duke@435 | 2268 | assert( _operand_idx != -1, |
duke@435 | 2269 | "Must use this subfield after operand"); |
duke@435 | 2270 | assert( ! _may_reloc, "UnImplemented()"); |
duke@435 | 2271 | fprintf(_fp,"->index(ra_,this,idx%d)", _operand_idx); |
duke@435 | 2272 | } |
duke@435 | 2273 | else if ( strcmp(rep_var,"$scale") == 0 ) { |
duke@435 | 2274 | assert( ! _may_reloc, "UnImplemented()"); |
duke@435 | 2275 | fprintf(_fp,"->scale()"); |
duke@435 | 2276 | } |
duke@435 | 2277 | else if ( strcmp(rep_var,"$cmpcode") == 0 ) { |
duke@435 | 2278 | assert( ! _may_reloc, "UnImplemented()"); |
duke@435 | 2279 | fprintf(_fp,"->ccode()"); |
duke@435 | 2280 | } |
duke@435 | 2281 | else if ( strcmp(rep_var,"$constant") == 0 ) { |
duke@435 | 2282 | if( _constant_status == LITERAL_NOT_SEEN ) { |
duke@435 | 2283 | if ( _constant_type == Form::idealD ) { |
duke@435 | 2284 | fprintf(_fp,"->constantD()"); |
duke@435 | 2285 | } else if ( _constant_type == Form::idealF ) { |
duke@435 | 2286 | fprintf(_fp,"->constantF()"); |
duke@435 | 2287 | } else if ( _constant_type == Form::idealL ) { |
duke@435 | 2288 | fprintf(_fp,"->constantL()"); |
duke@435 | 2289 | } else { |
duke@435 | 2290 | fprintf(_fp,"->constant()"); |
duke@435 | 2291 | } |
duke@435 | 2292 | } else { |
duke@435 | 2293 | assert( _constant_status == LITERAL_OUTPUT, "should have output constant literal in emit_rep_var"); |
duke@435 | 2294 | // Cosntant literal has already been sent to output file, nothing more needed |
duke@435 | 2295 | } |
duke@435 | 2296 | } |
duke@435 | 2297 | else if ( strcmp(rep_var,"$disp") == 0 ) { |
duke@435 | 2298 | Form::DataType stack_type = _operand ? _operand->is_user_name_for_sReg() : Form::none; |
duke@435 | 2299 | if( _operand && _operand_idx==0 && stack_type != Form::none ) { |
duke@435 | 2300 | fprintf(_fp,"->disp(ra_,this,0)"); |
duke@435 | 2301 | } else { |
duke@435 | 2302 | fprintf(_fp,"->disp(ra_,this,idx%d)", _operand_idx); |
duke@435 | 2303 | } |
duke@435 | 2304 | } |
duke@435 | 2305 | else if ( strcmp(rep_var,"$label") == 0 ) { |
duke@435 | 2306 | fprintf(_fp,"->label()"); |
duke@435 | 2307 | } |
duke@435 | 2308 | else if ( strcmp(rep_var,"$method") == 0 ) { |
duke@435 | 2309 | fprintf(_fp,"->method()"); |
duke@435 | 2310 | } |
duke@435 | 2311 | else { |
duke@435 | 2312 | printf("emit_field: %s\n",rep_var); |
duke@435 | 2313 | assert( false, "UnImplemented()"); |
duke@435 | 2314 | } |
duke@435 | 2315 | } |
duke@435 | 2316 | |
duke@435 | 2317 | |
duke@435 | 2318 | void emit_rep_var(const char *rep_var) { |
duke@435 | 2319 | _processing_noninput = false; |
duke@435 | 2320 | // A replacement variable, originally '$' |
duke@435 | 2321 | if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) { |
never@850 | 2322 | if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(rep_var) )) { |
never@850 | 2323 | // Missing opcode |
never@850 | 2324 | _AD.syntax_err( _inst._linenum, |
never@850 | 2325 | "Missing $%s opcode definition in %s, used by encoding %s\n", |
never@850 | 2326 | rep_var, _inst._ident, _encoding._name); |
never@850 | 2327 | } |
duke@435 | 2328 | } |
duke@435 | 2329 | else { |
duke@435 | 2330 | // Lookup its position in parameter list |
duke@435 | 2331 | int param_no = _encoding.rep_var_index(rep_var); |
duke@435 | 2332 | if ( param_no == -1 ) { |
duke@435 | 2333 | _AD.syntax_err( _encoding._linenum, |
duke@435 | 2334 | "Replacement variable %s not found in enc_class %s.\n", |
duke@435 | 2335 | rep_var, _encoding._name); |
duke@435 | 2336 | } |
duke@435 | 2337 | // Lookup the corresponding ins_encode parameter |
duke@435 | 2338 | const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no); |
duke@435 | 2339 | |
duke@435 | 2340 | // Check if instruction's actual parameter is a local name in the instruction |
duke@435 | 2341 | const Form *local = _inst._localNames[inst_rep_var]; |
duke@435 | 2342 | OpClassForm *opc = (local != NULL) ? local->is_opclass() : NULL; |
duke@435 | 2343 | // Note: assert removed to allow constant and symbolic parameters |
duke@435 | 2344 | // assert( opc, "replacement variable was not found in local names"); |
duke@435 | 2345 | // Lookup the index position iff the replacement variable is a localName |
duke@435 | 2346 | int idx = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1; |
duke@435 | 2347 | if( idx != -1 ) { |
duke@435 | 2348 | if (_inst.is_noninput_operand(idx)) { |
duke@435 | 2349 | // This operand isn't a normal input so printing it is done |
duke@435 | 2350 | // specially. |
duke@435 | 2351 | _processing_noninput = true; |
duke@435 | 2352 | } else { |
duke@435 | 2353 | // Output the emit code for this operand |
duke@435 | 2354 | fprintf(_fp,"opnd_array(%d)",idx); |
duke@435 | 2355 | } |
duke@435 | 2356 | assert( _operand == opc->is_operand(), |
duke@435 | 2357 | "Previous emit $operand does not match current"); |
duke@435 | 2358 | } |
duke@435 | 2359 | else if( ADLParser::is_literal_constant(inst_rep_var) ) { |
duke@435 | 2360 | // else check if it is a constant expression |
duke@435 | 2361 | // Removed following assert to allow primitive C types as arguments to encodings |
duke@435 | 2362 | // assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter"); |
duke@435 | 2363 | fprintf(_fp,"(%s)", inst_rep_var); |
duke@435 | 2364 | _constant_status = LITERAL_OUTPUT; |
duke@435 | 2365 | } |
duke@435 | 2366 | else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) { |
duke@435 | 2367 | // else check if "primary", "secondary", "tertiary" |
duke@435 | 2368 | assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter"); |
never@850 | 2369 | if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(inst_rep_var) )) { |
never@850 | 2370 | // Missing opcode |
never@850 | 2371 | _AD.syntax_err( _inst._linenum, |
never@850 | 2372 | "Missing $%s opcode definition in %s\n", |
never@850 | 2373 | rep_var, _inst._ident); |
never@850 | 2374 | |
never@850 | 2375 | } |
duke@435 | 2376 | _constant_status = LITERAL_OUTPUT; |
duke@435 | 2377 | } |
duke@435 | 2378 | else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) { |
duke@435 | 2379 | // Instruction provided a literal register name for this parameter |
duke@435 | 2380 | // Check that encoding specifies $$$reg to resolve.as register. |
duke@435 | 2381 | assert( _reg_status == LITERAL_ACCESSED, "Must be processing a literal register parameter"); |
duke@435 | 2382 | fprintf(_fp,"(%s_enc)", inst_rep_var); |
duke@435 | 2383 | _reg_status = LITERAL_OUTPUT; |
duke@435 | 2384 | } |
duke@435 | 2385 | else { |
duke@435 | 2386 | // Check for unimplemented functionality before hard failure |
duke@435 | 2387 | assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label"); |
duke@435 | 2388 | assert( false, "ShouldNotReachHere()"); |
duke@435 | 2389 | } |
duke@435 | 2390 | // all done |
duke@435 | 2391 | } |
duke@435 | 2392 | } |
duke@435 | 2393 | |
duke@435 | 2394 | }; // end class DefineEmitState |
duke@435 | 2395 | |
duke@435 | 2396 | |
duke@435 | 2397 | void ArchDesc::defineSize(FILE *fp, InstructForm &inst) { |
duke@435 | 2398 | |
duke@435 | 2399 | //(1) |
duke@435 | 2400 | // Output instruction's emit prototype |
duke@435 | 2401 | fprintf(fp,"uint %sNode::size(PhaseRegAlloc *ra_) const {\n", |
duke@435 | 2402 | inst._ident); |
duke@435 | 2403 | |
coleenp@548 | 2404 | fprintf(fp, " assert(VerifyOops || MachNode::size(ra_) <= %s, \"bad fixed size\");\n", inst._size); |
coleenp@548 | 2405 | |
duke@435 | 2406 | //(2) |
duke@435 | 2407 | // Print the size |
duke@435 | 2408 | fprintf(fp, " return (VerifyOops ? MachNode::size(ra_) : %s);\n", inst._size); |
duke@435 | 2409 | |
duke@435 | 2410 | // (3) and (4) |
duke@435 | 2411 | fprintf(fp,"}\n"); |
duke@435 | 2412 | } |
duke@435 | 2413 | |
duke@435 | 2414 | void ArchDesc::defineEmit(FILE *fp, InstructForm &inst) { |
duke@435 | 2415 | InsEncode *ins_encode = inst._insencode; |
duke@435 | 2416 | |
duke@435 | 2417 | // (1) |
duke@435 | 2418 | // Output instruction's emit prototype |
duke@435 | 2419 | fprintf(fp,"void %sNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {\n", |
duke@435 | 2420 | inst._ident); |
duke@435 | 2421 | |
duke@435 | 2422 | // If user did not define an encode section, |
duke@435 | 2423 | // provide stub that does not generate any machine code. |
duke@435 | 2424 | if( (_encode == NULL) || (ins_encode == NULL) ) { |
duke@435 | 2425 | fprintf(fp, " // User did not define an encode section.\n"); |
duke@435 | 2426 | fprintf(fp,"}\n"); |
duke@435 | 2427 | return; |
duke@435 | 2428 | } |
duke@435 | 2429 | |
duke@435 | 2430 | // Save current instruction's starting address (helps with relocation). |
duke@435 | 2431 | fprintf( fp, " cbuf.set_inst_mark();\n"); |
duke@435 | 2432 | |
duke@435 | 2433 | // // // idx0 is only needed for syntactic purposes and only by "storeSSI" |
duke@435 | 2434 | // fprintf( fp, " unsigned idx0 = 0;\n"); |
duke@435 | 2435 | |
duke@435 | 2436 | // Output each operand's offset into the array of registers. |
duke@435 | 2437 | inst.index_temps( fp, _globalNames ); |
duke@435 | 2438 | |
duke@435 | 2439 | // Output this instruction's encodings |
duke@435 | 2440 | const char *ec_name; |
duke@435 | 2441 | bool user_defined = false; |
duke@435 | 2442 | ins_encode->reset(); |
duke@435 | 2443 | while ( (ec_name = ins_encode->encode_class_iter()) != NULL ) { |
duke@435 | 2444 | fprintf(fp, " {"); |
duke@435 | 2445 | // Output user-defined encoding |
duke@435 | 2446 | user_defined = true; |
duke@435 | 2447 | |
duke@435 | 2448 | const char *ec_code = NULL; |
duke@435 | 2449 | const char *ec_rep_var = NULL; |
duke@435 | 2450 | EncClass *encoding = _encode->encClass(ec_name); |
duke@435 | 2451 | if (encoding == NULL) { |
duke@435 | 2452 | fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name); |
duke@435 | 2453 | abort(); |
duke@435 | 2454 | } |
duke@435 | 2455 | |
duke@435 | 2456 | if (ins_encode->current_encoding_num_args() != encoding->num_args()) { |
duke@435 | 2457 | globalAD->syntax_err(ins_encode->_linenum, "In %s: passing %d arguments to %s but expecting %d", |
duke@435 | 2458 | inst._ident, ins_encode->current_encoding_num_args(), |
duke@435 | 2459 | ec_name, encoding->num_args()); |
duke@435 | 2460 | } |
duke@435 | 2461 | |
duke@435 | 2462 | DefineEmitState pending(fp, *this, *encoding, *ins_encode, inst ); |
duke@435 | 2463 | encoding->_code.reset(); |
duke@435 | 2464 | encoding->_rep_vars.reset(); |
duke@435 | 2465 | // Process list of user-defined strings, |
duke@435 | 2466 | // and occurrences of replacement variables. |
duke@435 | 2467 | // Replacement Vars are pushed into a list and then output |
duke@435 | 2468 | while ( (ec_code = encoding->_code.iter()) != NULL ) { |
duke@435 | 2469 | if ( ! encoding->_code.is_signal( ec_code ) ) { |
duke@435 | 2470 | // Emit pending code |
duke@435 | 2471 | pending.emit(); |
duke@435 | 2472 | pending.clear(); |
duke@435 | 2473 | // Emit this code section |
duke@435 | 2474 | fprintf(fp,"%s", ec_code); |
duke@435 | 2475 | } else { |
duke@435 | 2476 | // A replacement variable or one of its subfields |
duke@435 | 2477 | // Obtain replacement variable from list |
duke@435 | 2478 | ec_rep_var = encoding->_rep_vars.iter(); |
duke@435 | 2479 | pending.add_rep_var(ec_rep_var); |
duke@435 | 2480 | } |
duke@435 | 2481 | } |
duke@435 | 2482 | // Emit pending code |
duke@435 | 2483 | pending.emit(); |
duke@435 | 2484 | pending.clear(); |
duke@435 | 2485 | fprintf(fp, "}\n"); |
duke@435 | 2486 | } // end while instruction's encodings |
duke@435 | 2487 | |
duke@435 | 2488 | // Check if user stated which encoding to user |
duke@435 | 2489 | if ( user_defined == false ) { |
duke@435 | 2490 | fprintf(fp, " // User did not define which encode class to use.\n"); |
duke@435 | 2491 | } |
duke@435 | 2492 | |
duke@435 | 2493 | // (3) and (4) |
duke@435 | 2494 | fprintf(fp,"}\n"); |
duke@435 | 2495 | } |
duke@435 | 2496 | |
duke@435 | 2497 | // --------------------------------------------------------------------------- |
duke@435 | 2498 | //--------Utilities to build MachOper and MachNode derived Classes------------ |
duke@435 | 2499 | // --------------------------------------------------------------------------- |
duke@435 | 2500 | |
duke@435 | 2501 | //------------------------------Utilities to build Operand Classes------------ |
duke@435 | 2502 | static void defineIn_RegMask(FILE *fp, FormDict &globals, OperandForm &oper) { |
duke@435 | 2503 | uint num_edges = oper.num_edges(globals); |
duke@435 | 2504 | if( num_edges != 0 ) { |
duke@435 | 2505 | // Method header |
duke@435 | 2506 | fprintf(fp, "const RegMask *%sOper::in_RegMask(int index) const {\n", |
duke@435 | 2507 | oper._ident); |
duke@435 | 2508 | |
duke@435 | 2509 | // Assert that the index is in range. |
duke@435 | 2510 | fprintf(fp, " assert(0 <= index && index < %d, \"index out of range\");\n", |
duke@435 | 2511 | num_edges); |
duke@435 | 2512 | |
duke@435 | 2513 | // Figure out if all RegMasks are the same. |
duke@435 | 2514 | const char* first_reg_class = oper.in_reg_class(0, globals); |
duke@435 | 2515 | bool all_same = true; |
duke@435 | 2516 | assert(first_reg_class != NULL, "did not find register mask"); |
duke@435 | 2517 | |
duke@435 | 2518 | for (uint index = 1; all_same && index < num_edges; index++) { |
duke@435 | 2519 | const char* some_reg_class = oper.in_reg_class(index, globals); |
duke@435 | 2520 | assert(some_reg_class != NULL, "did not find register mask"); |
duke@435 | 2521 | if (strcmp(first_reg_class, some_reg_class) != 0) { |
duke@435 | 2522 | all_same = false; |
duke@435 | 2523 | } |
duke@435 | 2524 | } |
duke@435 | 2525 | |
duke@435 | 2526 | if (all_same) { |
duke@435 | 2527 | // Return the sole RegMask. |
duke@435 | 2528 | if (strcmp(first_reg_class, "stack_slots") == 0) { |
duke@435 | 2529 | fprintf(fp," return &(Compile::current()->FIRST_STACK_mask());\n"); |
duke@435 | 2530 | } else { |
duke@435 | 2531 | fprintf(fp," return &%s_mask;\n", toUpper(first_reg_class)); |
duke@435 | 2532 | } |
duke@435 | 2533 | } else { |
duke@435 | 2534 | // Build a switch statement to return the desired mask. |
duke@435 | 2535 | fprintf(fp," switch (index) {\n"); |
duke@435 | 2536 | |
duke@435 | 2537 | for (uint index = 0; index < num_edges; index++) { |
duke@435 | 2538 | const char *reg_class = oper.in_reg_class(index, globals); |
duke@435 | 2539 | assert(reg_class != NULL, "did not find register mask"); |
duke@435 | 2540 | if( !strcmp(reg_class, "stack_slots") ) { |
duke@435 | 2541 | fprintf(fp, " case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index); |
duke@435 | 2542 | } else { |
duke@435 | 2543 | fprintf(fp, " case %d: return &%s_mask;\n", index, toUpper(reg_class)); |
duke@435 | 2544 | } |
duke@435 | 2545 | } |
duke@435 | 2546 | fprintf(fp," }\n"); |
duke@435 | 2547 | fprintf(fp," ShouldNotReachHere();\n"); |
duke@435 | 2548 | fprintf(fp," return NULL;\n"); |
duke@435 | 2549 | } |
duke@435 | 2550 | |
duke@435 | 2551 | // Method close |
duke@435 | 2552 | fprintf(fp, "}\n\n"); |
duke@435 | 2553 | } |
duke@435 | 2554 | } |
duke@435 | 2555 | |
duke@435 | 2556 | // generate code to create a clone for a class derived from MachOper |
duke@435 | 2557 | // |
duke@435 | 2558 | // (0) MachOper *MachOperXOper::clone(Compile* C) const { |
duke@435 | 2559 | // (1) return new (C) MachXOper( _ccode, _c0, _c1, ..., _cn); |
duke@435 | 2560 | // (2) } |
duke@435 | 2561 | // |
duke@435 | 2562 | static void defineClone(FILE *fp, FormDict &globalNames, OperandForm &oper) { |
duke@435 | 2563 | fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper._ident); |
duke@435 | 2564 | // Check for constants that need to be copied over |
duke@435 | 2565 | const int num_consts = oper.num_consts(globalNames); |
duke@435 | 2566 | const bool is_ideal_bool = oper.is_ideal_bool(); |
duke@435 | 2567 | if( (num_consts > 0) ) { |
duke@435 | 2568 | fprintf(fp," return new (C) %sOper(", oper._ident); |
duke@435 | 2569 | // generate parameters for constants |
duke@435 | 2570 | int i = 0; |
duke@435 | 2571 | fprintf(fp,"_c%d", i); |
duke@435 | 2572 | for( i = 1; i < num_consts; ++i) { |
duke@435 | 2573 | fprintf(fp,", _c%d", i); |
duke@435 | 2574 | } |
duke@435 | 2575 | // finish line (1) |
duke@435 | 2576 | fprintf(fp,");\n"); |
duke@435 | 2577 | } |
duke@435 | 2578 | else { |
duke@435 | 2579 | assert( num_consts == 0, "Currently support zero or one constant per operand clone function"); |
duke@435 | 2580 | fprintf(fp," return new (C) %sOper();\n", oper._ident); |
duke@435 | 2581 | } |
duke@435 | 2582 | // finish method |
duke@435 | 2583 | fprintf(fp,"}\n"); |
duke@435 | 2584 | } |
duke@435 | 2585 | |
duke@435 | 2586 | static void define_hash(FILE *fp, char *operand) { |
duke@435 | 2587 | fprintf(fp,"uint %sOper::hash() const { return 5; }\n", operand); |
duke@435 | 2588 | } |
duke@435 | 2589 | |
duke@435 | 2590 | static void define_cmp(FILE *fp, char *operand) { |
duke@435 | 2591 | fprintf(fp,"uint %sOper::cmp( const MachOper &oper ) const { return opcode() == oper.opcode(); }\n", operand); |
duke@435 | 2592 | } |
duke@435 | 2593 | |
duke@435 | 2594 | |
duke@435 | 2595 | // Helper functions for bug 4796752, abstracted with minimal modification |
duke@435 | 2596 | // from define_oper_interface() |
duke@435 | 2597 | OperandForm *rep_var_to_operand(const char *encoding, OperandForm &oper, FormDict &globals) { |
duke@435 | 2598 | OperandForm *op = NULL; |
duke@435 | 2599 | // Check for replacement variable |
duke@435 | 2600 | if( *encoding == '$' ) { |
duke@435 | 2601 | // Replacement variable |
duke@435 | 2602 | const char *rep_var = encoding + 1; |
duke@435 | 2603 | // Lookup replacement variable, rep_var, in operand's component list |
duke@435 | 2604 | const Component *comp = oper._components.search(rep_var); |
duke@435 | 2605 | assert( comp != NULL, "Replacement variable not found in components"); |
duke@435 | 2606 | // Lookup operand form for replacement variable's type |
duke@435 | 2607 | const char *type = comp->_type; |
duke@435 | 2608 | Form *form = (Form*)globals[type]; |
duke@435 | 2609 | assert( form != NULL, "Replacement variable's type not found"); |
duke@435 | 2610 | op = form->is_operand(); |
duke@435 | 2611 | assert( op, "Attempting to emit a non-register or non-constant"); |
duke@435 | 2612 | } |
duke@435 | 2613 | |
duke@435 | 2614 | return op; |
duke@435 | 2615 | } |
duke@435 | 2616 | |
duke@435 | 2617 | int rep_var_to_constant_index(const char *encoding, OperandForm &oper, FormDict &globals) { |
duke@435 | 2618 | int idx = -1; |
duke@435 | 2619 | // Check for replacement variable |
duke@435 | 2620 | if( *encoding == '$' ) { |
duke@435 | 2621 | // Replacement variable |
duke@435 | 2622 | const char *rep_var = encoding + 1; |
duke@435 | 2623 | // Lookup replacement variable, rep_var, in operand's component list |
duke@435 | 2624 | const Component *comp = oper._components.search(rep_var); |
duke@435 | 2625 | assert( comp != NULL, "Replacement variable not found in components"); |
duke@435 | 2626 | // Lookup operand form for replacement variable's type |
duke@435 | 2627 | const char *type = comp->_type; |
duke@435 | 2628 | Form *form = (Form*)globals[type]; |
duke@435 | 2629 | assert( form != NULL, "Replacement variable's type not found"); |
duke@435 | 2630 | OperandForm *op = form->is_operand(); |
duke@435 | 2631 | assert( op, "Attempting to emit a non-register or non-constant"); |
duke@435 | 2632 | // Check that this is a constant and find constant's index: |
duke@435 | 2633 | if (op->_matrule && op->_matrule->is_base_constant(globals)) { |
duke@435 | 2634 | idx = oper.constant_position(globals, comp); |
duke@435 | 2635 | } |
duke@435 | 2636 | } |
duke@435 | 2637 | |
duke@435 | 2638 | return idx; |
duke@435 | 2639 | } |
duke@435 | 2640 | |
duke@435 | 2641 | bool is_regI(const char *encoding, OperandForm &oper, FormDict &globals ) { |
duke@435 | 2642 | bool is_regI = false; |
duke@435 | 2643 | |
duke@435 | 2644 | OperandForm *op = rep_var_to_operand(encoding, oper, globals); |
duke@435 | 2645 | if( op != NULL ) { |
duke@435 | 2646 | // Check that this is a register |
duke@435 | 2647 | if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) { |
duke@435 | 2648 | // Register |
duke@435 | 2649 | const char* ideal = op->ideal_type(globals); |
duke@435 | 2650 | is_regI = (ideal && (op->ideal_to_Reg_type(ideal) == Form::idealI)); |
duke@435 | 2651 | } |
duke@435 | 2652 | } |
duke@435 | 2653 | |
duke@435 | 2654 | return is_regI; |
duke@435 | 2655 | } |
duke@435 | 2656 | |
duke@435 | 2657 | bool is_conP(const char *encoding, OperandForm &oper, FormDict &globals ) { |
duke@435 | 2658 | bool is_conP = false; |
duke@435 | 2659 | |
duke@435 | 2660 | OperandForm *op = rep_var_to_operand(encoding, oper, globals); |
duke@435 | 2661 | if( op != NULL ) { |
duke@435 | 2662 | // Check that this is a constant pointer |
duke@435 | 2663 | if (op->_matrule && op->_matrule->is_base_constant(globals)) { |
duke@435 | 2664 | // Constant |
duke@435 | 2665 | Form::DataType dtype = op->is_base_constant(globals); |
duke@435 | 2666 | is_conP = (dtype == Form::idealP); |
duke@435 | 2667 | } |
duke@435 | 2668 | } |
duke@435 | 2669 | |
duke@435 | 2670 | return is_conP; |
duke@435 | 2671 | } |
duke@435 | 2672 | |
duke@435 | 2673 | |
duke@435 | 2674 | // Define a MachOper interface methods |
duke@435 | 2675 | void ArchDesc::define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals, |
duke@435 | 2676 | const char *name, const char *encoding) { |
duke@435 | 2677 | bool emit_position = false; |
duke@435 | 2678 | int position = -1; |
duke@435 | 2679 | |
duke@435 | 2680 | fprintf(fp," virtual int %s", name); |
duke@435 | 2681 | // Generate access method for base, index, scale, disp, ... |
duke@435 | 2682 | if( (strcmp(name,"base") == 0) || (strcmp(name,"index") == 0) ) { |
duke@435 | 2683 | fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n"); |
duke@435 | 2684 | emit_position = true; |
duke@435 | 2685 | } else if ( (strcmp(name,"disp") == 0) ) { |
duke@435 | 2686 | fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n"); |
duke@435 | 2687 | } else { |
duke@435 | 2688 | fprintf(fp,"() const { "); |
duke@435 | 2689 | } |
duke@435 | 2690 | |
duke@435 | 2691 | // Check for hexadecimal value OR replacement variable |
duke@435 | 2692 | if( *encoding == '$' ) { |
duke@435 | 2693 | // Replacement variable |
duke@435 | 2694 | const char *rep_var = encoding + 1; |
duke@435 | 2695 | fprintf(fp,"// Replacement variable: %s\n", encoding+1); |
duke@435 | 2696 | // Lookup replacement variable, rep_var, in operand's component list |
duke@435 | 2697 | const Component *comp = oper._components.search(rep_var); |
duke@435 | 2698 | assert( comp != NULL, "Replacement variable not found in components"); |
duke@435 | 2699 | // Lookup operand form for replacement variable's type |
duke@435 | 2700 | const char *type = comp->_type; |
duke@435 | 2701 | Form *form = (Form*)globals[type]; |
duke@435 | 2702 | assert( form != NULL, "Replacement variable's type not found"); |
duke@435 | 2703 | OperandForm *op = form->is_operand(); |
duke@435 | 2704 | assert( op, "Attempting to emit a non-register or non-constant"); |
duke@435 | 2705 | // Check that this is a register or a constant and generate code: |
duke@435 | 2706 | if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) { |
duke@435 | 2707 | // Register |
duke@435 | 2708 | int idx_offset = oper.register_position( globals, rep_var); |
duke@435 | 2709 | position = idx_offset; |
duke@435 | 2710 | fprintf(fp," return (int)ra_->get_encode(node->in(idx"); |
duke@435 | 2711 | if ( idx_offset > 0 ) fprintf(fp, "+%d",idx_offset); |
duke@435 | 2712 | fprintf(fp,"));\n"); |
duke@435 | 2713 | } else if ( op->ideal_to_sReg_type(op->_ident) != Form::none ) { |
duke@435 | 2714 | // StackSlot for an sReg comes either from input node or from self, when idx==0 |
duke@435 | 2715 | fprintf(fp," if( idx != 0 ) {\n"); |
duke@435 | 2716 | fprintf(fp," // Access register number for input operand\n"); |
duke@435 | 2717 | fprintf(fp," return ra_->reg2offset(ra_->get_reg_first(node->in(idx)));/* sReg */\n"); |
duke@435 | 2718 | fprintf(fp," }\n"); |
duke@435 | 2719 | fprintf(fp," // Access register number from myself\n"); |
duke@435 | 2720 | fprintf(fp," return ra_->reg2offset(ra_->get_reg_first(node));/* sReg */\n"); |
duke@435 | 2721 | } else if (op->_matrule && op->_matrule->is_base_constant(globals)) { |
duke@435 | 2722 | // Constant |
duke@435 | 2723 | // Check which constant this name maps to: _c0, _c1, ..., _cn |
duke@435 | 2724 | const int idx = oper.constant_position(globals, comp); |
duke@435 | 2725 | assert( idx != -1, "Constant component not found in operand"); |
duke@435 | 2726 | // Output code for this constant, type dependent. |
duke@435 | 2727 | fprintf(fp," return (int)" ); |
duke@435 | 2728 | oper.access_constant(fp, globals, (uint)idx /* , const_type */); |
duke@435 | 2729 | fprintf(fp,";\n"); |
duke@435 | 2730 | } else { |
duke@435 | 2731 | assert( false, "Attempting to emit a non-register or non-constant"); |
duke@435 | 2732 | } |
duke@435 | 2733 | } |
duke@435 | 2734 | else if( *encoding == '0' && *(encoding+1) == 'x' ) { |
duke@435 | 2735 | // Hex value |
duke@435 | 2736 | fprintf(fp,"return %s;", encoding); |
duke@435 | 2737 | } else { |
duke@435 | 2738 | assert( false, "Do not support octal or decimal encode constants"); |
duke@435 | 2739 | } |
duke@435 | 2740 | fprintf(fp," }\n"); |
duke@435 | 2741 | |
duke@435 | 2742 | if( emit_position && (position != -1) && (oper.num_edges(globals) > 0) ) { |
duke@435 | 2743 | fprintf(fp," virtual int %s_position() const { return %d; }\n", name, position); |
duke@435 | 2744 | MemInterface *mem_interface = oper._interface->is_MemInterface(); |
duke@435 | 2745 | const char *base = mem_interface->_base; |
duke@435 | 2746 | const char *disp = mem_interface->_disp; |
duke@435 | 2747 | if( emit_position && (strcmp(name,"base") == 0) |
duke@435 | 2748 | && base != NULL && is_regI(base, oper, globals) |
duke@435 | 2749 | && disp != NULL && is_conP(disp, oper, globals) ) { |
duke@435 | 2750 | // Found a memory access using a constant pointer for a displacement |
duke@435 | 2751 | // and a base register containing an integer offset. |
duke@435 | 2752 | // In this case the base and disp are reversed with respect to what |
duke@435 | 2753 | // is expected by MachNode::get_base_and_disp() and MachNode::adr_type(). |
duke@435 | 2754 | // Provide a non-NULL return for disp_as_type() that will allow adr_type() |
duke@435 | 2755 | // to correctly compute the access type for alias analysis. |
duke@435 | 2756 | // |
duke@435 | 2757 | // See BugId 4796752, operand indOffset32X in i486.ad |
duke@435 | 2758 | int idx = rep_var_to_constant_index(disp, oper, globals); |
duke@435 | 2759 | fprintf(fp," virtual const TypePtr *disp_as_type() const { return _c%d; }\n", idx); |
duke@435 | 2760 | } |
duke@435 | 2761 | } |
duke@435 | 2762 | } |
duke@435 | 2763 | |
duke@435 | 2764 | // |
duke@435 | 2765 | // Construct the method to copy _idx, inputs and operands to new node. |
duke@435 | 2766 | static void define_fill_new_machnode(bool used, FILE *fp_cpp) { |
duke@435 | 2767 | fprintf(fp_cpp, "\n"); |
duke@435 | 2768 | fprintf(fp_cpp, "// Copy _idx, inputs and operands to new node\n"); |
duke@435 | 2769 | fprintf(fp_cpp, "void MachNode::fill_new_machnode( MachNode* node, Compile* C) const {\n"); |
duke@435 | 2770 | if( !used ) { |
duke@435 | 2771 | fprintf(fp_cpp, " // This architecture does not have cisc or short branch instructions\n"); |
duke@435 | 2772 | fprintf(fp_cpp, " ShouldNotCallThis();\n"); |
duke@435 | 2773 | fprintf(fp_cpp, "}\n"); |
duke@435 | 2774 | } else { |
duke@435 | 2775 | // New node must use same node index for access through allocator's tables |
duke@435 | 2776 | fprintf(fp_cpp, " // New node must use same node index\n"); |
duke@435 | 2777 | fprintf(fp_cpp, " node->set_idx( _idx );\n"); |
duke@435 | 2778 | // Copy machine-independent inputs |
duke@435 | 2779 | fprintf(fp_cpp, " // Copy machine-independent inputs\n"); |
duke@435 | 2780 | fprintf(fp_cpp, " for( uint j = 0; j < req(); j++ ) {\n"); |
duke@435 | 2781 | fprintf(fp_cpp, " node->add_req(in(j));\n"); |
duke@435 | 2782 | fprintf(fp_cpp, " }\n"); |
duke@435 | 2783 | // Copy machine operands to new MachNode |
duke@435 | 2784 | fprintf(fp_cpp, " // Copy my operands, except for cisc position\n"); |
duke@435 | 2785 | fprintf(fp_cpp, " int nopnds = num_opnds();\n"); |
duke@435 | 2786 | fprintf(fp_cpp, " assert( node->num_opnds() == (uint)nopnds, \"Must have same number of operands\");\n"); |
duke@435 | 2787 | fprintf(fp_cpp, " MachOper **to = node->_opnds;\n"); |
duke@435 | 2788 | fprintf(fp_cpp, " for( int i = 0; i < nopnds; i++ ) {\n"); |
duke@435 | 2789 | fprintf(fp_cpp, " if( i != cisc_operand() ) \n"); |
duke@435 | 2790 | fprintf(fp_cpp, " to[i] = _opnds[i]->clone(C);\n"); |
duke@435 | 2791 | fprintf(fp_cpp, " }\n"); |
duke@435 | 2792 | fprintf(fp_cpp, "}\n"); |
duke@435 | 2793 | } |
duke@435 | 2794 | fprintf(fp_cpp, "\n"); |
duke@435 | 2795 | } |
duke@435 | 2796 | |
duke@435 | 2797 | //------------------------------defineClasses---------------------------------- |
duke@435 | 2798 | // Define members of MachNode and MachOper classes based on |
duke@435 | 2799 | // operand and instruction lists |
duke@435 | 2800 | void ArchDesc::defineClasses(FILE *fp) { |
duke@435 | 2801 | |
duke@435 | 2802 | // Define the contents of an array containing the machine register names |
duke@435 | 2803 | defineRegNames(fp, _register); |
duke@435 | 2804 | // Define an array containing the machine register encoding values |
duke@435 | 2805 | defineRegEncodes(fp, _register); |
duke@435 | 2806 | // Generate an enumeration of user-defined register classes |
duke@435 | 2807 | // and a list of register masks, one for each class. |
duke@435 | 2808 | // Only define the RegMask value objects in the expand file. |
duke@435 | 2809 | // Declare each as an extern const RegMask ...; in ad_<arch>.hpp |
duke@435 | 2810 | declare_register_masks(_HPP_file._fp); |
duke@435 | 2811 | // build_register_masks(fp); |
duke@435 | 2812 | build_register_masks(_CPP_EXPAND_file._fp); |
duke@435 | 2813 | // Define the pipe_classes |
duke@435 | 2814 | build_pipe_classes(_CPP_PIPELINE_file._fp); |
duke@435 | 2815 | |
duke@435 | 2816 | // Generate Machine Classes for each operand defined in AD file |
duke@435 | 2817 | fprintf(fp,"\n"); |
duke@435 | 2818 | fprintf(fp,"\n"); |
duke@435 | 2819 | fprintf(fp,"//------------------Define classes derived from MachOper---------------------\n"); |
duke@435 | 2820 | // Iterate through all operands |
duke@435 | 2821 | _operands.reset(); |
duke@435 | 2822 | OperandForm *oper; |
duke@435 | 2823 | for( ; (oper = (OperandForm*)_operands.iter()) != NULL; ) { |
duke@435 | 2824 | // Ensure this is a machine-world instruction |
duke@435 | 2825 | if ( oper->ideal_only() ) continue; |
duke@435 | 2826 | // !!!!! |
duke@435 | 2827 | // The declaration of labelOper is in machine-independent file: machnode |
duke@435 | 2828 | if ( strcmp(oper->_ident,"label") == 0 ) { |
duke@435 | 2829 | defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper); |
duke@435 | 2830 | |
duke@435 | 2831 | fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident); |
duke@435 | 2832 | fprintf(fp," return new (C) %sOper(_label, _block_num);\n", oper->_ident); |
duke@435 | 2833 | fprintf(fp,"}\n"); |
duke@435 | 2834 | |
duke@435 | 2835 | fprintf(fp,"uint %sOper::opcode() const { return %s; }\n", |
duke@435 | 2836 | oper->_ident, machOperEnum(oper->_ident)); |
duke@435 | 2837 | // // Currently all XXXOper::Hash() methods are identical (990820) |
duke@435 | 2838 | // define_hash(fp, oper->_ident); |
duke@435 | 2839 | // // Currently all XXXOper::Cmp() methods are identical (990820) |
duke@435 | 2840 | // define_cmp(fp, oper->_ident); |
duke@435 | 2841 | fprintf(fp,"\n"); |
duke@435 | 2842 | |
duke@435 | 2843 | continue; |
duke@435 | 2844 | } |
duke@435 | 2845 | |
duke@435 | 2846 | // The declaration of methodOper is in machine-independent file: machnode |
duke@435 | 2847 | if ( strcmp(oper->_ident,"method") == 0 ) { |
duke@435 | 2848 | defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper); |
duke@435 | 2849 | |
duke@435 | 2850 | fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident); |
duke@435 | 2851 | fprintf(fp," return new (C) %sOper(_method);\n", oper->_ident); |
duke@435 | 2852 | fprintf(fp,"}\n"); |
duke@435 | 2853 | |
duke@435 | 2854 | fprintf(fp,"uint %sOper::opcode() const { return %s; }\n", |
duke@435 | 2855 | oper->_ident, machOperEnum(oper->_ident)); |
duke@435 | 2856 | // // Currently all XXXOper::Hash() methods are identical (990820) |
duke@435 | 2857 | // define_hash(fp, oper->_ident); |
duke@435 | 2858 | // // Currently all XXXOper::Cmp() methods are identical (990820) |
duke@435 | 2859 | // define_cmp(fp, oper->_ident); |
duke@435 | 2860 | fprintf(fp,"\n"); |
duke@435 | 2861 | |
duke@435 | 2862 | continue; |
duke@435 | 2863 | } |
duke@435 | 2864 | |
duke@435 | 2865 | defineIn_RegMask(fp, _globalNames, *oper); |
duke@435 | 2866 | defineClone(_CPP_CLONE_file._fp, _globalNames, *oper); |
duke@435 | 2867 | // // Currently all XXXOper::Hash() methods are identical (990820) |
duke@435 | 2868 | // define_hash(fp, oper->_ident); |
duke@435 | 2869 | // // Currently all XXXOper::Cmp() methods are identical (990820) |
duke@435 | 2870 | // define_cmp(fp, oper->_ident); |
duke@435 | 2871 | |
duke@435 | 2872 | // side-call to generate output that used to be in the header file: |
duke@435 | 2873 | extern void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file); |
duke@435 | 2874 | gen_oper_format(_CPP_FORMAT_file._fp, _globalNames, *oper, true); |
duke@435 | 2875 | |
duke@435 | 2876 | } |
duke@435 | 2877 | |
duke@435 | 2878 | |
duke@435 | 2879 | // Generate Machine Classes for each instruction defined in AD file |
duke@435 | 2880 | fprintf(fp,"//------------------Define members for classes derived from MachNode----------\n"); |
duke@435 | 2881 | // Output the definitions for out_RegMask() // & kill_RegMask() |
duke@435 | 2882 | _instructions.reset(); |
duke@435 | 2883 | InstructForm *instr; |
duke@435 | 2884 | MachNodeForm *machnode; |
duke@435 | 2885 | for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 2886 | // Ensure this is a machine-world instruction |
duke@435 | 2887 | if ( instr->ideal_only() ) continue; |
duke@435 | 2888 | |
duke@435 | 2889 | defineOut_RegMask(_CPP_MISC_file._fp, instr->_ident, reg_mask(*instr)); |
duke@435 | 2890 | } |
duke@435 | 2891 | |
duke@435 | 2892 | bool used = false; |
duke@435 | 2893 | // Output the definitions for expand rules & peephole rules |
duke@435 | 2894 | _instructions.reset(); |
duke@435 | 2895 | for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 2896 | // Ensure this is a machine-world instruction |
duke@435 | 2897 | if ( instr->ideal_only() ) continue; |
duke@435 | 2898 | // If there are multiple defs/kills, or an explicit expand rule, build rule |
duke@435 | 2899 | if( instr->expands() || instr->needs_projections() || |
duke@435 | 2900 | instr->has_temps() || |
duke@435 | 2901 | instr->_matrule != NULL && |
duke@435 | 2902 | instr->num_opnds() != instr->num_unique_opnds() ) |
duke@435 | 2903 | defineExpand(_CPP_EXPAND_file._fp, instr); |
duke@435 | 2904 | // If there is an explicit peephole rule, build it |
duke@435 | 2905 | if ( instr->peepholes() ) |
duke@435 | 2906 | definePeephole(_CPP_PEEPHOLE_file._fp, instr); |
duke@435 | 2907 | |
duke@435 | 2908 | // Output code to convert to the cisc version, if applicable |
duke@435 | 2909 | used |= instr->define_cisc_version(*this, fp); |
duke@435 | 2910 | |
duke@435 | 2911 | // Output code to convert to the short branch version, if applicable |
duke@435 | 2912 | used |= instr->define_short_branch_methods(fp); |
duke@435 | 2913 | } |
duke@435 | 2914 | |
duke@435 | 2915 | // Construct the method called by cisc_version() to copy inputs and operands. |
duke@435 | 2916 | define_fill_new_machnode(used, fp); |
duke@435 | 2917 | |
duke@435 | 2918 | // Output the definitions for labels |
duke@435 | 2919 | _instructions.reset(); |
duke@435 | 2920 | while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { |
duke@435 | 2921 | // Ensure this is a machine-world instruction |
duke@435 | 2922 | if ( instr->ideal_only() ) continue; |
duke@435 | 2923 | |
duke@435 | 2924 | // Access the fields for operand Label |
duke@435 | 2925 | int label_position = instr->label_position(); |
duke@435 | 2926 | if( label_position != -1 ) { |
duke@435 | 2927 | // Set the label |
duke@435 | 2928 | fprintf(fp,"void %sNode::label_set( Label& label, uint block_num ) {\n", instr->_ident); |
duke@435 | 2929 | fprintf(fp," labelOper* oper = (labelOper*)(opnd_array(%d));\n", |
duke@435 | 2930 | label_position ); |
duke@435 | 2931 | fprintf(fp," oper->_label = &label;\n"); |
duke@435 | 2932 | fprintf(fp," oper->_block_num = block_num;\n"); |
duke@435 | 2933 | fprintf(fp,"}\n"); |
duke@435 | 2934 | } |
duke@435 | 2935 | } |
duke@435 | 2936 | |
duke@435 | 2937 | // Output the definitions for methods |
duke@435 | 2938 | _instructions.reset(); |
duke@435 | 2939 | while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { |
duke@435 | 2940 | // Ensure this is a machine-world instruction |
duke@435 | 2941 | if ( instr->ideal_only() ) continue; |
duke@435 | 2942 | |
duke@435 | 2943 | // Access the fields for operand Label |
duke@435 | 2944 | int method_position = instr->method_position(); |
duke@435 | 2945 | if( method_position != -1 ) { |
duke@435 | 2946 | // Access the method's address |
duke@435 | 2947 | fprintf(fp,"void %sNode::method_set( intptr_t method ) {\n", instr->_ident); |
duke@435 | 2948 | fprintf(fp," ((methodOper*)opnd_array(%d))->_method = method;\n", |
duke@435 | 2949 | method_position ); |
duke@435 | 2950 | fprintf(fp,"}\n"); |
duke@435 | 2951 | fprintf(fp,"\n"); |
duke@435 | 2952 | } |
duke@435 | 2953 | } |
duke@435 | 2954 | |
duke@435 | 2955 | // Define this instruction's number of relocation entries, base is '0' |
duke@435 | 2956 | _instructions.reset(); |
duke@435 | 2957 | while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { |
duke@435 | 2958 | // Output the definition for number of relocation entries |
duke@435 | 2959 | uint reloc_size = instr->reloc(_globalNames); |
duke@435 | 2960 | if ( reloc_size != 0 ) { |
duke@435 | 2961 | fprintf(fp,"int %sNode::reloc() const {\n", instr->_ident); |
duke@435 | 2962 | fprintf(fp, " return %d;\n", reloc_size ); |
duke@435 | 2963 | fprintf(fp,"}\n"); |
duke@435 | 2964 | fprintf(fp,"\n"); |
duke@435 | 2965 | } |
duke@435 | 2966 | } |
duke@435 | 2967 | fprintf(fp,"\n"); |
duke@435 | 2968 | |
duke@435 | 2969 | // Output the definitions for code generation |
duke@435 | 2970 | // |
duke@435 | 2971 | // address ___Node::emit(address ptr, PhaseRegAlloc *ra_) const { |
duke@435 | 2972 | // // ... encoding defined by user |
duke@435 | 2973 | // return ptr; |
duke@435 | 2974 | // } |
duke@435 | 2975 | // |
duke@435 | 2976 | _instructions.reset(); |
duke@435 | 2977 | for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 2978 | // Ensure this is a machine-world instruction |
duke@435 | 2979 | if ( instr->ideal_only() ) continue; |
duke@435 | 2980 | |
duke@435 | 2981 | if (instr->_insencode) defineEmit(fp, *instr); |
duke@435 | 2982 | if (instr->_size) defineSize(fp, *instr); |
duke@435 | 2983 | |
duke@435 | 2984 | // side-call to generate output that used to be in the header file: |
duke@435 | 2985 | extern void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &oper, bool for_c_file); |
duke@435 | 2986 | gen_inst_format(_CPP_FORMAT_file._fp, _globalNames, *instr, true); |
duke@435 | 2987 | } |
duke@435 | 2988 | |
duke@435 | 2989 | // Output the definitions for alias analysis |
duke@435 | 2990 | _instructions.reset(); |
duke@435 | 2991 | for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 2992 | // Ensure this is a machine-world instruction |
duke@435 | 2993 | if ( instr->ideal_only() ) continue; |
duke@435 | 2994 | |
duke@435 | 2995 | // Analyze machine instructions that either USE or DEF memory. |
duke@435 | 2996 | int memory_operand = instr->memory_operand(_globalNames); |
duke@435 | 2997 | // Some guys kill all of memory |
duke@435 | 2998 | if ( instr->is_wide_memory_kill(_globalNames) ) { |
duke@435 | 2999 | memory_operand = InstructForm::MANY_MEMORY_OPERANDS; |
duke@435 | 3000 | } |
duke@435 | 3001 | |
duke@435 | 3002 | if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) { |
duke@435 | 3003 | if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) { |
duke@435 | 3004 | fprintf(fp,"const TypePtr *%sNode::adr_type() const { return TypePtr::BOTTOM; }\n", instr->_ident); |
duke@435 | 3005 | fprintf(fp,"const MachOper* %sNode::memory_operand() const { return (MachOper*)-1; }\n", instr->_ident); |
duke@435 | 3006 | } else { |
duke@435 | 3007 | fprintf(fp,"const MachOper* %sNode::memory_operand() const { return _opnds[%d]; }\n", instr->_ident, memory_operand); |
duke@435 | 3008 | } |
duke@435 | 3009 | } |
duke@435 | 3010 | } |
duke@435 | 3011 | |
duke@435 | 3012 | // Get the length of the longest identifier |
duke@435 | 3013 | int max_ident_len = 0; |
duke@435 | 3014 | _instructions.reset(); |
duke@435 | 3015 | |
duke@435 | 3016 | for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 3017 | if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) { |
duke@435 | 3018 | int ident_len = (int)strlen(instr->_ident); |
duke@435 | 3019 | if( max_ident_len < ident_len ) |
duke@435 | 3020 | max_ident_len = ident_len; |
duke@435 | 3021 | } |
duke@435 | 3022 | } |
duke@435 | 3023 | |
duke@435 | 3024 | // Emit specifically for Node(s) |
duke@435 | 3025 | fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n", |
duke@435 | 3026 | max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL"); |
duke@435 | 3027 | fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return %s; }\n", |
duke@435 | 3028 | max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL"); |
duke@435 | 3029 | fprintf(_CPP_PIPELINE_file._fp, "\n"); |
duke@435 | 3030 | |
duke@435 | 3031 | fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n", |
duke@435 | 3032 | max_ident_len, "MachNode", _pipeline ? "(&pipeline_class_Unknown_Instructions)" : "NULL"); |
duke@435 | 3033 | fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return pipeline_class(); }\n", |
duke@435 | 3034 | max_ident_len, "MachNode"); |
duke@435 | 3035 | fprintf(_CPP_PIPELINE_file._fp, "\n"); |
duke@435 | 3036 | |
duke@435 | 3037 | // Output the definitions for machine node specific pipeline data |
duke@435 | 3038 | _machnodes.reset(); |
duke@435 | 3039 | |
duke@435 | 3040 | for ( ; (machnode = (MachNodeForm*)_machnodes.iter()) != NULL; ) { |
duke@435 | 3041 | fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %sNode::pipeline() const { return (&pipeline_class_%03d); }\n", |
duke@435 | 3042 | machnode->_ident, ((class PipeClassForm *)_pipeline->_classdict[machnode->_machnode_pipe])->_num); |
duke@435 | 3043 | } |
duke@435 | 3044 | |
duke@435 | 3045 | fprintf(_CPP_PIPELINE_file._fp, "\n"); |
duke@435 | 3046 | |
duke@435 | 3047 | // Output the definitions for instruction pipeline static data references |
duke@435 | 3048 | _instructions.reset(); |
duke@435 | 3049 | |
duke@435 | 3050 | for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 3051 | if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) { |
duke@435 | 3052 | fprintf(_CPP_PIPELINE_file._fp, "\n"); |
duke@435 | 3053 | fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline_class() { return (&pipeline_class_%03d); }\n", |
duke@435 | 3054 | max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num); |
duke@435 | 3055 | fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline() const { return (&pipeline_class_%03d); }\n", |
duke@435 | 3056 | max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num); |
duke@435 | 3057 | } |
duke@435 | 3058 | } |
duke@435 | 3059 | } |
duke@435 | 3060 | |
duke@435 | 3061 | |
duke@435 | 3062 | // -------------------------------- maps ------------------------------------ |
duke@435 | 3063 | |
duke@435 | 3064 | // Information needed to generate the ReduceOp mapping for the DFA |
duke@435 | 3065 | class OutputReduceOp : public OutputMap { |
duke@435 | 3066 | public: |
duke@435 | 3067 | OutputReduceOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) |
duke@435 | 3068 | : OutputMap(hpp, cpp, globals, AD) {}; |
duke@435 | 3069 | |
duke@435 | 3070 | void declaration() { fprintf(_hpp, "extern const int reduceOp[];\n"); } |
duke@435 | 3071 | void definition() { fprintf(_cpp, "const int reduceOp[] = {\n"); } |
duke@435 | 3072 | void closing() { fprintf(_cpp, " 0 // no trailing comma\n"); |
duke@435 | 3073 | OutputMap::closing(); |
duke@435 | 3074 | } |
duke@435 | 3075 | void map(OpClassForm &opc) { |
duke@435 | 3076 | const char *reduce = opc._ident; |
duke@435 | 3077 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3078 | else fprintf(_cpp, " 0"); |
duke@435 | 3079 | } |
duke@435 | 3080 | void map(OperandForm &oper) { |
duke@435 | 3081 | // Most operands without match rules, e.g. eFlagsReg, do not have a result operand |
duke@435 | 3082 | const char *reduce = (oper._matrule ? oper.reduce_result() : NULL); |
duke@435 | 3083 | // operand stackSlot does not have a match rule, but produces a stackSlot |
duke@435 | 3084 | if( oper.is_user_name_for_sReg() != Form::none ) reduce = oper.reduce_result(); |
duke@435 | 3085 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3086 | else fprintf(_cpp, " 0"); |
duke@435 | 3087 | } |
duke@435 | 3088 | void map(InstructForm &inst) { |
duke@435 | 3089 | const char *reduce = (inst._matrule ? inst.reduce_result() : NULL); |
duke@435 | 3090 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3091 | else fprintf(_cpp, " 0"); |
duke@435 | 3092 | } |
duke@435 | 3093 | void map(char *reduce) { |
duke@435 | 3094 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3095 | else fprintf(_cpp, " 0"); |
duke@435 | 3096 | } |
duke@435 | 3097 | }; |
duke@435 | 3098 | |
duke@435 | 3099 | // Information needed to generate the LeftOp mapping for the DFA |
duke@435 | 3100 | class OutputLeftOp : public OutputMap { |
duke@435 | 3101 | public: |
duke@435 | 3102 | OutputLeftOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) |
duke@435 | 3103 | : OutputMap(hpp, cpp, globals, AD) {}; |
duke@435 | 3104 | |
duke@435 | 3105 | void declaration() { fprintf(_hpp, "extern const int leftOp[];\n"); } |
duke@435 | 3106 | void definition() { fprintf(_cpp, "const int leftOp[] = {\n"); } |
duke@435 | 3107 | void closing() { fprintf(_cpp, " 0 // no trailing comma\n"); |
duke@435 | 3108 | OutputMap::closing(); |
duke@435 | 3109 | } |
duke@435 | 3110 | void map(OpClassForm &opc) { fprintf(_cpp, " 0"); } |
duke@435 | 3111 | void map(OperandForm &oper) { |
duke@435 | 3112 | const char *reduce = oper.reduce_left(_globals); |
duke@435 | 3113 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3114 | else fprintf(_cpp, " 0"); |
duke@435 | 3115 | } |
duke@435 | 3116 | void map(char *name) { |
duke@435 | 3117 | const char *reduce = _AD.reduceLeft(name); |
duke@435 | 3118 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3119 | else fprintf(_cpp, " 0"); |
duke@435 | 3120 | } |
duke@435 | 3121 | void map(InstructForm &inst) { |
duke@435 | 3122 | const char *reduce = inst.reduce_left(_globals); |
duke@435 | 3123 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3124 | else fprintf(_cpp, " 0"); |
duke@435 | 3125 | } |
duke@435 | 3126 | }; |
duke@435 | 3127 | |
duke@435 | 3128 | |
duke@435 | 3129 | // Information needed to generate the RightOp mapping for the DFA |
duke@435 | 3130 | class OutputRightOp : public OutputMap { |
duke@435 | 3131 | public: |
duke@435 | 3132 | OutputRightOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) |
duke@435 | 3133 | : OutputMap(hpp, cpp, globals, AD) {}; |
duke@435 | 3134 | |
duke@435 | 3135 | void declaration() { fprintf(_hpp, "extern const int rightOp[];\n"); } |
duke@435 | 3136 | void definition() { fprintf(_cpp, "const int rightOp[] = {\n"); } |
duke@435 | 3137 | void closing() { fprintf(_cpp, " 0 // no trailing comma\n"); |
duke@435 | 3138 | OutputMap::closing(); |
duke@435 | 3139 | } |
duke@435 | 3140 | void map(OpClassForm &opc) { fprintf(_cpp, " 0"); } |
duke@435 | 3141 | void map(OperandForm &oper) { |
duke@435 | 3142 | const char *reduce = oper.reduce_right(_globals); |
duke@435 | 3143 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3144 | else fprintf(_cpp, " 0"); |
duke@435 | 3145 | } |
duke@435 | 3146 | void map(char *name) { |
duke@435 | 3147 | const char *reduce = _AD.reduceRight(name); |
duke@435 | 3148 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3149 | else fprintf(_cpp, " 0"); |
duke@435 | 3150 | } |
duke@435 | 3151 | void map(InstructForm &inst) { |
duke@435 | 3152 | const char *reduce = inst.reduce_right(_globals); |
duke@435 | 3153 | if( reduce ) fprintf(_cpp, " %s_rule", reduce); |
duke@435 | 3154 | else fprintf(_cpp, " 0"); |
duke@435 | 3155 | } |
duke@435 | 3156 | }; |
duke@435 | 3157 | |
duke@435 | 3158 | |
duke@435 | 3159 | // Information needed to generate the Rule names for the DFA |
duke@435 | 3160 | class OutputRuleName : public OutputMap { |
duke@435 | 3161 | public: |
duke@435 | 3162 | OutputRuleName(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) |
duke@435 | 3163 | : OutputMap(hpp, cpp, globals, AD) {}; |
duke@435 | 3164 | |
duke@435 | 3165 | void declaration() { fprintf(_hpp, "extern const char *ruleName[];\n"); } |
duke@435 | 3166 | void definition() { fprintf(_cpp, "const char *ruleName[] = {\n"); } |
duke@435 | 3167 | void closing() { fprintf(_cpp, " \"no trailing comma\"\n"); |
duke@435 | 3168 | OutputMap::closing(); |
duke@435 | 3169 | } |
duke@435 | 3170 | void map(OpClassForm &opc) { fprintf(_cpp, " \"%s\"", _AD.machOperEnum(opc._ident) ); } |
duke@435 | 3171 | void map(OperandForm &oper) { fprintf(_cpp, " \"%s\"", _AD.machOperEnum(oper._ident) ); } |
duke@435 | 3172 | void map(char *name) { fprintf(_cpp, " \"%s\"", name ? name : "0"); } |
duke@435 | 3173 | void map(InstructForm &inst){ fprintf(_cpp, " \"%s\"", inst._ident ? inst._ident : "0"); } |
duke@435 | 3174 | }; |
duke@435 | 3175 | |
duke@435 | 3176 | |
duke@435 | 3177 | // Information needed to generate the swallowed mapping for the DFA |
duke@435 | 3178 | class OutputSwallowed : public OutputMap { |
duke@435 | 3179 | public: |
duke@435 | 3180 | OutputSwallowed(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) |
duke@435 | 3181 | : OutputMap(hpp, cpp, globals, AD) {}; |
duke@435 | 3182 | |
duke@435 | 3183 | void declaration() { fprintf(_hpp, "extern const bool swallowed[];\n"); } |
duke@435 | 3184 | void definition() { fprintf(_cpp, "const bool swallowed[] = {\n"); } |
duke@435 | 3185 | void closing() { fprintf(_cpp, " false // no trailing comma\n"); |
duke@435 | 3186 | OutputMap::closing(); |
duke@435 | 3187 | } |
duke@435 | 3188 | void map(OperandForm &oper) { // Generate the entry for this opcode |
duke@435 | 3189 | const char *swallowed = oper.swallowed(_globals) ? "true" : "false"; |
duke@435 | 3190 | fprintf(_cpp, " %s", swallowed); |
duke@435 | 3191 | } |
duke@435 | 3192 | void map(OpClassForm &opc) { fprintf(_cpp, " false"); } |
duke@435 | 3193 | void map(char *name) { fprintf(_cpp, " false"); } |
duke@435 | 3194 | void map(InstructForm &inst){ fprintf(_cpp, " false"); } |
duke@435 | 3195 | }; |
duke@435 | 3196 | |
duke@435 | 3197 | |
duke@435 | 3198 | // Information needed to generate the decision array for instruction chain rule |
duke@435 | 3199 | class OutputInstChainRule : public OutputMap { |
duke@435 | 3200 | public: |
duke@435 | 3201 | OutputInstChainRule(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) |
duke@435 | 3202 | : OutputMap(hpp, cpp, globals, AD) {}; |
duke@435 | 3203 | |
duke@435 | 3204 | void declaration() { fprintf(_hpp, "extern const bool instruction_chain_rule[];\n"); } |
duke@435 | 3205 | void definition() { fprintf(_cpp, "const bool instruction_chain_rule[] = {\n"); } |
duke@435 | 3206 | void closing() { fprintf(_cpp, " false // no trailing comma\n"); |
duke@435 | 3207 | OutputMap::closing(); |
duke@435 | 3208 | } |
duke@435 | 3209 | void map(OpClassForm &opc) { fprintf(_cpp, " false"); } |
duke@435 | 3210 | void map(OperandForm &oper) { fprintf(_cpp, " false"); } |
duke@435 | 3211 | void map(char *name) { fprintf(_cpp, " false"); } |
duke@435 | 3212 | void map(InstructForm &inst) { // Check for simple chain rule |
duke@435 | 3213 | const char *chain = inst.is_simple_chain_rule(_globals) ? "true" : "false"; |
duke@435 | 3214 | fprintf(_cpp, " %s", chain); |
duke@435 | 3215 | } |
duke@435 | 3216 | }; |
duke@435 | 3217 | |
duke@435 | 3218 | |
duke@435 | 3219 | //---------------------------build_map------------------------------------ |
duke@435 | 3220 | // Build mapping from enumeration for densely packed operands |
duke@435 | 3221 | // TO result and child types. |
duke@435 | 3222 | void ArchDesc::build_map(OutputMap &map) { |
duke@435 | 3223 | FILE *fp_hpp = map.decl_file(); |
duke@435 | 3224 | FILE *fp_cpp = map.def_file(); |
duke@435 | 3225 | int idx = 0; |
duke@435 | 3226 | OperandForm *op; |
duke@435 | 3227 | OpClassForm *opc; |
duke@435 | 3228 | InstructForm *inst; |
duke@435 | 3229 | |
duke@435 | 3230 | // Construct this mapping |
duke@435 | 3231 | map.declaration(); |
duke@435 | 3232 | fprintf(fp_cpp,"\n"); |
duke@435 | 3233 | map.definition(); |
duke@435 | 3234 | |
duke@435 | 3235 | // Output the mapping for operands |
duke@435 | 3236 | map.record_position(OutputMap::BEGIN_OPERANDS, idx ); |
duke@435 | 3237 | _operands.reset(); |
duke@435 | 3238 | for(; (op = (OperandForm*)_operands.iter()) != NULL; ) { |
duke@435 | 3239 | // Ensure this is a machine-world instruction |
duke@435 | 3240 | if ( op->ideal_only() ) continue; |
duke@435 | 3241 | |
duke@435 | 3242 | // Generate the entry for this opcode |
duke@435 | 3243 | map.map(*op); fprintf(fp_cpp, ", // %d\n", idx); |
duke@435 | 3244 | ++idx; |
duke@435 | 3245 | }; |
duke@435 | 3246 | fprintf(fp_cpp, " // last operand\n"); |
duke@435 | 3247 | |
duke@435 | 3248 | // Place all user-defined operand classes into the mapping |
duke@435 | 3249 | map.record_position(OutputMap::BEGIN_OPCLASSES, idx ); |
duke@435 | 3250 | _opclass.reset(); |
duke@435 | 3251 | for(; (opc = (OpClassForm*)_opclass.iter()) != NULL; ) { |
duke@435 | 3252 | map.map(*opc); fprintf(fp_cpp, ", // %d\n", idx); |
duke@435 | 3253 | ++idx; |
duke@435 | 3254 | }; |
duke@435 | 3255 | fprintf(fp_cpp, " // last operand class\n"); |
duke@435 | 3256 | |
duke@435 | 3257 | // Place all internally defined operands into the mapping |
duke@435 | 3258 | map.record_position(OutputMap::BEGIN_INTERNALS, idx ); |
duke@435 | 3259 | _internalOpNames.reset(); |
duke@435 | 3260 | char *name = NULL; |
duke@435 | 3261 | for(; (name = (char *)_internalOpNames.iter()) != NULL; ) { |
duke@435 | 3262 | map.map(name); fprintf(fp_cpp, ", // %d\n", idx); |
duke@435 | 3263 | ++idx; |
duke@435 | 3264 | }; |
duke@435 | 3265 | fprintf(fp_cpp, " // last internally defined operand\n"); |
duke@435 | 3266 | |
duke@435 | 3267 | // Place all user-defined instructions into the mapping |
duke@435 | 3268 | if( map.do_instructions() ) { |
duke@435 | 3269 | map.record_position(OutputMap::BEGIN_INSTRUCTIONS, idx ); |
duke@435 | 3270 | // Output all simple instruction chain rules first |
duke@435 | 3271 | map.record_position(OutputMap::BEGIN_INST_CHAIN_RULES, idx ); |
duke@435 | 3272 | { |
duke@435 | 3273 | _instructions.reset(); |
duke@435 | 3274 | for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 3275 | // Ensure this is a machine-world instruction |
duke@435 | 3276 | if ( inst->ideal_only() ) continue; |
duke@435 | 3277 | if ( ! inst->is_simple_chain_rule(_globalNames) ) continue; |
duke@435 | 3278 | if ( inst->rematerialize(_globalNames, get_registers()) ) continue; |
duke@435 | 3279 | |
duke@435 | 3280 | map.map(*inst); fprintf(fp_cpp, ", // %d\n", idx); |
duke@435 | 3281 | ++idx; |
duke@435 | 3282 | }; |
duke@435 | 3283 | map.record_position(OutputMap::BEGIN_REMATERIALIZE, idx ); |
duke@435 | 3284 | _instructions.reset(); |
duke@435 | 3285 | for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 3286 | // Ensure this is a machine-world instruction |
duke@435 | 3287 | if ( inst->ideal_only() ) continue; |
duke@435 | 3288 | if ( ! inst->is_simple_chain_rule(_globalNames) ) continue; |
duke@435 | 3289 | if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue; |
duke@435 | 3290 | |
duke@435 | 3291 | map.map(*inst); fprintf(fp_cpp, ", // %d\n", idx); |
duke@435 | 3292 | ++idx; |
duke@435 | 3293 | }; |
duke@435 | 3294 | map.record_position(OutputMap::END_INST_CHAIN_RULES, idx ); |
duke@435 | 3295 | } |
duke@435 | 3296 | // Output all instructions that are NOT simple chain rules |
duke@435 | 3297 | { |
duke@435 | 3298 | _instructions.reset(); |
duke@435 | 3299 | for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 3300 | // Ensure this is a machine-world instruction |
duke@435 | 3301 | if ( inst->ideal_only() ) continue; |
duke@435 | 3302 | if ( inst->is_simple_chain_rule(_globalNames) ) continue; |
duke@435 | 3303 | if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue; |
duke@435 | 3304 | |
duke@435 | 3305 | map.map(*inst); fprintf(fp_cpp, ", // %d\n", idx); |
duke@435 | 3306 | ++idx; |
duke@435 | 3307 | }; |
duke@435 | 3308 | map.record_position(OutputMap::END_REMATERIALIZE, idx ); |
duke@435 | 3309 | _instructions.reset(); |
duke@435 | 3310 | for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 3311 | // Ensure this is a machine-world instruction |
duke@435 | 3312 | if ( inst->ideal_only() ) continue; |
duke@435 | 3313 | if ( inst->is_simple_chain_rule(_globalNames) ) continue; |
duke@435 | 3314 | if ( inst->rematerialize(_globalNames, get_registers()) ) continue; |
duke@435 | 3315 | |
duke@435 | 3316 | map.map(*inst); fprintf(fp_cpp, ", // %d\n", idx); |
duke@435 | 3317 | ++idx; |
duke@435 | 3318 | }; |
duke@435 | 3319 | } |
duke@435 | 3320 | fprintf(fp_cpp, " // last instruction\n"); |
duke@435 | 3321 | map.record_position(OutputMap::END_INSTRUCTIONS, idx ); |
duke@435 | 3322 | } |
duke@435 | 3323 | // Finish defining table |
duke@435 | 3324 | map.closing(); |
duke@435 | 3325 | }; |
duke@435 | 3326 | |
duke@435 | 3327 | |
duke@435 | 3328 | // Helper function for buildReduceMaps |
duke@435 | 3329 | char reg_save_policy(const char *calling_convention) { |
duke@435 | 3330 | char callconv; |
duke@435 | 3331 | |
duke@435 | 3332 | if (!strcmp(calling_convention, "NS")) callconv = 'N'; |
duke@435 | 3333 | else if (!strcmp(calling_convention, "SOE")) callconv = 'E'; |
duke@435 | 3334 | else if (!strcmp(calling_convention, "SOC")) callconv = 'C'; |
duke@435 | 3335 | else if (!strcmp(calling_convention, "AS")) callconv = 'A'; |
duke@435 | 3336 | else callconv = 'Z'; |
duke@435 | 3337 | |
duke@435 | 3338 | return callconv; |
duke@435 | 3339 | } |
duke@435 | 3340 | |
duke@435 | 3341 | //---------------------------generate_assertion_checks------------------- |
duke@435 | 3342 | void ArchDesc::generate_adlc_verification(FILE *fp_cpp) { |
duke@435 | 3343 | fprintf(fp_cpp, "\n"); |
duke@435 | 3344 | |
duke@435 | 3345 | fprintf(fp_cpp, "#ifndef PRODUCT\n"); |
duke@435 | 3346 | fprintf(fp_cpp, "void Compile::adlc_verification() {\n"); |
duke@435 | 3347 | globalDefs().print_asserts(fp_cpp); |
duke@435 | 3348 | fprintf(fp_cpp, "}\n"); |
duke@435 | 3349 | fprintf(fp_cpp, "#endif\n"); |
duke@435 | 3350 | fprintf(fp_cpp, "\n"); |
duke@435 | 3351 | } |
duke@435 | 3352 | |
duke@435 | 3353 | //---------------------------addSourceBlocks----------------------------- |
duke@435 | 3354 | void ArchDesc::addSourceBlocks(FILE *fp_cpp) { |
duke@435 | 3355 | if (_source.count() > 0) |
duke@435 | 3356 | _source.output(fp_cpp); |
duke@435 | 3357 | |
duke@435 | 3358 | generate_adlc_verification(fp_cpp); |
duke@435 | 3359 | } |
duke@435 | 3360 | //---------------------------addHeaderBlocks----------------------------- |
duke@435 | 3361 | void ArchDesc::addHeaderBlocks(FILE *fp_hpp) { |
duke@435 | 3362 | if (_header.count() > 0) |
duke@435 | 3363 | _header.output(fp_hpp); |
duke@435 | 3364 | } |
duke@435 | 3365 | //-------------------------addPreHeaderBlocks---------------------------- |
duke@435 | 3366 | void ArchDesc::addPreHeaderBlocks(FILE *fp_hpp) { |
duke@435 | 3367 | // Output #defines from definition block |
duke@435 | 3368 | globalDefs().print_defines(fp_hpp); |
duke@435 | 3369 | |
duke@435 | 3370 | if (_pre_header.count() > 0) |
duke@435 | 3371 | _pre_header.output(fp_hpp); |
duke@435 | 3372 | } |
duke@435 | 3373 | |
duke@435 | 3374 | //---------------------------buildReduceMaps----------------------------- |
duke@435 | 3375 | // Build mapping from enumeration for densely packed operands |
duke@435 | 3376 | // TO result and child types. |
duke@435 | 3377 | void ArchDesc::buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp) { |
duke@435 | 3378 | RegDef *rdef; |
duke@435 | 3379 | RegDef *next; |
duke@435 | 3380 | |
duke@435 | 3381 | // The emit bodies currently require functions defined in the source block. |
duke@435 | 3382 | |
duke@435 | 3383 | // Build external declarations for mappings |
duke@435 | 3384 | fprintf(fp_hpp, "\n"); |
duke@435 | 3385 | fprintf(fp_hpp, "extern const char register_save_policy[];\n"); |
duke@435 | 3386 | fprintf(fp_hpp, "extern const char c_reg_save_policy[];\n"); |
duke@435 | 3387 | fprintf(fp_hpp, "extern const int register_save_type[];\n"); |
duke@435 | 3388 | fprintf(fp_hpp, "\n"); |
duke@435 | 3389 | |
duke@435 | 3390 | // Construct Save-Policy array |
duke@435 | 3391 | fprintf(fp_cpp, "// Map from machine-independent register number to register_save_policy\n"); |
duke@435 | 3392 | fprintf(fp_cpp, "const char register_save_policy[] = {\n"); |
duke@435 | 3393 | _register->reset_RegDefs(); |
duke@435 | 3394 | for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) { |
duke@435 | 3395 | next = _register->iter_RegDefs(); |
duke@435 | 3396 | char policy = reg_save_policy(rdef->_callconv); |
duke@435 | 3397 | const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
duke@435 | 3398 | fprintf(fp_cpp, " '%c'%s\n", policy, comma); |
duke@435 | 3399 | } |
duke@435 | 3400 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 3401 | |
duke@435 | 3402 | // Construct Native Save-Policy array |
duke@435 | 3403 | fprintf(fp_cpp, "// Map from machine-independent register number to c_reg_save_policy\n"); |
duke@435 | 3404 | fprintf(fp_cpp, "const char c_reg_save_policy[] = {\n"); |
duke@435 | 3405 | _register->reset_RegDefs(); |
duke@435 | 3406 | for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) { |
duke@435 | 3407 | next = _register->iter_RegDefs(); |
duke@435 | 3408 | char policy = reg_save_policy(rdef->_c_conv); |
duke@435 | 3409 | const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
duke@435 | 3410 | fprintf(fp_cpp, " '%c'%s\n", policy, comma); |
duke@435 | 3411 | } |
duke@435 | 3412 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 3413 | |
duke@435 | 3414 | // Construct Register Save Type array |
duke@435 | 3415 | fprintf(fp_cpp, "// Map from machine-independent register number to register_save_type\n"); |
duke@435 | 3416 | fprintf(fp_cpp, "const int register_save_type[] = {\n"); |
duke@435 | 3417 | _register->reset_RegDefs(); |
duke@435 | 3418 | for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) { |
duke@435 | 3419 | next = _register->iter_RegDefs(); |
duke@435 | 3420 | const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
duke@435 | 3421 | fprintf(fp_cpp, " %s%s\n", rdef->_idealtype, comma); |
duke@435 | 3422 | } |
duke@435 | 3423 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 3424 | |
duke@435 | 3425 | // Construct the table for reduceOp |
duke@435 | 3426 | OutputReduceOp output_reduce_op(fp_hpp, fp_cpp, _globalNames, *this); |
duke@435 | 3427 | build_map(output_reduce_op); |
duke@435 | 3428 | // Construct the table for leftOp |
duke@435 | 3429 | OutputLeftOp output_left_op(fp_hpp, fp_cpp, _globalNames, *this); |
duke@435 | 3430 | build_map(output_left_op); |
duke@435 | 3431 | // Construct the table for rightOp |
duke@435 | 3432 | OutputRightOp output_right_op(fp_hpp, fp_cpp, _globalNames, *this); |
duke@435 | 3433 | build_map(output_right_op); |
duke@435 | 3434 | // Construct the table of rule names |
duke@435 | 3435 | OutputRuleName output_rule_name(fp_hpp, fp_cpp, _globalNames, *this); |
duke@435 | 3436 | build_map(output_rule_name); |
duke@435 | 3437 | // Construct the boolean table for subsumed operands |
duke@435 | 3438 | OutputSwallowed output_swallowed(fp_hpp, fp_cpp, _globalNames, *this); |
duke@435 | 3439 | build_map(output_swallowed); |
duke@435 | 3440 | // // // Preserve in case we decide to use this table instead of another |
duke@435 | 3441 | //// Construct the boolean table for instruction chain rules |
duke@435 | 3442 | //OutputInstChainRule output_inst_chain(fp_hpp, fp_cpp, _globalNames, *this); |
duke@435 | 3443 | //build_map(output_inst_chain); |
duke@435 | 3444 | |
duke@435 | 3445 | } |
duke@435 | 3446 | |
duke@435 | 3447 | |
duke@435 | 3448 | //---------------------------buildMachOperGenerator--------------------------- |
duke@435 | 3449 | |
duke@435 | 3450 | // Recurse through match tree, building path through corresponding state tree, |
duke@435 | 3451 | // Until we reach the constant we are looking for. |
duke@435 | 3452 | static void path_to_constant(FILE *fp, FormDict &globals, |
duke@435 | 3453 | MatchNode *mnode, uint idx) { |
duke@435 | 3454 | if ( ! mnode) return; |
duke@435 | 3455 | |
duke@435 | 3456 | unsigned position = 0; |
duke@435 | 3457 | const char *result = NULL; |
duke@435 | 3458 | const char *name = NULL; |
duke@435 | 3459 | const char *optype = NULL; |
duke@435 | 3460 | |
duke@435 | 3461 | // Base Case: access constant in ideal node linked to current state node |
duke@435 | 3462 | // Each type of constant has its own access function |
duke@435 | 3463 | if ( (mnode->_lChild == NULL) && (mnode->_rChild == NULL) |
duke@435 | 3464 | && mnode->base_operand(position, globals, result, name, optype) ) { |
duke@435 | 3465 | if ( strcmp(optype,"ConI") == 0 ) { |
duke@435 | 3466 | fprintf(fp, "_leaf->get_int()"); |
duke@435 | 3467 | } else if ( (strcmp(optype,"ConP") == 0) ) { |
duke@435 | 3468 | fprintf(fp, "_leaf->bottom_type()->is_ptr()"); |
coleenp@548 | 3469 | } else if ( (strcmp(optype,"ConN") == 0) ) { |
coleenp@548 | 3470 | fprintf(fp, "_leaf->bottom_type()->is_narrowoop()"); |
duke@435 | 3471 | } else if ( (strcmp(optype,"ConF") == 0) ) { |
duke@435 | 3472 | fprintf(fp, "_leaf->getf()"); |
duke@435 | 3473 | } else if ( (strcmp(optype,"ConD") == 0) ) { |
duke@435 | 3474 | fprintf(fp, "_leaf->getd()"); |
duke@435 | 3475 | } else if ( (strcmp(optype,"ConL") == 0) ) { |
duke@435 | 3476 | fprintf(fp, "_leaf->get_long()"); |
duke@435 | 3477 | } else if ( (strcmp(optype,"Con")==0) ) { |
duke@435 | 3478 | // !!!!! - Update if adding a machine-independent constant type |
duke@435 | 3479 | fprintf(fp, "_leaf->get_int()"); |
duke@435 | 3480 | assert( false, "Unsupported constant type, pointer or indefinite"); |
duke@435 | 3481 | } else if ( (strcmp(optype,"Bool") == 0) ) { |
duke@435 | 3482 | fprintf(fp, "_leaf->as_Bool()->_test._test"); |
duke@435 | 3483 | } else { |
duke@435 | 3484 | assert( false, "Unsupported constant type"); |
duke@435 | 3485 | } |
duke@435 | 3486 | return; |
duke@435 | 3487 | } |
duke@435 | 3488 | |
duke@435 | 3489 | // If constant is in left child, build path and recurse |
duke@435 | 3490 | uint lConsts = (mnode->_lChild) ? (mnode->_lChild->num_consts(globals) ) : 0; |
duke@435 | 3491 | uint rConsts = (mnode->_rChild) ? (mnode->_rChild->num_consts(globals) ) : 0; |
duke@435 | 3492 | if ( (mnode->_lChild) && (lConsts > idx) ) { |
duke@435 | 3493 | fprintf(fp, "_kids[0]->"); |
duke@435 | 3494 | path_to_constant(fp, globals, mnode->_lChild, idx); |
duke@435 | 3495 | return; |
duke@435 | 3496 | } |
duke@435 | 3497 | // If constant is in right child, build path and recurse |
duke@435 | 3498 | if ( (mnode->_rChild) && (rConsts > (idx - lConsts) ) ) { |
duke@435 | 3499 | idx = idx - lConsts; |
duke@435 | 3500 | fprintf(fp, "_kids[1]->"); |
duke@435 | 3501 | path_to_constant(fp, globals, mnode->_rChild, idx); |
duke@435 | 3502 | return; |
duke@435 | 3503 | } |
duke@435 | 3504 | assert( false, "ShouldNotReachHere()"); |
duke@435 | 3505 | } |
duke@435 | 3506 | |
duke@435 | 3507 | // Generate code that is executed when generating a specific Machine Operand |
duke@435 | 3508 | static void genMachOperCase(FILE *fp, FormDict &globalNames, ArchDesc &AD, |
duke@435 | 3509 | OperandForm &op) { |
duke@435 | 3510 | const char *opName = op._ident; |
duke@435 | 3511 | const char *opEnumName = AD.machOperEnum(opName); |
duke@435 | 3512 | uint num_consts = op.num_consts(globalNames); |
duke@435 | 3513 | |
duke@435 | 3514 | // Generate the case statement for this opcode |
duke@435 | 3515 | fprintf(fp, " case %s:", opEnumName); |
duke@435 | 3516 | fprintf(fp, "\n return new (C) %sOper(", opName); |
duke@435 | 3517 | // Access parameters for constructor from the stat object |
duke@435 | 3518 | // |
duke@435 | 3519 | // Build access to condition code value |
duke@435 | 3520 | if ( (num_consts > 0) ) { |
duke@435 | 3521 | uint i = 0; |
duke@435 | 3522 | path_to_constant(fp, globalNames, op._matrule, i); |
duke@435 | 3523 | for ( i = 1; i < num_consts; ++i ) { |
duke@435 | 3524 | fprintf(fp, ", "); |
duke@435 | 3525 | path_to_constant(fp, globalNames, op._matrule, i); |
duke@435 | 3526 | } |
duke@435 | 3527 | } |
duke@435 | 3528 | fprintf(fp, " );\n"); |
duke@435 | 3529 | } |
duke@435 | 3530 | |
duke@435 | 3531 | |
duke@435 | 3532 | // Build switch to invoke "new" MachNode or MachOper |
duke@435 | 3533 | void ArchDesc::buildMachOperGenerator(FILE *fp_cpp) { |
duke@435 | 3534 | int idx = 0; |
duke@435 | 3535 | |
duke@435 | 3536 | // Build switch to invoke 'new' for a specific MachOper |
duke@435 | 3537 | fprintf(fp_cpp, "\n"); |
duke@435 | 3538 | fprintf(fp_cpp, "\n"); |
duke@435 | 3539 | fprintf(fp_cpp, |
duke@435 | 3540 | "//------------------------- MachOper Generator ---------------\n"); |
duke@435 | 3541 | fprintf(fp_cpp, |
duke@435 | 3542 | "// A switch statement on the dense-packed user-defined type system\n" |
duke@435 | 3543 | "// that invokes 'new' on the corresponding class constructor.\n"); |
duke@435 | 3544 | fprintf(fp_cpp, "\n"); |
duke@435 | 3545 | fprintf(fp_cpp, "MachOper *State::MachOperGenerator"); |
duke@435 | 3546 | fprintf(fp_cpp, "(int opcode, Compile* C)"); |
duke@435 | 3547 | fprintf(fp_cpp, "{\n"); |
duke@435 | 3548 | fprintf(fp_cpp, "\n"); |
duke@435 | 3549 | fprintf(fp_cpp, " switch(opcode) {\n"); |
duke@435 | 3550 | |
duke@435 | 3551 | // Place all user-defined operands into the mapping |
duke@435 | 3552 | _operands.reset(); |
duke@435 | 3553 | int opIndex = 0; |
duke@435 | 3554 | OperandForm *op; |
duke@435 | 3555 | for( ; (op = (OperandForm*)_operands.iter()) != NULL; ) { |
duke@435 | 3556 | // Ensure this is a machine-world instruction |
duke@435 | 3557 | if ( op->ideal_only() ) continue; |
duke@435 | 3558 | |
duke@435 | 3559 | genMachOperCase(fp_cpp, _globalNames, *this, *op); |
duke@435 | 3560 | }; |
duke@435 | 3561 | |
duke@435 | 3562 | // Do not iterate over operand classes for the operand generator!!! |
duke@435 | 3563 | |
duke@435 | 3564 | // Place all internal operands into the mapping |
duke@435 | 3565 | _internalOpNames.reset(); |
duke@435 | 3566 | const char *iopn; |
duke@435 | 3567 | for( ; (iopn = _internalOpNames.iter()) != NULL; ) { |
duke@435 | 3568 | const char *opEnumName = machOperEnum(iopn); |
duke@435 | 3569 | // Generate the case statement for this opcode |
duke@435 | 3570 | fprintf(fp_cpp, " case %s:", opEnumName); |
duke@435 | 3571 | fprintf(fp_cpp, " return NULL;\n"); |
duke@435 | 3572 | }; |
duke@435 | 3573 | |
duke@435 | 3574 | // Generate the default case for switch(opcode) |
duke@435 | 3575 | fprintf(fp_cpp, " \n"); |
duke@435 | 3576 | fprintf(fp_cpp, " default:\n"); |
duke@435 | 3577 | fprintf(fp_cpp, " fprintf(stderr, \"Default MachOper Generator invoked for: \\n\");\n"); |
duke@435 | 3578 | fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%'); |
duke@435 | 3579 | fprintf(fp_cpp, " break;\n"); |
duke@435 | 3580 | fprintf(fp_cpp, " }\n"); |
duke@435 | 3581 | |
duke@435 | 3582 | // Generate the closing for method Matcher::MachOperGenerator |
duke@435 | 3583 | fprintf(fp_cpp, " return NULL;\n"); |
duke@435 | 3584 | fprintf(fp_cpp, "};\n"); |
duke@435 | 3585 | } |
duke@435 | 3586 | |
duke@435 | 3587 | |
duke@435 | 3588 | //---------------------------buildMachNode------------------------------------- |
duke@435 | 3589 | // Build a new MachNode, for MachNodeGenerator or cisc-spilling |
duke@435 | 3590 | void ArchDesc::buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent) { |
duke@435 | 3591 | const char *opType = NULL; |
duke@435 | 3592 | const char *opClass = inst->_ident; |
duke@435 | 3593 | |
duke@435 | 3594 | // Create the MachNode object |
duke@435 | 3595 | fprintf(fp_cpp, "%s %sNode *node = new (C) %sNode();\n",indent, opClass,opClass); |
duke@435 | 3596 | |
duke@435 | 3597 | if ( (inst->num_post_match_opnds() != 0) ) { |
duke@435 | 3598 | // Instruction that contains operands which are not in match rule. |
duke@435 | 3599 | // |
duke@435 | 3600 | // Check if the first post-match component may be an interesting def |
duke@435 | 3601 | bool dont_care = false; |
duke@435 | 3602 | ComponentList &comp_list = inst->_components; |
duke@435 | 3603 | Component *comp = NULL; |
duke@435 | 3604 | comp_list.reset(); |
duke@435 | 3605 | if ( comp_list.match_iter() != NULL ) dont_care = true; |
duke@435 | 3606 | |
duke@435 | 3607 | // Insert operands that are not in match-rule. |
duke@435 | 3608 | // Only insert a DEF if the do_care flag is set |
duke@435 | 3609 | comp_list.reset(); |
duke@435 | 3610 | while ( comp = comp_list.post_match_iter() ) { |
duke@435 | 3611 | // Check if we don't care about DEFs or KILLs that are not USEs |
duke@435 | 3612 | if ( dont_care && (! comp->isa(Component::USE)) ) { |
duke@435 | 3613 | continue; |
duke@435 | 3614 | } |
duke@435 | 3615 | dont_care = true; |
duke@435 | 3616 | // For each operand not in the match rule, call MachOperGenerator |
duke@435 | 3617 | // with the enum for the opcode that needs to be built |
duke@435 | 3618 | // and the node just built, the parent of the operand. |
duke@435 | 3619 | ComponentList clist = inst->_components; |
duke@435 | 3620 | int index = clist.operand_position(comp->_name, comp->_usedef); |
duke@435 | 3621 | const char *opcode = machOperEnum(comp->_type); |
duke@435 | 3622 | const char *parent = "node"; |
duke@435 | 3623 | fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index); |
duke@435 | 3624 | fprintf(fp_cpp, "MachOperGenerator(%s, C));\n", opcode); |
duke@435 | 3625 | } |
duke@435 | 3626 | } |
duke@435 | 3627 | else if ( inst->is_chain_of_constant(_globalNames, opType) ) { |
duke@435 | 3628 | // An instruction that chains from a constant! |
duke@435 | 3629 | // In this case, we need to subsume the constant into the node |
duke@435 | 3630 | // at operand position, oper_input_base(). |
duke@435 | 3631 | // |
duke@435 | 3632 | // Fill in the constant |
duke@435 | 3633 | fprintf(fp_cpp, "%s node->_opnd_array[%d] = ", indent, |
duke@435 | 3634 | inst->oper_input_base(_globalNames)); |
duke@435 | 3635 | // ##### |
duke@435 | 3636 | // Check for multiple constants and then fill them in. |
duke@435 | 3637 | // Just like MachOperGenerator |
duke@435 | 3638 | const char *opName = inst->_matrule->_rChild->_opType; |
duke@435 | 3639 | fprintf(fp_cpp, "new (C) %sOper(", opName); |
duke@435 | 3640 | // Grab operand form |
duke@435 | 3641 | OperandForm *op = (_globalNames[opName])->is_operand(); |
duke@435 | 3642 | // Look up the number of constants |
duke@435 | 3643 | uint num_consts = op->num_consts(_globalNames); |
duke@435 | 3644 | if ( (num_consts > 0) ) { |
duke@435 | 3645 | uint i = 0; |
duke@435 | 3646 | path_to_constant(fp_cpp, _globalNames, op->_matrule, i); |
duke@435 | 3647 | for ( i = 1; i < num_consts; ++i ) { |
duke@435 | 3648 | fprintf(fp_cpp, ", "); |
duke@435 | 3649 | path_to_constant(fp_cpp, _globalNames, op->_matrule, i); |
duke@435 | 3650 | } |
duke@435 | 3651 | } |
duke@435 | 3652 | fprintf(fp_cpp, " );\n"); |
duke@435 | 3653 | // ##### |
duke@435 | 3654 | } |
duke@435 | 3655 | |
duke@435 | 3656 | // Fill in the bottom_type where requested |
duke@435 | 3657 | if ( inst->captures_bottom_type() ) { |
duke@435 | 3658 | fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent); |
duke@435 | 3659 | } |
duke@435 | 3660 | if( inst->is_ideal_if() ) { |
duke@435 | 3661 | fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent); |
duke@435 | 3662 | fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent); |
duke@435 | 3663 | } |
duke@435 | 3664 | if( inst->is_ideal_fastlock() ) { |
duke@435 | 3665 | fprintf(fp_cpp, "%s node->_counters = _leaf->as_FastLock()->counters();\n", indent); |
duke@435 | 3666 | } |
duke@435 | 3667 | |
duke@435 | 3668 | } |
duke@435 | 3669 | |
duke@435 | 3670 | //---------------------------declare_cisc_version------------------------------ |
duke@435 | 3671 | // Build CISC version of this instruction |
duke@435 | 3672 | void InstructForm::declare_cisc_version(ArchDesc &AD, FILE *fp_hpp) { |
duke@435 | 3673 | if( AD.can_cisc_spill() ) { |
duke@435 | 3674 | InstructForm *inst_cisc = cisc_spill_alternate(); |
duke@435 | 3675 | if (inst_cisc != NULL) { |
duke@435 | 3676 | fprintf(fp_hpp, " virtual int cisc_operand() const { return %d; }\n", cisc_spill_operand()); |
duke@435 | 3677 | fprintf(fp_hpp, " virtual MachNode *cisc_version(int offset, Compile* C);\n"); |
duke@435 | 3678 | fprintf(fp_hpp, " virtual void use_cisc_RegMask();\n"); |
duke@435 | 3679 | fprintf(fp_hpp, " virtual const RegMask *cisc_RegMask() const { return _cisc_RegMask; }\n"); |
duke@435 | 3680 | } |
duke@435 | 3681 | } |
duke@435 | 3682 | } |
duke@435 | 3683 | |
duke@435 | 3684 | //---------------------------define_cisc_version------------------------------- |
duke@435 | 3685 | // Build CISC version of this instruction |
duke@435 | 3686 | bool InstructForm::define_cisc_version(ArchDesc &AD, FILE *fp_cpp) { |
duke@435 | 3687 | InstructForm *inst_cisc = this->cisc_spill_alternate(); |
duke@435 | 3688 | if( AD.can_cisc_spill() && (inst_cisc != NULL) ) { |
duke@435 | 3689 | const char *name = inst_cisc->_ident; |
duke@435 | 3690 | assert( inst_cisc->num_opnds() == this->num_opnds(), "Must have same number of operands"); |
duke@435 | 3691 | OperandForm *cisc_oper = AD.cisc_spill_operand(); |
duke@435 | 3692 | assert( cisc_oper != NULL, "insanity check"); |
duke@435 | 3693 | const char *cisc_oper_name = cisc_oper->_ident; |
duke@435 | 3694 | assert( cisc_oper_name != NULL, "insanity check"); |
duke@435 | 3695 | // |
duke@435 | 3696 | // Set the correct reg_mask_or_stack for the cisc operand |
duke@435 | 3697 | fprintf(fp_cpp, "\n"); |
duke@435 | 3698 | fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident); |
duke@435 | 3699 | // Lookup the correct reg_mask_or_stack |
duke@435 | 3700 | const char *reg_mask_name = cisc_reg_mask_name(); |
duke@435 | 3701 | fprintf(fp_cpp, " _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name); |
duke@435 | 3702 | fprintf(fp_cpp, "}\n"); |
duke@435 | 3703 | // |
duke@435 | 3704 | // Construct CISC version of this instruction |
duke@435 | 3705 | fprintf(fp_cpp, "\n"); |
duke@435 | 3706 | fprintf(fp_cpp, "// Build CISC version of this instruction\n"); |
duke@435 | 3707 | fprintf(fp_cpp, "MachNode *%sNode::cisc_version( int offset, Compile* C ) {\n", this->_ident); |
duke@435 | 3708 | // Create the MachNode object |
duke@435 | 3709 | fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name); |
duke@435 | 3710 | // Fill in the bottom_type where requested |
duke@435 | 3711 | if ( this->captures_bottom_type() ) { |
duke@435 | 3712 | fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n"); |
duke@435 | 3713 | } |
duke@435 | 3714 | fprintf(fp_cpp, "\n"); |
duke@435 | 3715 | fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n"); |
duke@435 | 3716 | fprintf(fp_cpp, " fill_new_machnode(node, C);\n"); |
duke@435 | 3717 | // Construct operand to access [stack_pointer + offset] |
duke@435 | 3718 | fprintf(fp_cpp, " // Construct operand to access [stack_pointer + offset]\n"); |
duke@435 | 3719 | fprintf(fp_cpp, " node->set_opnd_array(cisc_operand(), new (C) %sOper(offset));\n", cisc_oper_name); |
duke@435 | 3720 | fprintf(fp_cpp, "\n"); |
duke@435 | 3721 | |
duke@435 | 3722 | // Return result and exit scope |
duke@435 | 3723 | fprintf(fp_cpp, " return node;\n"); |
duke@435 | 3724 | fprintf(fp_cpp, "}\n"); |
duke@435 | 3725 | fprintf(fp_cpp, "\n"); |
duke@435 | 3726 | return true; |
duke@435 | 3727 | } |
duke@435 | 3728 | return false; |
duke@435 | 3729 | } |
duke@435 | 3730 | |
duke@435 | 3731 | //---------------------------declare_short_branch_methods---------------------- |
duke@435 | 3732 | // Build prototypes for short branch methods |
duke@435 | 3733 | void InstructForm::declare_short_branch_methods(FILE *fp_hpp) { |
duke@435 | 3734 | if (has_short_branch_form()) { |
duke@435 | 3735 | fprintf(fp_hpp, " virtual MachNode *short_branch_version(Compile* C);\n"); |
duke@435 | 3736 | } |
duke@435 | 3737 | } |
duke@435 | 3738 | |
duke@435 | 3739 | //---------------------------define_short_branch_methods----------------------- |
duke@435 | 3740 | // Build definitions for short branch methods |
duke@435 | 3741 | bool InstructForm::define_short_branch_methods(FILE *fp_cpp) { |
duke@435 | 3742 | if (has_short_branch_form()) { |
duke@435 | 3743 | InstructForm *short_branch = short_branch_form(); |
duke@435 | 3744 | const char *name = short_branch->_ident; |
duke@435 | 3745 | |
duke@435 | 3746 | // Construct short_branch_version() method. |
duke@435 | 3747 | fprintf(fp_cpp, "// Build short branch version of this instruction\n"); |
duke@435 | 3748 | fprintf(fp_cpp, "MachNode *%sNode::short_branch_version(Compile* C) {\n", this->_ident); |
duke@435 | 3749 | // Create the MachNode object |
duke@435 | 3750 | fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name); |
duke@435 | 3751 | if( is_ideal_if() ) { |
duke@435 | 3752 | fprintf(fp_cpp, " node->_prob = _prob;\n"); |
duke@435 | 3753 | fprintf(fp_cpp, " node->_fcnt = _fcnt;\n"); |
duke@435 | 3754 | } |
duke@435 | 3755 | // Fill in the bottom_type where requested |
duke@435 | 3756 | if ( this->captures_bottom_type() ) { |
duke@435 | 3757 | fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n"); |
duke@435 | 3758 | } |
duke@435 | 3759 | |
duke@435 | 3760 | fprintf(fp_cpp, "\n"); |
duke@435 | 3761 | // Short branch version must use same node index for access |
duke@435 | 3762 | // through allocator's tables |
duke@435 | 3763 | fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n"); |
duke@435 | 3764 | fprintf(fp_cpp, " fill_new_machnode(node, C);\n"); |
duke@435 | 3765 | |
duke@435 | 3766 | // Return result and exit scope |
duke@435 | 3767 | fprintf(fp_cpp, " return node;\n"); |
duke@435 | 3768 | fprintf(fp_cpp, "}\n"); |
duke@435 | 3769 | fprintf(fp_cpp,"\n"); |
duke@435 | 3770 | return true; |
duke@435 | 3771 | } |
duke@435 | 3772 | return false; |
duke@435 | 3773 | } |
duke@435 | 3774 | |
duke@435 | 3775 | |
duke@435 | 3776 | //---------------------------buildMachNodeGenerator---------------------------- |
duke@435 | 3777 | // Build switch to invoke appropriate "new" MachNode for an opcode |
duke@435 | 3778 | void ArchDesc::buildMachNodeGenerator(FILE *fp_cpp) { |
duke@435 | 3779 | |
duke@435 | 3780 | // Build switch to invoke 'new' for a specific MachNode |
duke@435 | 3781 | fprintf(fp_cpp, "\n"); |
duke@435 | 3782 | fprintf(fp_cpp, "\n"); |
duke@435 | 3783 | fprintf(fp_cpp, |
duke@435 | 3784 | "//------------------------- MachNode Generator ---------------\n"); |
duke@435 | 3785 | fprintf(fp_cpp, |
duke@435 | 3786 | "// A switch statement on the dense-packed user-defined type system\n" |
duke@435 | 3787 | "// that invokes 'new' on the corresponding class constructor.\n"); |
duke@435 | 3788 | fprintf(fp_cpp, "\n"); |
duke@435 | 3789 | fprintf(fp_cpp, "MachNode *State::MachNodeGenerator"); |
duke@435 | 3790 | fprintf(fp_cpp, "(int opcode, Compile* C)"); |
duke@435 | 3791 | fprintf(fp_cpp, "{\n"); |
duke@435 | 3792 | fprintf(fp_cpp, " switch(opcode) {\n"); |
duke@435 | 3793 | |
duke@435 | 3794 | // Provide constructor for all user-defined instructions |
duke@435 | 3795 | _instructions.reset(); |
duke@435 | 3796 | int opIndex = operandFormCount(); |
duke@435 | 3797 | InstructForm *inst; |
duke@435 | 3798 | for( ; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 3799 | // Ensure that matrule is defined. |
duke@435 | 3800 | if ( inst->_matrule == NULL ) continue; |
duke@435 | 3801 | |
duke@435 | 3802 | int opcode = opIndex++; |
duke@435 | 3803 | const char *opClass = inst->_ident; |
duke@435 | 3804 | char *opType = NULL; |
duke@435 | 3805 | |
duke@435 | 3806 | // Generate the case statement for this instruction |
duke@435 | 3807 | fprintf(fp_cpp, " case %s_rule:", opClass); |
duke@435 | 3808 | |
duke@435 | 3809 | // Start local scope |
duke@435 | 3810 | fprintf(fp_cpp, " {\n"); |
duke@435 | 3811 | // Generate code to construct the new MachNode |
duke@435 | 3812 | buildMachNode(fp_cpp, inst, " "); |
duke@435 | 3813 | // Return result and exit scope |
duke@435 | 3814 | fprintf(fp_cpp, " return node;\n"); |
duke@435 | 3815 | fprintf(fp_cpp, " }\n"); |
duke@435 | 3816 | } |
duke@435 | 3817 | |
duke@435 | 3818 | // Generate the default case for switch(opcode) |
duke@435 | 3819 | fprintf(fp_cpp, " \n"); |
duke@435 | 3820 | fprintf(fp_cpp, " default:\n"); |
duke@435 | 3821 | fprintf(fp_cpp, " fprintf(stderr, \"Default MachNode Generator invoked for: \\n\");\n"); |
duke@435 | 3822 | fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%'); |
duke@435 | 3823 | fprintf(fp_cpp, " break;\n"); |
duke@435 | 3824 | fprintf(fp_cpp, " };\n"); |
duke@435 | 3825 | |
duke@435 | 3826 | // Generate the closing for method Matcher::MachNodeGenerator |
duke@435 | 3827 | fprintf(fp_cpp, " return NULL;\n"); |
duke@435 | 3828 | fprintf(fp_cpp, "}\n"); |
duke@435 | 3829 | } |
duke@435 | 3830 | |
duke@435 | 3831 | |
duke@435 | 3832 | //---------------------------buildInstructMatchCheck-------------------------- |
duke@435 | 3833 | // Output the method to Matcher which checks whether or not a specific |
duke@435 | 3834 | // instruction has a matching rule for the host architecture. |
duke@435 | 3835 | void ArchDesc::buildInstructMatchCheck(FILE *fp_cpp) const { |
duke@435 | 3836 | fprintf(fp_cpp, "\n\n"); |
duke@435 | 3837 | fprintf(fp_cpp, "const bool Matcher::has_match_rule(int opcode) {\n"); |
duke@435 | 3838 | fprintf(fp_cpp, " assert(_last_machine_leaf < opcode && opcode < _last_opcode, \"opcode in range\");\n"); |
duke@435 | 3839 | fprintf(fp_cpp, " return _hasMatchRule[opcode];\n"); |
duke@435 | 3840 | fprintf(fp_cpp, "}\n\n"); |
duke@435 | 3841 | |
duke@435 | 3842 | fprintf(fp_cpp, "const bool Matcher::_hasMatchRule[_last_opcode] = {\n"); |
duke@435 | 3843 | int i; |
duke@435 | 3844 | for (i = 0; i < _last_opcode - 1; i++) { |
duke@435 | 3845 | fprintf(fp_cpp, " %-5s, // %s\n", |
duke@435 | 3846 | _has_match_rule[i] ? "true" : "false", |
duke@435 | 3847 | NodeClassNames[i]); |
duke@435 | 3848 | } |
duke@435 | 3849 | fprintf(fp_cpp, " %-5s // %s\n", |
duke@435 | 3850 | _has_match_rule[i] ? "true" : "false", |
duke@435 | 3851 | NodeClassNames[i]); |
duke@435 | 3852 | fprintf(fp_cpp, "};\n"); |
duke@435 | 3853 | } |
duke@435 | 3854 | |
duke@435 | 3855 | //---------------------------buildFrameMethods--------------------------------- |
duke@435 | 3856 | // Output the methods to Matcher which specify frame behavior |
duke@435 | 3857 | void ArchDesc::buildFrameMethods(FILE *fp_cpp) { |
duke@435 | 3858 | fprintf(fp_cpp,"\n\n"); |
duke@435 | 3859 | // Stack Direction |
duke@435 | 3860 | fprintf(fp_cpp,"bool Matcher::stack_direction() const { return %s; }\n\n", |
duke@435 | 3861 | _frame->_direction ? "true" : "false"); |
duke@435 | 3862 | // Sync Stack Slots |
duke@435 | 3863 | fprintf(fp_cpp,"int Compile::sync_stack_slots() const { return %s; }\n\n", |
duke@435 | 3864 | _frame->_sync_stack_slots); |
duke@435 | 3865 | // Java Stack Alignment |
duke@435 | 3866 | fprintf(fp_cpp,"uint Matcher::stack_alignment_in_bytes() { return %s; }\n\n", |
duke@435 | 3867 | _frame->_alignment); |
duke@435 | 3868 | // Java Return Address Location |
duke@435 | 3869 | fprintf(fp_cpp,"OptoReg::Name Matcher::return_addr() const {"); |
duke@435 | 3870 | if (_frame->_return_addr_loc) { |
duke@435 | 3871 | fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", |
duke@435 | 3872 | _frame->_return_addr); |
duke@435 | 3873 | } |
duke@435 | 3874 | else { |
duke@435 | 3875 | fprintf(fp_cpp," return OptoReg::stack2reg(%s); }\n\n", |
duke@435 | 3876 | _frame->_return_addr); |
duke@435 | 3877 | } |
duke@435 | 3878 | // Java Stack Slot Preservation |
duke@435 | 3879 | fprintf(fp_cpp,"uint Compile::in_preserve_stack_slots() "); |
duke@435 | 3880 | fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_in_preserve_slots); |
duke@435 | 3881 | // Top Of Stack Slot Preservation, for both Java and C |
duke@435 | 3882 | fprintf(fp_cpp,"uint Compile::out_preserve_stack_slots() "); |
duke@435 | 3883 | fprintf(fp_cpp,"{ return SharedRuntime::out_preserve_stack_slots(); }\n\n"); |
duke@435 | 3884 | // varargs C out slots killed |
duke@435 | 3885 | fprintf(fp_cpp,"uint Compile::varargs_C_out_slots_killed() const "); |
duke@435 | 3886 | fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_varargs_C_out_slots_killed); |
duke@435 | 3887 | // Java Argument Position |
duke@435 | 3888 | fprintf(fp_cpp,"void Matcher::calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length, bool is_outgoing) {\n"); |
duke@435 | 3889 | fprintf(fp_cpp,"%s\n", _frame->_calling_convention); |
duke@435 | 3890 | fprintf(fp_cpp,"}\n\n"); |
duke@435 | 3891 | // Native Argument Position |
duke@435 | 3892 | fprintf(fp_cpp,"void Matcher::c_calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length) {\n"); |
duke@435 | 3893 | fprintf(fp_cpp,"%s\n", _frame->_c_calling_convention); |
duke@435 | 3894 | fprintf(fp_cpp,"}\n\n"); |
duke@435 | 3895 | // Java Return Value Location |
duke@435 | 3896 | fprintf(fp_cpp,"OptoRegPair Matcher::return_value(int ideal_reg, bool is_outgoing) {\n"); |
duke@435 | 3897 | fprintf(fp_cpp,"%s\n", _frame->_return_value); |
duke@435 | 3898 | fprintf(fp_cpp,"}\n\n"); |
duke@435 | 3899 | // Native Return Value Location |
duke@435 | 3900 | fprintf(fp_cpp,"OptoRegPair Matcher::c_return_value(int ideal_reg, bool is_outgoing) {\n"); |
duke@435 | 3901 | fprintf(fp_cpp,"%s\n", _frame->_c_return_value); |
duke@435 | 3902 | fprintf(fp_cpp,"}\n\n"); |
duke@435 | 3903 | |
duke@435 | 3904 | // Inline Cache Register, mask definition, and encoding |
duke@435 | 3905 | fprintf(fp_cpp,"OptoReg::Name Matcher::inline_cache_reg() {"); |
duke@435 | 3906 | fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", |
duke@435 | 3907 | _frame->_inline_cache_reg); |
duke@435 | 3908 | fprintf(fp_cpp,"const RegMask &Matcher::inline_cache_reg_mask() {"); |
duke@435 | 3909 | fprintf(fp_cpp," return INLINE_CACHE_REG_mask; }\n\n"); |
duke@435 | 3910 | fprintf(fp_cpp,"int Matcher::inline_cache_reg_encode() {"); |
duke@435 | 3911 | fprintf(fp_cpp," return _regEncode[inline_cache_reg()]; }\n\n"); |
duke@435 | 3912 | |
duke@435 | 3913 | // Interpreter's Method Oop Register, mask definition, and encoding |
duke@435 | 3914 | fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_method_oop_reg() {"); |
duke@435 | 3915 | fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", |
duke@435 | 3916 | _frame->_interpreter_method_oop_reg); |
duke@435 | 3917 | fprintf(fp_cpp,"const RegMask &Matcher::interpreter_method_oop_reg_mask() {"); |
duke@435 | 3918 | fprintf(fp_cpp," return INTERPRETER_METHOD_OOP_REG_mask; }\n\n"); |
duke@435 | 3919 | fprintf(fp_cpp,"int Matcher::interpreter_method_oop_reg_encode() {"); |
duke@435 | 3920 | fprintf(fp_cpp," return _regEncode[interpreter_method_oop_reg()]; }\n\n"); |
duke@435 | 3921 | |
duke@435 | 3922 | // Interpreter's Frame Pointer Register, mask definition, and encoding |
duke@435 | 3923 | fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_frame_pointer_reg() {"); |
duke@435 | 3924 | if (_frame->_interpreter_frame_pointer_reg == NULL) |
duke@435 | 3925 | fprintf(fp_cpp," return OptoReg::Bad; }\n\n"); |
duke@435 | 3926 | else |
duke@435 | 3927 | fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", |
duke@435 | 3928 | _frame->_interpreter_frame_pointer_reg); |
duke@435 | 3929 | fprintf(fp_cpp,"const RegMask &Matcher::interpreter_frame_pointer_reg_mask() {"); |
duke@435 | 3930 | if (_frame->_interpreter_frame_pointer_reg == NULL) |
duke@435 | 3931 | fprintf(fp_cpp," static RegMask dummy; return dummy; }\n\n"); |
duke@435 | 3932 | else |
duke@435 | 3933 | fprintf(fp_cpp," return INTERPRETER_FRAME_POINTER_REG_mask; }\n\n"); |
duke@435 | 3934 | |
duke@435 | 3935 | // Frame Pointer definition |
duke@435 | 3936 | /* CNC - I can not contemplate having a different frame pointer between |
duke@435 | 3937 | Java and native code; makes my head hurt to think about it. |
duke@435 | 3938 | fprintf(fp_cpp,"OptoReg::Name Matcher::frame_pointer() const {"); |
duke@435 | 3939 | fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", |
duke@435 | 3940 | _frame->_frame_pointer); |
duke@435 | 3941 | */ |
duke@435 | 3942 | // (Native) Frame Pointer definition |
duke@435 | 3943 | fprintf(fp_cpp,"OptoReg::Name Matcher::c_frame_pointer() const {"); |
duke@435 | 3944 | fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n", |
duke@435 | 3945 | _frame->_frame_pointer); |
duke@435 | 3946 | |
duke@435 | 3947 | // Number of callee-save + always-save registers for calling convention |
duke@435 | 3948 | fprintf(fp_cpp, "// Number of callee-save + always-save registers\n"); |
duke@435 | 3949 | fprintf(fp_cpp, "int Matcher::number_of_saved_registers() {\n"); |
duke@435 | 3950 | RegDef *rdef; |
duke@435 | 3951 | int nof_saved_registers = 0; |
duke@435 | 3952 | _register->reset_RegDefs(); |
duke@435 | 3953 | while( (rdef = _register->iter_RegDefs()) != NULL ) { |
duke@435 | 3954 | if( !strcmp(rdef->_callconv, "SOE") || !strcmp(rdef->_callconv, "AS") ) |
duke@435 | 3955 | ++nof_saved_registers; |
duke@435 | 3956 | } |
duke@435 | 3957 | fprintf(fp_cpp, " return %d;\n", nof_saved_registers); |
duke@435 | 3958 | fprintf(fp_cpp, "};\n\n"); |
duke@435 | 3959 | } |
duke@435 | 3960 | |
duke@435 | 3961 | |
duke@435 | 3962 | |
duke@435 | 3963 | |
duke@435 | 3964 | static int PrintAdlcCisc = 0; |
duke@435 | 3965 | //---------------------------identify_cisc_spilling---------------------------- |
duke@435 | 3966 | // Get info for the CISC_oracle and MachNode::cisc_version() |
duke@435 | 3967 | void ArchDesc::identify_cisc_spill_instructions() { |
duke@435 | 3968 | |
duke@435 | 3969 | // Find the user-defined operand for cisc-spilling |
duke@435 | 3970 | if( _frame->_cisc_spilling_operand_name != NULL ) { |
duke@435 | 3971 | const Form *form = _globalNames[_frame->_cisc_spilling_operand_name]; |
duke@435 | 3972 | OperandForm *oper = form ? form->is_operand() : NULL; |
duke@435 | 3973 | // Verify the user's suggestion |
duke@435 | 3974 | if( oper != NULL ) { |
duke@435 | 3975 | // Ensure that match field is defined. |
duke@435 | 3976 | if ( oper->_matrule != NULL ) { |
duke@435 | 3977 | MatchRule &mrule = *oper->_matrule; |
duke@435 | 3978 | if( strcmp(mrule._opType,"AddP") == 0 ) { |
duke@435 | 3979 | MatchNode *left = mrule._lChild; |
duke@435 | 3980 | MatchNode *right= mrule._rChild; |
duke@435 | 3981 | if( left != NULL && right != NULL ) { |
duke@435 | 3982 | const Form *left_op = _globalNames[left->_opType]->is_operand(); |
duke@435 | 3983 | const Form *right_op = _globalNames[right->_opType]->is_operand(); |
duke@435 | 3984 | if( (left_op != NULL && right_op != NULL) |
duke@435 | 3985 | && (left_op->interface_type(_globalNames) == Form::register_interface) |
duke@435 | 3986 | && (right_op->interface_type(_globalNames) == Form::constant_interface) ) { |
duke@435 | 3987 | // Successfully verified operand |
duke@435 | 3988 | set_cisc_spill_operand( oper ); |
duke@435 | 3989 | if( _cisc_spill_debug ) { |
duke@435 | 3990 | fprintf(stderr, "\n\nVerified CISC-spill operand %s\n\n", oper->_ident); |
duke@435 | 3991 | } |
duke@435 | 3992 | } |
duke@435 | 3993 | } |
duke@435 | 3994 | } |
duke@435 | 3995 | } |
duke@435 | 3996 | } |
duke@435 | 3997 | } |
duke@435 | 3998 | |
duke@435 | 3999 | if( cisc_spill_operand() != NULL ) { |
duke@435 | 4000 | // N^2 comparison of instructions looking for a cisc-spilling version |
duke@435 | 4001 | _instructions.reset(); |
duke@435 | 4002 | InstructForm *instr; |
duke@435 | 4003 | for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 4004 | // Ensure that match field is defined. |
duke@435 | 4005 | if ( instr->_matrule == NULL ) continue; |
duke@435 | 4006 | |
duke@435 | 4007 | MatchRule &mrule = *instr->_matrule; |
duke@435 | 4008 | Predicate *pred = instr->build_predicate(); |
duke@435 | 4009 | |
duke@435 | 4010 | // Grab the machine type of the operand |
duke@435 | 4011 | const char *rootOp = instr->_ident; |
duke@435 | 4012 | mrule._machType = rootOp; |
duke@435 | 4013 | |
duke@435 | 4014 | // Find result type for match |
duke@435 | 4015 | const char *result = instr->reduce_result(); |
duke@435 | 4016 | |
duke@435 | 4017 | if( PrintAdlcCisc ) fprintf(stderr, " new instruction %s \n", instr->_ident ? instr->_ident : " "); |
duke@435 | 4018 | bool found_cisc_alternate = false; |
duke@435 | 4019 | _instructions.reset2(); |
duke@435 | 4020 | InstructForm *instr2; |
duke@435 | 4021 | for( ; !found_cisc_alternate && (instr2 = (InstructForm*)_instructions.iter2()) != NULL; ) { |
duke@435 | 4022 | // Ensure that match field is defined. |
duke@435 | 4023 | if( PrintAdlcCisc ) fprintf(stderr, " instr2 == %s \n", instr2->_ident ? instr2->_ident : " "); |
duke@435 | 4024 | if ( instr2->_matrule != NULL |
duke@435 | 4025 | && (instr != instr2 ) // Skip self |
duke@435 | 4026 | && (instr2->reduce_result() != NULL) // want same result |
duke@435 | 4027 | && (strcmp(result, instr2->reduce_result()) == 0)) { |
duke@435 | 4028 | MatchRule &mrule2 = *instr2->_matrule; |
duke@435 | 4029 | Predicate *pred2 = instr2->build_predicate(); |
duke@435 | 4030 | found_cisc_alternate = instr->cisc_spills_to(*this, instr2); |
duke@435 | 4031 | } |
duke@435 | 4032 | } |
duke@435 | 4033 | } |
duke@435 | 4034 | } |
duke@435 | 4035 | } |
duke@435 | 4036 | |
duke@435 | 4037 | //---------------------------build_cisc_spilling------------------------------- |
duke@435 | 4038 | // Get info for the CISC_oracle and MachNode::cisc_version() |
duke@435 | 4039 | void ArchDesc::build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp) { |
duke@435 | 4040 | // Output the table for cisc spilling |
duke@435 | 4041 | fprintf(fp_cpp, "// The following instructions can cisc-spill\n"); |
duke@435 | 4042 | _instructions.reset(); |
duke@435 | 4043 | InstructForm *inst = NULL; |
duke@435 | 4044 | for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 4045 | // Ensure this is a machine-world instruction |
duke@435 | 4046 | if ( inst->ideal_only() ) continue; |
duke@435 | 4047 | const char *inst_name = inst->_ident; |
duke@435 | 4048 | int operand = inst->cisc_spill_operand(); |
duke@435 | 4049 | if( operand != AdlcVMDeps::Not_cisc_spillable ) { |
duke@435 | 4050 | InstructForm *inst2 = inst->cisc_spill_alternate(); |
duke@435 | 4051 | fprintf(fp_cpp, "// %s can cisc-spill operand %d to %s\n", inst->_ident, operand, inst2->_ident); |
duke@435 | 4052 | } |
duke@435 | 4053 | } |
duke@435 | 4054 | fprintf(fp_cpp, "\n\n"); |
duke@435 | 4055 | } |
duke@435 | 4056 | |
duke@435 | 4057 | //---------------------------identify_short_branches---------------------------- |
duke@435 | 4058 | // Get info for our short branch replacement oracle. |
duke@435 | 4059 | void ArchDesc::identify_short_branches() { |
duke@435 | 4060 | // Walk over all instructions, checking to see if they match a short |
duke@435 | 4061 | // branching alternate. |
duke@435 | 4062 | _instructions.reset(); |
duke@435 | 4063 | InstructForm *instr; |
duke@435 | 4064 | while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { |
duke@435 | 4065 | // The instruction must have a match rule. |
duke@435 | 4066 | if (instr->_matrule != NULL && |
duke@435 | 4067 | instr->is_short_branch()) { |
duke@435 | 4068 | |
duke@435 | 4069 | _instructions.reset2(); |
duke@435 | 4070 | InstructForm *instr2; |
duke@435 | 4071 | while( (instr2 = (InstructForm*)_instructions.iter2()) != NULL ) { |
duke@435 | 4072 | instr2->check_branch_variant(*this, instr); |
duke@435 | 4073 | } |
duke@435 | 4074 | } |
duke@435 | 4075 | } |
duke@435 | 4076 | } |
duke@435 | 4077 | |
duke@435 | 4078 | |
duke@435 | 4079 | //---------------------------identify_unique_operands--------------------------- |
duke@435 | 4080 | // Identify unique operands. |
duke@435 | 4081 | void ArchDesc::identify_unique_operands() { |
duke@435 | 4082 | // Walk over all instructions. |
duke@435 | 4083 | _instructions.reset(); |
duke@435 | 4084 | InstructForm *instr; |
duke@435 | 4085 | while( (instr = (InstructForm*)_instructions.iter()) != NULL ) { |
duke@435 | 4086 | // Ensure this is a machine-world instruction |
duke@435 | 4087 | if (!instr->ideal_only()) { |
duke@435 | 4088 | instr->set_unique_opnds(); |
duke@435 | 4089 | } |
duke@435 | 4090 | } |
duke@435 | 4091 | } |