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