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