Print this page
rev 1838 : 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/formssel.cpp
+++ new/src/share/vm/adlc/formssel.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 *
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
23 23 */
24 24
25 25 // FORMS.CPP - Definitions for ADL Parser Forms Classes
26 26 #include "adlc.hpp"
27 27
28 28 //==============================Instructions===================================
29 29 //------------------------------InstructForm-----------------------------------
30 30 InstructForm::InstructForm(const char *id, bool ideal_only)
31 31 : _ident(id), _ideal_only(ideal_only),
32 32 _localNames(cmpstr, hashstr, Form::arena),
33 - _effects(cmpstr, hashstr, Form::arena) {
33 + _effects(cmpstr, hashstr, Form::arena),
34 + _is_mach_constant(false)
35 +{
34 36 _ftype = Form::INS;
35 37
36 38 _matrule = NULL;
37 39 _insencode = NULL;
40 + _constant = NULL;
38 41 _opcode = NULL;
39 42 _size = NULL;
40 43 _attribs = NULL;
41 44 _predicate = NULL;
42 45 _exprule = NULL;
43 46 _rewrule = NULL;
44 47 _format = NULL;
45 48 _peephole = NULL;
46 49 _ins_pipe = NULL;
47 50 _uniq_idx = NULL;
48 51 _num_uniq = 0;
49 52 _cisc_spill_operand = Not_cisc_spillable;// Which operand may cisc-spill
50 53 _cisc_spill_alternate = NULL; // possible cisc replacement
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
51 54 _cisc_reg_mask_name = NULL;
52 55 _is_cisc_alternate = false;
53 56 _is_short_branch = false;
54 57 _short_branch_form = NULL;
55 58 _alignment = 1;
56 59 }
57 60
58 61 InstructForm::InstructForm(const char *id, InstructForm *instr, MatchRule *rule)
59 62 : _ident(id), _ideal_only(false),
60 63 _localNames(instr->_localNames),
61 - _effects(instr->_effects) {
64 + _effects(instr->_effects),
65 + _is_mach_constant(false)
66 +{
62 67 _ftype = Form::INS;
63 68
64 69 _matrule = rule;
65 70 _insencode = instr->_insencode;
71 + _constant = instr->_constant;
66 72 _opcode = instr->_opcode;
67 73 _size = instr->_size;
68 74 _attribs = instr->_attribs;
69 75 _predicate = instr->_predicate;
70 76 _exprule = instr->_exprule;
71 77 _rewrule = instr->_rewrule;
72 78 _format = instr->_format;
73 79 _peephole = instr->_peephole;
74 80 _ins_pipe = instr->_ins_pipe;
75 81 _uniq_idx = instr->_uniq_idx;
76 82 _num_uniq = instr->_num_uniq;
77 83 _cisc_spill_operand = Not_cisc_spillable;// Which operand may cisc-spill
78 84 _cisc_spill_alternate = NULL; // possible cisc replacement
79 85 _cisc_reg_mask_name = NULL;
80 86 _is_cisc_alternate = false;
81 87 _is_short_branch = false;
82 88 _short_branch_form = NULL;
83 89 _alignment = 1;
84 90 // Copy parameters
85 91 const char *name;
86 92 instr->_parameters.reset();
87 93 for (; (name = instr->_parameters.iter()) != NULL;)
88 94 _parameters.addName(name);
89 95 }
90 96
91 97 InstructForm::~InstructForm() {
92 98 }
93 99
94 100 InstructForm *InstructForm::is_instruction() const {
95 101 return (InstructForm*)this;
96 102 }
97 103
98 104 bool InstructForm::ideal_only() const {
99 105 return _ideal_only;
100 106 }
101 107
102 108 bool InstructForm::sets_result() const {
103 109 return (_matrule != NULL && _matrule->sets_result());
104 110 }
105 111
106 112 bool InstructForm::needs_projections() {
107 113 _components.reset();
108 114 for( Component *comp; (comp = _components.iter()) != NULL; ) {
109 115 if (comp->isa(Component::KILL)) {
110 116 return true;
111 117 }
112 118 }
113 119 return false;
114 120 }
115 121
116 122
117 123 bool InstructForm::has_temps() {
118 124 if (_matrule) {
119 125 // Examine each component to see if it is a TEMP
120 126 _components.reset();
121 127 // Skip the first component, if already handled as (SET dst (...))
122 128 Component *comp = NULL;
123 129 if (sets_result()) comp = _components.iter();
124 130 while ((comp = _components.iter()) != NULL) {
125 131 if (comp->isa(Component::TEMP)) {
126 132 return true;
127 133 }
128 134 }
129 135 }
130 136
131 137 return false;
132 138 }
133 139
134 140 uint InstructForm::num_defs_or_kills() {
135 141 uint defs_or_kills = 0;
136 142
137 143 _components.reset();
138 144 for( Component *comp; (comp = _components.iter()) != NULL; ) {
139 145 if( comp->isa(Component::DEF) || comp->isa(Component::KILL) ) {
140 146 ++defs_or_kills;
141 147 }
142 148 }
143 149
144 150 return defs_or_kills;
145 151 }
146 152
147 153 // This instruction has an expand rule?
148 154 bool InstructForm::expands() const {
149 155 return ( _exprule != NULL );
150 156 }
151 157
152 158 // This instruction has a peephole rule?
153 159 Peephole *InstructForm::peepholes() const {
154 160 return _peephole;
155 161 }
156 162
157 163 // This instruction has a peephole rule?
158 164 void InstructForm::append_peephole(Peephole *peephole) {
159 165 if( _peephole == NULL ) {
160 166 _peephole = peephole;
161 167 } else {
162 168 _peephole->append_peephole(peephole);
163 169 }
164 170 }
165 171
166 172
167 173 // ideal opcode enumeration
168 174 const char *InstructForm::ideal_Opcode( FormDict &globalNames ) const {
169 175 if( !_matrule ) return "Node"; // Something weird
170 176 // Chain rules do not really have ideal Opcodes; use their source
171 177 // operand ideal Opcode instead.
172 178 if( is_simple_chain_rule(globalNames) ) {
173 179 const char *src = _matrule->_rChild->_opType;
174 180 OperandForm *src_op = globalNames[src]->is_operand();
175 181 assert( src_op, "Not operand class of chain rule" );
176 182 if( !src_op->_matrule ) return "Node";
177 183 return src_op->_matrule->_opType;
178 184 }
179 185 // Operand chain rules do not really have ideal Opcodes
180 186 if( _matrule->is_chain_rule(globalNames) )
181 187 return "Node";
182 188 return strcmp(_matrule->_opType,"Set")
183 189 ? _matrule->_opType
184 190 : _matrule->_rChild->_opType;
185 191 }
186 192
187 193 // Recursive check on all operands' match rules in my match rule
188 194 bool InstructForm::is_pinned(FormDict &globals) {
189 195 if ( ! _matrule) return false;
190 196
191 197 int index = 0;
192 198 if (_matrule->find_type("Goto", index)) return true;
193 199 if (_matrule->find_type("If", index)) return true;
194 200 if (_matrule->find_type("CountedLoopEnd",index)) return true;
195 201 if (_matrule->find_type("Return", index)) return true;
196 202 if (_matrule->find_type("Rethrow", index)) return true;
197 203 if (_matrule->find_type("TailCall", index)) return true;
198 204 if (_matrule->find_type("TailJump", index)) return true;
199 205 if (_matrule->find_type("Halt", index)) return true;
200 206 if (_matrule->find_type("Jump", index)) return true;
201 207
202 208 return is_parm(globals);
203 209 }
204 210
205 211 // Recursive check on all operands' match rules in my match rule
206 212 bool InstructForm::is_projection(FormDict &globals) {
207 213 if ( ! _matrule) return false;
208 214
209 215 int index = 0;
210 216 if (_matrule->find_type("Goto", index)) return true;
211 217 if (_matrule->find_type("Return", index)) return true;
212 218 if (_matrule->find_type("Rethrow", index)) return true;
213 219 if (_matrule->find_type("TailCall",index)) return true;
214 220 if (_matrule->find_type("TailJump",index)) return true;
215 221 if (_matrule->find_type("Halt", index)) return true;
216 222
217 223 return false;
218 224 }
219 225
220 226 // Recursive check on all operands' match rules in my match rule
221 227 bool InstructForm::is_parm(FormDict &globals) {
222 228 if ( ! _matrule) return false;
223 229
224 230 int index = 0;
225 231 if (_matrule->find_type("Parm",index)) return true;
226 232
227 233 return false;
228 234 }
229 235
230 236
231 237 // Return 'true' if this instruction matches an ideal 'Copy*' node
232 238 int InstructForm::is_ideal_copy() const {
233 239 return _matrule ? _matrule->is_ideal_copy() : 0;
234 240 }
235 241
236 242 // Return 'true' if this instruction is too complex to rematerialize.
237 243 int InstructForm::is_expensive() const {
238 244 // We can prove it is cheap if it has an empty encoding.
239 245 // This helps with platform-specific nops like ThreadLocal and RoundFloat.
240 246 if (is_empty_encoding())
241 247 return 0;
242 248
243 249 if (is_tls_instruction())
244 250 return 1;
245 251
246 252 if (_matrule == NULL) return 0;
247 253
248 254 return _matrule->is_expensive();
249 255 }
250 256
251 257 // Has an empty encoding if _size is a constant zero or there
252 258 // are no ins_encode tokens.
253 259 int InstructForm::is_empty_encoding() const {
254 260 if (_insencode != NULL) {
255 261 _insencode->reset();
256 262 if (_insencode->encode_class_iter() == NULL) {
257 263 return 1;
258 264 }
259 265 }
260 266 if (_size != NULL && strcmp(_size, "0") == 0) {
261 267 return 1;
262 268 }
263 269 return 0;
264 270 }
265 271
266 272 int InstructForm::is_tls_instruction() const {
267 273 if (_ident != NULL &&
268 274 ( ! strcmp( _ident,"tlsLoadP") ||
269 275 ! strncmp(_ident,"tlsLoadP_",9)) ) {
270 276 return 1;
271 277 }
272 278
273 279 if (_matrule != NULL && _insencode != NULL) {
274 280 const char* opType = _matrule->_opType;
275 281 if (strcmp(opType, "Set")==0)
276 282 opType = _matrule->_rChild->_opType;
277 283 if (strcmp(opType,"ThreadLocal")==0) {
278 284 fprintf(stderr, "Warning: ThreadLocal instruction %s should be named 'tlsLoadP_*'\n",
279 285 (_ident == NULL ? "NULL" : _ident));
280 286 return 1;
281 287 }
282 288 }
283 289
284 290 return 0;
285 291 }
286 292
287 293
288 294 // Return 'true' if this instruction matches an ideal 'Copy*' node
289 295 bool InstructForm::is_ideal_unlock() const {
290 296 return _matrule ? _matrule->is_ideal_unlock() : false;
291 297 }
292 298
293 299 bool InstructForm::is_ideal_call_leaf() const {
294 300 return _matrule ? _matrule->is_ideal_call_leaf() : false;
295 301 }
296 302
297 303 // Return 'true' if this instruction matches an ideal 'If' node
298 304 bool InstructForm::is_ideal_if() const {
299 305 if( _matrule == NULL ) return false;
300 306
301 307 return _matrule->is_ideal_if();
302 308 }
303 309
304 310 // Return 'true' if this instruction matches an ideal 'FastLock' node
305 311 bool InstructForm::is_ideal_fastlock() const {
306 312 if( _matrule == NULL ) return false;
307 313
308 314 return _matrule->is_ideal_fastlock();
309 315 }
310 316
311 317 // Return 'true' if this instruction matches an ideal 'MemBarXXX' node
312 318 bool InstructForm::is_ideal_membar() const {
313 319 if( _matrule == NULL ) return false;
314 320
315 321 return _matrule->is_ideal_membar();
316 322 }
317 323
318 324 // Return 'true' if this instruction matches an ideal 'LoadPC' node
319 325 bool InstructForm::is_ideal_loadPC() const {
320 326 if( _matrule == NULL ) return false;
321 327
322 328 return _matrule->is_ideal_loadPC();
323 329 }
324 330
325 331 // Return 'true' if this instruction matches an ideal 'Box' node
326 332 bool InstructForm::is_ideal_box() const {
327 333 if( _matrule == NULL ) return false;
328 334
329 335 return _matrule->is_ideal_box();
330 336 }
331 337
332 338 // Return 'true' if this instruction matches an ideal 'Goto' node
333 339 bool InstructForm::is_ideal_goto() const {
334 340 if( _matrule == NULL ) return false;
335 341
336 342 return _matrule->is_ideal_goto();
337 343 }
338 344
339 345 // Return 'true' if this instruction matches an ideal 'Jump' node
340 346 bool InstructForm::is_ideal_jump() const {
341 347 if( _matrule == NULL ) return false;
342 348
343 349 return _matrule->is_ideal_jump();
344 350 }
345 351
346 352 // Return 'true' if instruction matches ideal 'If' | 'Goto' |
347 353 // 'CountedLoopEnd' | 'Jump'
348 354 bool InstructForm::is_ideal_branch() const {
349 355 if( _matrule == NULL ) return false;
350 356
351 357 return _matrule->is_ideal_if() || _matrule->is_ideal_goto() || _matrule->is_ideal_jump();
352 358 }
353 359
354 360
355 361 // Return 'true' if this instruction matches an ideal 'Return' node
356 362 bool InstructForm::is_ideal_return() const {
357 363 if( _matrule == NULL ) return false;
358 364
359 365 // Check MatchRule to see if the first entry is the ideal "Return" node
360 366 int index = 0;
361 367 if (_matrule->find_type("Return",index)) return true;
362 368 if (_matrule->find_type("Rethrow",index)) return true;
363 369 if (_matrule->find_type("TailCall",index)) return true;
364 370 if (_matrule->find_type("TailJump",index)) return true;
365 371
366 372 return false;
367 373 }
368 374
369 375 // Return 'true' if this instruction matches an ideal 'Halt' node
370 376 bool InstructForm::is_ideal_halt() const {
371 377 int index = 0;
372 378 return _matrule && _matrule->find_type("Halt",index);
373 379 }
374 380
375 381 // Return 'true' if this instruction matches an ideal 'SafePoint' node
376 382 bool InstructForm::is_ideal_safepoint() const {
377 383 int index = 0;
378 384 return _matrule && _matrule->find_type("SafePoint",index);
379 385 }
380 386
381 387 // Return 'true' if this instruction matches an ideal 'Nop' node
382 388 bool InstructForm::is_ideal_nop() const {
383 389 return _ident && _ident[0] == 'N' && _ident[1] == 'o' && _ident[2] == 'p' && _ident[3] == '_';
384 390 }
385 391
386 392 bool InstructForm::is_ideal_control() const {
387 393 if ( ! _matrule) return false;
388 394
389 395 return is_ideal_return() || is_ideal_branch() || is_ideal_halt();
390 396 }
391 397
392 398 // Return 'true' if this instruction matches an ideal 'Call' node
393 399 Form::CallType InstructForm::is_ideal_call() const {
394 400 if( _matrule == NULL ) return Form::invalid_type;
395 401
396 402 // Check MatchRule to see if the first entry is the ideal "Call" node
397 403 int idx = 0;
398 404 if(_matrule->find_type("CallStaticJava",idx)) return Form::JAVA_STATIC;
399 405 idx = 0;
400 406 if(_matrule->find_type("Lock",idx)) return Form::JAVA_STATIC;
401 407 idx = 0;
402 408 if(_matrule->find_type("Unlock",idx)) return Form::JAVA_STATIC;
403 409 idx = 0;
404 410 if(_matrule->find_type("CallDynamicJava",idx)) return Form::JAVA_DYNAMIC;
405 411 idx = 0;
406 412 if(_matrule->find_type("CallRuntime",idx)) return Form::JAVA_RUNTIME;
407 413 idx = 0;
408 414 if(_matrule->find_type("CallLeaf",idx)) return Form::JAVA_LEAF;
409 415 idx = 0;
410 416 if(_matrule->find_type("CallLeafNoFP",idx)) return Form::JAVA_LEAF;
411 417 idx = 0;
412 418
413 419 return Form::invalid_type;
414 420 }
415 421
416 422 // Return 'true' if this instruction matches an ideal 'Load?' node
417 423 Form::DataType InstructForm::is_ideal_load() const {
418 424 if( _matrule == NULL ) return Form::none;
419 425
420 426 return _matrule->is_ideal_load();
421 427 }
422 428
423 429 // Return 'true' if this instruction matches an ideal 'LoadKlass' node
424 430 bool InstructForm::skip_antidep_check() const {
425 431 if( _matrule == NULL ) return false;
426 432
427 433 return _matrule->skip_antidep_check();
428 434 }
429 435
430 436 // Return 'true' if this instruction matches an ideal 'Load?' node
431 437 Form::DataType InstructForm::is_ideal_store() const {
432 438 if( _matrule == NULL ) return Form::none;
433 439
434 440 return _matrule->is_ideal_store();
435 441 }
436 442
437 443 // Return the input register that must match the output register
438 444 // If this is not required, return 0
439 445 uint InstructForm::two_address(FormDict &globals) {
440 446 uint matching_input = 0;
441 447 if(_components.count() == 0) return 0;
442 448
443 449 _components.reset();
444 450 Component *comp = _components.iter();
445 451 // Check if there is a DEF
446 452 if( comp->isa(Component::DEF) ) {
447 453 // Check that this is a register
448 454 const char *def_type = comp->_type;
449 455 const Form *form = globals[def_type];
450 456 OperandForm *op = form->is_operand();
451 457 if( op ) {
452 458 if( op->constrained_reg_class() != NULL &&
453 459 op->interface_type(globals) == Form::register_interface ) {
454 460 // Remember the local name for equality test later
455 461 const char *def_name = comp->_name;
456 462 // Check if a component has the same name and is a USE
457 463 do {
458 464 if( comp->isa(Component::USE) && strcmp(comp->_name,def_name)==0 ) {
459 465 return operand_position_format(def_name);
460 466 }
461 467 } while( (comp = _components.iter()) != NULL);
462 468 }
463 469 }
464 470 }
465 471
466 472 return 0;
467 473 }
468 474
469 475
470 476 // when chaining a constant to an instruction, returns 'true' and sets opType
471 477 Form::DataType InstructForm::is_chain_of_constant(FormDict &globals) {
472 478 const char *dummy = NULL;
473 479 const char *dummy2 = NULL;
474 480 return is_chain_of_constant(globals, dummy, dummy2);
475 481 }
476 482 Form::DataType InstructForm::is_chain_of_constant(FormDict &globals,
477 483 const char * &opTypeParam) {
478 484 const char *result = NULL;
479 485
480 486 return is_chain_of_constant(globals, opTypeParam, result);
481 487 }
482 488
483 489 Form::DataType InstructForm::is_chain_of_constant(FormDict &globals,
484 490 const char * &opTypeParam, const char * &resultParam) {
485 491 Form::DataType data_type = Form::none;
486 492 if ( ! _matrule) return data_type;
487 493
488 494 // !!!!!
489 495 // The source of the chain rule is 'position = 1'
490 496 uint position = 1;
491 497 const char *result = NULL;
492 498 const char *name = NULL;
493 499 const char *opType = NULL;
494 500 // Here base_operand is looking for an ideal type to be returned (opType).
495 501 if ( _matrule->is_chain_rule(globals)
496 502 && _matrule->base_operand(position, globals, result, name, opType) ) {
497 503 data_type = ideal_to_const_type(opType);
498 504
499 505 // if it isn't an ideal constant type, just return
500 506 if ( data_type == Form::none ) return data_type;
501 507
502 508 // Ideal constant types also adjust the opType parameter.
503 509 resultParam = result;
504 510 opTypeParam = opType;
505 511 return data_type;
506 512 }
507 513
508 514 return data_type;
509 515 }
510 516
511 517 // Check if a simple chain rule
512 518 bool InstructForm::is_simple_chain_rule(FormDict &globals) const {
513 519 if( _matrule && _matrule->sets_result()
514 520 && _matrule->_rChild->_lChild == NULL
515 521 && globals[_matrule->_rChild->_opType]
516 522 && globals[_matrule->_rChild->_opType]->is_opclass() ) {
517 523 return true;
518 524 }
519 525 return false;
520 526 }
521 527
522 528 // check for structural rematerialization
523 529 bool InstructForm::rematerialize(FormDict &globals, RegisterForm *registers ) {
524 530 bool rematerialize = false;
525 531
526 532 Form::DataType data_type = is_chain_of_constant(globals);
527 533 if( data_type != Form::none )
528 534 rematerialize = true;
529 535
530 536 // Constants
531 537 if( _components.count() == 1 && _components[0]->is(Component::USE_DEF) )
532 538 rematerialize = true;
533 539
534 540 // Pseudo-constants (values easily available to the runtime)
535 541 if (is_empty_encoding() && is_tls_instruction())
536 542 rematerialize = true;
537 543
538 544 // 1-input, 1-output, such as copies or increments.
539 545 if( _components.count() == 2 &&
540 546 _components[0]->is(Component::DEF) &&
541 547 _components[1]->isa(Component::USE) )
542 548 rematerialize = true;
543 549
544 550 // Check for an ideal 'Load?' and eliminate rematerialize option
545 551 if ( is_ideal_load() != Form::none || // Ideal load? Do not rematerialize
546 552 is_ideal_copy() != Form::none || // Ideal copy? Do not rematerialize
547 553 is_expensive() != Form::none) { // Expensive? Do not rematerialize
548 554 rematerialize = false;
549 555 }
550 556
551 557 // Always rematerialize the flags. They are more expensive to save &
552 558 // restore than to recompute (and possibly spill the compare's inputs).
553 559 if( _components.count() >= 1 ) {
554 560 Component *c = _components[0];
555 561 const Form *form = globals[c->_type];
556 562 OperandForm *opform = form->is_operand();
557 563 if( opform ) {
558 564 // Avoid the special stack_slots register classes
559 565 const char *rc_name = opform->constrained_reg_class();
560 566 if( rc_name ) {
561 567 if( strcmp(rc_name,"stack_slots") ) {
562 568 // Check for ideal_type of RegFlags
563 569 const char *type = opform->ideal_type( globals, registers );
564 570 if( !strcmp(type,"RegFlags") )
565 571 rematerialize = true;
566 572 } else
567 573 rematerialize = false; // Do not rematerialize things target stk
568 574 }
569 575 }
570 576 }
571 577
572 578 return rematerialize;
573 579 }
574 580
575 581 // loads from memory, so must check for anti-dependence
576 582 bool InstructForm::needs_anti_dependence_check(FormDict &globals) const {
577 583 if ( skip_antidep_check() ) return false;
578 584
579 585 // Machine independent loads must be checked for anti-dependences
580 586 if( is_ideal_load() != Form::none ) return true;
581 587
582 588 // !!!!! !!!!! !!!!!
583 589 // TEMPORARY
584 590 // if( is_simple_chain_rule(globals) ) return false;
585 591
586 592 // String.(compareTo/equals/indexOf) and Arrays.equals use many memorys edges,
587 593 // but writes none
588 594 if( _matrule && _matrule->_rChild &&
589 595 ( strcmp(_matrule->_rChild->_opType,"StrComp" )==0 ||
590 596 strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 ||
591 597 strcmp(_matrule->_rChild->_opType,"StrIndexOf" )==0 ||
592 598 strcmp(_matrule->_rChild->_opType,"AryEq" )==0 ))
593 599 return true;
594 600
595 601 // Check if instruction has a USE of a memory operand class, but no defs
596 602 bool USE_of_memory = false;
597 603 bool DEF_of_memory = false;
598 604 Component *comp = NULL;
599 605 ComponentList &components = (ComponentList &)_components;
600 606
601 607 components.reset();
602 608 while( (comp = components.iter()) != NULL ) {
603 609 const Form *form = globals[comp->_type];
604 610 if( !form ) continue;
605 611 OpClassForm *op = form->is_opclass();
606 612 if( !op ) continue;
607 613 if( form->interface_type(globals) == Form::memory_interface ) {
608 614 if( comp->isa(Component::USE) ) USE_of_memory = true;
609 615 if( comp->isa(Component::DEF) ) {
610 616 OperandForm *oper = form->is_operand();
611 617 if( oper && oper->is_user_name_for_sReg() ) {
612 618 // Stack slots are unaliased memory handled by allocator
613 619 oper = oper; // debug stopping point !!!!!
614 620 } else {
615 621 DEF_of_memory = true;
616 622 }
617 623 }
618 624 }
619 625 }
620 626 return (USE_of_memory && !DEF_of_memory);
621 627 }
622 628
623 629
624 630 bool InstructForm::is_wide_memory_kill(FormDict &globals) const {
625 631 if( _matrule == NULL ) return false;
626 632 if( !_matrule->_opType ) return false;
627 633
628 634 if( strcmp(_matrule->_opType,"MemBarRelease") == 0 ) return true;
629 635 if( strcmp(_matrule->_opType,"MemBarAcquire") == 0 ) return true;
630 636
631 637 return false;
632 638 }
633 639
634 640 int InstructForm::memory_operand(FormDict &globals) const {
635 641 // Machine independent loads must be checked for anti-dependences
636 642 // Check if instruction has a USE of a memory operand class, or a def.
637 643 int USE_of_memory = 0;
638 644 int DEF_of_memory = 0;
639 645 const char* last_memory_DEF = NULL; // to test DEF/USE pairing in asserts
640 646 Component *unique = NULL;
641 647 Component *comp = NULL;
642 648 ComponentList &components = (ComponentList &)_components;
643 649
644 650 components.reset();
645 651 while( (comp = components.iter()) != NULL ) {
646 652 const Form *form = globals[comp->_type];
647 653 if( !form ) continue;
648 654 OpClassForm *op = form->is_opclass();
649 655 if( !op ) continue;
650 656 if( op->stack_slots_only(globals) ) continue;
651 657 if( form->interface_type(globals) == Form::memory_interface ) {
652 658 if( comp->isa(Component::DEF) ) {
653 659 last_memory_DEF = comp->_name;
654 660 DEF_of_memory++;
655 661 unique = comp;
656 662 } else if( comp->isa(Component::USE) ) {
657 663 if( last_memory_DEF != NULL ) {
658 664 assert(0 == strcmp(last_memory_DEF, comp->_name), "every memory DEF is followed by a USE of the same name");
659 665 last_memory_DEF = NULL;
660 666 }
661 667 USE_of_memory++;
662 668 if (DEF_of_memory == 0) // defs take precedence
663 669 unique = comp;
664 670 } else {
665 671 assert(last_memory_DEF == NULL, "unpaired memory DEF");
666 672 }
667 673 }
668 674 }
669 675 assert(last_memory_DEF == NULL, "unpaired memory DEF");
670 676 assert(USE_of_memory >= DEF_of_memory, "unpaired memory DEF");
671 677 USE_of_memory -= DEF_of_memory; // treat paired DEF/USE as one occurrence
672 678 if( (USE_of_memory + DEF_of_memory) > 0 ) {
673 679 if( is_simple_chain_rule(globals) ) {
674 680 //fprintf(stderr, "Warning: chain rule is not really a memory user.\n");
675 681 //((InstructForm*)this)->dump();
676 682 // Preceding code prints nothing on sparc and these insns on intel:
677 683 // leaP8 leaP32 leaPIdxOff leaPIdxScale leaPIdxScaleOff leaP8 leaP32
678 684 // leaPIdxOff leaPIdxScale leaPIdxScaleOff
679 685 return NO_MEMORY_OPERAND;
680 686 }
681 687
682 688 if( DEF_of_memory == 1 ) {
683 689 assert(unique != NULL, "");
684 690 if( USE_of_memory == 0 ) {
685 691 // unique def, no uses
686 692 } else {
687 693 // // unique def, some uses
688 694 // // must return bottom unless all uses match def
689 695 // unique = NULL;
690 696 }
691 697 } else if( DEF_of_memory > 0 ) {
692 698 // multiple defs, don't care about uses
693 699 unique = NULL;
694 700 } else if( USE_of_memory == 1) {
695 701 // unique use, no defs
696 702 assert(unique != NULL, "");
697 703 } else if( USE_of_memory > 0 ) {
698 704 // multiple uses, no defs
699 705 unique = NULL;
700 706 } else {
701 707 assert(false, "bad case analysis");
702 708 }
703 709 // process the unique DEF or USE, if there is one
704 710 if( unique == NULL ) {
705 711 return MANY_MEMORY_OPERANDS;
706 712 } else {
707 713 int pos = components.operand_position(unique->_name);
708 714 if( unique->isa(Component::DEF) ) {
709 715 pos += 1; // get corresponding USE from DEF
710 716 }
711 717 assert(pos >= 1, "I was just looking at it!");
712 718 return pos;
713 719 }
714 720 }
715 721
716 722 // missed the memory op??
717 723 if( true ) { // %%% should not be necessary
718 724 if( is_ideal_store() != Form::none ) {
719 725 fprintf(stderr, "Warning: cannot find memory opnd in instr.\n");
720 726 ((InstructForm*)this)->dump();
721 727 // pretend it has multiple defs and uses
722 728 return MANY_MEMORY_OPERANDS;
723 729 }
724 730 if( is_ideal_load() != Form::none ) {
725 731 fprintf(stderr, "Warning: cannot find memory opnd in instr.\n");
726 732 ((InstructForm*)this)->dump();
727 733 // pretend it has multiple uses and no defs
728 734 return MANY_MEMORY_OPERANDS;
729 735 }
730 736 }
731 737
732 738 return NO_MEMORY_OPERAND;
733 739 }
734 740
735 741
736 742 // This instruction captures the machine-independent bottom_type
737 743 // Expected use is for pointer vs oop determination for LoadP
738 744 bool InstructForm::captures_bottom_type(FormDict &globals) const {
739 745 if( _matrule && _matrule->_rChild &&
740 746 (!strcmp(_matrule->_rChild->_opType,"CastPP") || // new result type
741 747 !strcmp(_matrule->_rChild->_opType,"CastX2P") || // new result type
742 748 !strcmp(_matrule->_rChild->_opType,"DecodeN") ||
743 749 !strcmp(_matrule->_rChild->_opType,"EncodeP") ||
744 750 !strcmp(_matrule->_rChild->_opType,"LoadN") ||
745 751 !strcmp(_matrule->_rChild->_opType,"LoadNKlass") ||
746 752 !strcmp(_matrule->_rChild->_opType,"CreateEx") || // type of exception
747 753 !strcmp(_matrule->_rChild->_opType,"CheckCastPP")) ) return true;
748 754 else if ( is_ideal_load() == Form::idealP ) return true;
749 755 else if ( is_ideal_store() != Form::none ) return true;
750 756
751 757 if (needs_base_oop_edge(globals)) return true;
752 758
753 759 return false;
754 760 }
755 761
756 762
757 763 // Access instr_cost attribute or return NULL.
758 764 const char* InstructForm::cost() {
759 765 for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) {
760 766 if( strcmp(cur->_ident,AttributeForm::_ins_cost) == 0 ) {
761 767 return cur->_val;
762 768 }
763 769 }
764 770 return NULL;
765 771 }
766 772
767 773 // Return count of top-level operands.
768 774 uint InstructForm::num_opnds() {
769 775 int num_opnds = _components.num_operands();
770 776
771 777 // Need special handling for matching some ideal nodes
772 778 // i.e. Matching a return node
773 779 /*
774 780 if( _matrule ) {
775 781 if( strcmp(_matrule->_opType,"Return" )==0 ||
776 782 strcmp(_matrule->_opType,"Halt" )==0 )
777 783 return 3;
778 784 }
779 785 */
780 786 return num_opnds;
781 787 }
782 788
783 789 // Return count of unmatched operands.
784 790 uint InstructForm::num_post_match_opnds() {
785 791 uint num_post_match_opnds = _components.count();
786 792 uint num_match_opnds = _components.match_count();
787 793 num_post_match_opnds = num_post_match_opnds - num_match_opnds;
788 794
789 795 return num_post_match_opnds;
790 796 }
791 797
792 798 // Return the number of leaves below this complex operand
793 799 uint InstructForm::num_consts(FormDict &globals) const {
794 800 if ( ! _matrule) return 0;
795 801
796 802 // This is a recursive invocation on all operands in the matchrule
797 803 return _matrule->num_consts(globals);
798 804 }
799 805
800 806 // Constants in match rule with specified type
801 807 uint InstructForm::num_consts(FormDict &globals, Form::DataType type) const {
802 808 if ( ! _matrule) return 0;
803 809
804 810 // This is a recursive invocation on all operands in the matchrule
805 811 return _matrule->num_consts(globals, type);
806 812 }
807 813
808 814
809 815 // Return the register class associated with 'leaf'.
810 816 const char *InstructForm::out_reg_class(FormDict &globals) {
811 817 assert( false, "InstructForm::out_reg_class(FormDict &globals); Not Implemented");
812 818
813 819 return NULL;
814 820 }
815 821
816 822
817 823
818 824 // Lookup the starting position of inputs we are interested in wrt. ideal nodes
819 825 uint InstructForm::oper_input_base(FormDict &globals) {
820 826 if( !_matrule ) return 1; // Skip control for most nodes
821 827
822 828 // Need special handling for matching some ideal nodes
823 829 // i.e. Matching a return node
824 830 if( strcmp(_matrule->_opType,"Return" )==0 ||
825 831 strcmp(_matrule->_opType,"Rethrow" )==0 ||
826 832 strcmp(_matrule->_opType,"TailCall" )==0 ||
827 833 strcmp(_matrule->_opType,"TailJump" )==0 ||
828 834 strcmp(_matrule->_opType,"SafePoint" )==0 ||
829 835 strcmp(_matrule->_opType,"Halt" )==0 )
830 836 return AdlcVMDeps::Parms; // Skip the machine-state edges
831 837
832 838 if( _matrule->_rChild &&
833 839 ( strcmp(_matrule->_rChild->_opType,"AryEq" )==0 ||
834 840 strcmp(_matrule->_rChild->_opType,"StrComp" )==0 ||
835 841 strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 ||
836 842 strcmp(_matrule->_rChild->_opType,"StrIndexOf")==0 )) {
837 843 // String.(compareTo/equals/indexOf) and Arrays.equals
838 844 // take 1 control and 1 memory edges.
839 845 return 2;
840 846 }
841 847
842 848 // Check for handling of 'Memory' input/edge in the ideal world.
843 849 // The AD file writer is shielded from knowledge of these edges.
844 850 int base = 1; // Skip control
845 851 base += _matrule->needs_ideal_memory_edge(globals);
846 852
847 853 // Also skip the base-oop value for uses of derived oops.
848 854 // The AD file writer is shielded from knowledge of these edges.
849 855 base += needs_base_oop_edge(globals);
850 856
851 857 return base;
852 858 }
853 859
854 860 // Implementation does not modify state of internal structures
855 861 void InstructForm::build_components() {
856 862 // Add top-level operands to the components
857 863 if (_matrule) _matrule->append_components(_localNames, _components);
858 864
859 865 // Add parameters that "do not appear in match rule".
860 866 bool has_temp = false;
861 867 const char *name;
862 868 const char *kill_name = NULL;
863 869 for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
864 870 OperandForm *opForm = (OperandForm*)_localNames[name];
865 871
866 872 Effect* e = NULL;
867 873 {
868 874 const Form* form = _effects[name];
869 875 e = form ? form->is_effect() : NULL;
870 876 }
871 877
872 878 if (e != NULL) {
873 879 has_temp |= e->is(Component::TEMP);
874 880
875 881 // KILLs must be declared after any TEMPs because TEMPs are real
876 882 // uses so their operand numbering must directly follow the real
877 883 // inputs from the match rule. Fixing the numbering seems
878 884 // complex so simply enforce the restriction during parse.
879 885 if (kill_name != NULL &&
880 886 e->isa(Component::TEMP) && !e->isa(Component::DEF)) {
881 887 OperandForm* kill = (OperandForm*)_localNames[kill_name];
882 888 globalAD->syntax_err(_linenum, "%s: %s %s must be at the end of the argument list\n",
883 889 _ident, kill->_ident, kill_name);
884 890 } else if (e->isa(Component::KILL) && !e->isa(Component::USE)) {
885 891 kill_name = name;
886 892 }
887 893 }
888 894
889 895 const Component *component = _components.search(name);
890 896 if ( component == NULL ) {
891 897 if (e) {
892 898 _components.insert(name, opForm->_ident, e->_use_def, false);
893 899 component = _components.search(name);
894 900 if (component->isa(Component::USE) && !component->isa(Component::TEMP) && _matrule) {
895 901 const Form *form = globalAD->globalNames()[component->_type];
896 902 assert( form, "component type must be a defined form");
897 903 OperandForm *op = form->is_operand();
898 904 if (op->_interface && op->_interface->is_RegInterface()) {
899 905 globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n",
900 906 _ident, opForm->_ident, name);
901 907 }
902 908 }
903 909 } else {
904 910 // This would be a nice warning but it triggers in a few places in a benign way
905 911 // if (_matrule != NULL && !expands()) {
906 912 // globalAD->syntax_err(_linenum, "%s: %s %s not mentioned in effect or match rule\n",
907 913 // _ident, opForm->_ident, name);
908 914 // }
909 915 _components.insert(name, opForm->_ident, Component::INVALID, false);
910 916 }
911 917 }
912 918 else if (e) {
913 919 // Component was found in the list
914 920 // Check if there is a new effect that requires an extra component.
915 921 // This happens when adding 'USE' to a component that is not yet one.
916 922 if ((!component->isa( Component::USE) && ((e->_use_def & Component::USE) != 0))) {
917 923 if (component->isa(Component::USE) && _matrule) {
918 924 const Form *form = globalAD->globalNames()[component->_type];
919 925 assert( form, "component type must be a defined form");
920 926 OperandForm *op = form->is_operand();
921 927 if (op->_interface && op->_interface->is_RegInterface()) {
922 928 globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n",
923 929 _ident, opForm->_ident, name);
924 930 }
925 931 }
926 932 _components.insert(name, opForm->_ident, e->_use_def, false);
927 933 } else {
928 934 Component *comp = (Component*)component;
929 935 comp->promote_use_def_info(e->_use_def);
930 936 }
931 937 // Component positions are zero based.
932 938 int pos = _components.operand_position(name);
933 939 assert( ! (component->isa(Component::DEF) && (pos >= 1)),
934 940 "Component::DEF can only occur in the first position");
935 941 }
936 942 }
937 943
938 944 // Resolving the interactions between expand rules and TEMPs would
939 945 // be complex so simply disallow it.
940 946 if (_matrule == NULL && has_temp) {
941 947 globalAD->syntax_err(_linenum, "%s: TEMPs without match rule isn't supported\n", _ident);
942 948 }
943 949
944 950 return;
945 951 }
946 952
947 953 // Return zero-based position in component list; -1 if not in list.
948 954 int InstructForm::operand_position(const char *name, int usedef) {
949 955 return unique_opnds_idx(_components.operand_position(name, usedef));
950 956 }
951 957
952 958 int InstructForm::operand_position_format(const char *name) {
953 959 return unique_opnds_idx(_components.operand_position_format(name));
954 960 }
955 961
956 962 // Return zero-based position in component list; -1 if not in list.
957 963 int InstructForm::label_position() {
958 964 return unique_opnds_idx(_components.label_position());
959 965 }
960 966
961 967 int InstructForm::method_position() {
962 968 return unique_opnds_idx(_components.method_position());
963 969 }
964 970
965 971 // Return number of relocation entries needed for this instruction.
966 972 uint InstructForm::reloc(FormDict &globals) {
967 973 uint reloc_entries = 0;
968 974 // Check for "Call" nodes
969 975 if ( is_ideal_call() ) ++reloc_entries;
970 976 if ( is_ideal_return() ) ++reloc_entries;
971 977 if ( is_ideal_safepoint() ) ++reloc_entries;
972 978
973 979
974 980 // Check if operands MAYBE oop pointers, by checking for ConP elements
975 981 // Proceed through the leaves of the match-tree and check for ConPs
976 982 if ( _matrule != NULL ) {
977 983 uint position = 0;
978 984 const char *result = NULL;
979 985 const char *name = NULL;
980 986 const char *opType = NULL;
981 987 while (_matrule->base_operand(position, globals, result, name, opType)) {
982 988 if ( strcmp(opType,"ConP") == 0 ) {
983 989 #ifdef SPARC
984 990 reloc_entries += 2; // 1 for sethi + 1 for setlo
985 991 #else
986 992 ++reloc_entries;
987 993 #endif
988 994 }
989 995 ++position;
990 996 }
991 997 }
992 998
993 999 // Above is only a conservative estimate
994 1000 // because it did not check contents of operand classes.
995 1001 // !!!!! !!!!!
996 1002 // Add 1 to reloc info for each operand class in the component list.
997 1003 Component *comp;
998 1004 _components.reset();
999 1005 while ( (comp = _components.iter()) != NULL ) {
1000 1006 const Form *form = globals[comp->_type];
1001 1007 assert( form, "Did not find component's type in global names");
1002 1008 const OpClassForm *opc = form->is_opclass();
1003 1009 const OperandForm *oper = form->is_operand();
1004 1010 if ( opc && (oper == NULL) ) {
1005 1011 ++reloc_entries;
1006 1012 } else if ( oper ) {
1007 1013 // floats and doubles loaded out of method's constant pool require reloc info
1008 1014 Form::DataType type = oper->is_base_constant(globals);
1009 1015 if ( (type == Form::idealF) || (type == Form::idealD) ) {
1010 1016 ++reloc_entries;
1011 1017 }
1012 1018 }
1013 1019 }
1014 1020
1015 1021 // Float and Double constants may come from the CodeBuffer table
1016 1022 // and require relocatable addresses for access
1017 1023 // !!!!!
1018 1024 // Check for any component being an immediate float or double.
1019 1025 Form::DataType data_type = is_chain_of_constant(globals);
1020 1026 if( data_type==idealD || data_type==idealF ) {
1021 1027 #ifdef SPARC
1022 1028 // sparc required more relocation entries for floating constants
1023 1029 // (expires 9/98)
1024 1030 reloc_entries += 6;
1025 1031 #else
1026 1032 reloc_entries++;
1027 1033 #endif
1028 1034 }
1029 1035
1030 1036 return reloc_entries;
1031 1037 }
1032 1038
1033 1039 // Utility function defined in archDesc.cpp
1034 1040 extern bool is_def(int usedef);
1035 1041
1036 1042 // Return the result of reducing an instruction
1037 1043 const char *InstructForm::reduce_result() {
1038 1044 const char* result = "Universe"; // default
1039 1045 _components.reset();
1040 1046 Component *comp = _components.iter();
1041 1047 if (comp != NULL && comp->isa(Component::DEF)) {
1042 1048 result = comp->_type;
1043 1049 // Override this if the rule is a store operation:
1044 1050 if (_matrule && _matrule->_rChild &&
1045 1051 is_store_to_memory(_matrule->_rChild->_opType))
1046 1052 result = "Universe";
1047 1053 }
1048 1054 return result;
1049 1055 }
1050 1056
1051 1057 // Return the name of the operand on the right hand side of the binary match
1052 1058 // Return NULL if there is no right hand side
1053 1059 const char *InstructForm::reduce_right(FormDict &globals) const {
1054 1060 if( _matrule == NULL ) return NULL;
1055 1061 return _matrule->reduce_right(globals);
1056 1062 }
1057 1063
1058 1064 // Similar for left
1059 1065 const char *InstructForm::reduce_left(FormDict &globals) const {
1060 1066 if( _matrule == NULL ) return NULL;
1061 1067 return _matrule->reduce_left(globals);
1062 1068 }
1063 1069
1064 1070
1065 1071 // Base class for this instruction, MachNode except for calls
1066 1072 const char *InstructForm::mach_base_class(FormDict &globals) const {
1067 1073 if( is_ideal_call() == Form::JAVA_STATIC ) {
1068 1074 return "MachCallStaticJavaNode";
1069 1075 }
1070 1076 else if( is_ideal_call() == Form::JAVA_DYNAMIC ) {
1071 1077 return "MachCallDynamicJavaNode";
1072 1078 }
1073 1079 else if( is_ideal_call() == Form::JAVA_RUNTIME ) {
1074 1080 return "MachCallRuntimeNode";
1075 1081 }
1076 1082 else if( is_ideal_call() == Form::JAVA_LEAF ) {
1077 1083 return "MachCallLeafNode";
1078 1084 }
1079 1085 else if (is_ideal_return()) {
1080 1086 return "MachReturnNode";
1081 1087 }
1082 1088 else if (is_ideal_halt()) {
1083 1089 return "MachHaltNode";
1084 1090 }
1085 1091 else if (is_ideal_safepoint()) {
1086 1092 return "MachSafePointNode";
↓ open down ↓ |
1011 lines elided |
↑ open up ↑ |
1087 1093 }
1088 1094 else if (is_ideal_if()) {
1089 1095 return "MachIfNode";
1090 1096 }
1091 1097 else if (is_ideal_fastlock()) {
1092 1098 return "MachFastLockNode";
1093 1099 }
1094 1100 else if (is_ideal_nop()) {
1095 1101 return "MachNopNode";
1096 1102 }
1103 + else if (is_mach_constant()) {
1104 + return "MachConstantNode";
1105 + }
1097 1106 else if (captures_bottom_type(globals)) {
1098 1107 return "MachTypeNode";
1099 1108 } else {
1100 1109 return "MachNode";
1101 1110 }
1102 1111 assert( false, "ShouldNotReachHere()");
1103 1112 return NULL;
1104 1113 }
1105 1114
1106 1115 // Compare the instruction predicates for textual equality
1107 1116 bool equivalent_predicates( const InstructForm *instr1, const InstructForm *instr2 ) {
1108 1117 const Predicate *pred1 = instr1->_predicate;
1109 1118 const Predicate *pred2 = instr2->_predicate;
1110 1119 if( pred1 == NULL && pred2 == NULL ) {
1111 1120 // no predicates means they are identical
1112 1121 return true;
1113 1122 }
1114 1123 if( pred1 != NULL && pred2 != NULL ) {
1115 1124 // compare the predicates
1116 1125 if (ADLParser::equivalent_expressions(pred1->_pred, pred2->_pred)) {
1117 1126 return true;
1118 1127 }
1119 1128 }
1120 1129
1121 1130 return false;
1122 1131 }
1123 1132
1124 1133 // Check if this instruction can cisc-spill to 'alternate'
1125 1134 bool InstructForm::cisc_spills_to(ArchDesc &AD, InstructForm *instr) {
1126 1135 assert( _matrule != NULL && instr->_matrule != NULL, "must have match rules");
1127 1136 // Do not replace if a cisc-version has been found.
1128 1137 if( cisc_spill_operand() != Not_cisc_spillable ) return false;
1129 1138
1130 1139 int cisc_spill_operand = Maybe_cisc_spillable;
1131 1140 char *result = NULL;
1132 1141 char *result2 = NULL;
1133 1142 const char *op_name = NULL;
1134 1143 const char *reg_type = NULL;
1135 1144 FormDict &globals = AD.globalNames();
1136 1145 cisc_spill_operand = _matrule->matchrule_cisc_spill_match(globals, AD.get_registers(), instr->_matrule, op_name, reg_type);
1137 1146 if( (cisc_spill_operand != Not_cisc_spillable) && (op_name != NULL) && equivalent_predicates(this, instr) ) {
1138 1147 cisc_spill_operand = operand_position(op_name, Component::USE);
1139 1148 int def_oper = operand_position(op_name, Component::DEF);
1140 1149 if( def_oper == NameList::Not_in_list && instr->num_opnds() == num_opnds()) {
1141 1150 // Do not support cisc-spilling for destination operands and
1142 1151 // make sure they have the same number of operands.
1143 1152 _cisc_spill_alternate = instr;
1144 1153 instr->set_cisc_alternate(true);
1145 1154 if( AD._cisc_spill_debug ) {
1146 1155 fprintf(stderr, "Instruction %s cisc-spills-to %s\n", _ident, instr->_ident);
1147 1156 fprintf(stderr, " using operand %s %s at index %d\n", reg_type, op_name, cisc_spill_operand);
1148 1157 }
1149 1158 // Record that a stack-version of the reg_mask is needed
1150 1159 // !!!!!
1151 1160 OperandForm *oper = (OperandForm*)(globals[reg_type]->is_operand());
1152 1161 assert( oper != NULL, "cisc-spilling non operand");
1153 1162 const char *reg_class_name = oper->constrained_reg_class();
1154 1163 AD.set_stack_or_reg(reg_class_name);
1155 1164 const char *reg_mask_name = AD.reg_mask(*oper);
1156 1165 set_cisc_reg_mask_name(reg_mask_name);
1157 1166 const char *stack_or_reg_mask_name = AD.stack_or_reg_mask(*oper);
1158 1167 } else {
1159 1168 cisc_spill_operand = Not_cisc_spillable;
1160 1169 }
1161 1170 } else {
1162 1171 cisc_spill_operand = Not_cisc_spillable;
1163 1172 }
1164 1173
1165 1174 set_cisc_spill_operand(cisc_spill_operand);
1166 1175 return (cisc_spill_operand != Not_cisc_spillable);
1167 1176 }
1168 1177
1169 1178 // Check to see if this instruction can be replaced with the short branch
1170 1179 // instruction `short-branch'
1171 1180 bool InstructForm::check_branch_variant(ArchDesc &AD, InstructForm *short_branch) {
1172 1181 if (_matrule != NULL &&
1173 1182 this != short_branch && // Don't match myself
1174 1183 !is_short_branch() && // Don't match another short branch variant
1175 1184 reduce_result() != NULL &&
1176 1185 strcmp(reduce_result(), short_branch->reduce_result()) == 0 &&
1177 1186 _matrule->equivalent(AD.globalNames(), short_branch->_matrule)) {
1178 1187 // The instructions are equivalent.
1179 1188 if (AD._short_branch_debug) {
1180 1189 fprintf(stderr, "Instruction %s has short form %s\n", _ident, short_branch->_ident);
1181 1190 }
1182 1191 _short_branch_form = short_branch;
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
1183 1192 return true;
1184 1193 }
1185 1194 return false;
1186 1195 }
1187 1196
1188 1197
1189 1198 // --------------------------- FILE *output_routines
1190 1199 //
1191 1200 // Generate the format call for the replacement variable
1192 1201 void InstructForm::rep_var_format(FILE *fp, const char *rep_var) {
1202 + // Handle special constant table variables.
1203 + if (strcmp(rep_var, "constanttablebase") == 0) {
1204 + fprintf(fp, "char reg[128]; ra->dump_register(in(mach_constant_base_node_input()), reg);\n");
1205 + fprintf(fp, "st->print(\"%%s\");\n");
1206 + return;
1207 + }
1208 + if (strcmp(rep_var, "constantoffset") == 0) {
1209 + fprintf(fp, "st->print(\"#%%d\", constant_offset());\n");
1210 + return;
1211 + }
1212 + if (strcmp(rep_var, "constantaddress") == 0) {
1213 + fprintf(fp, "st->print(\"constant table base + #%%d\", constant_offset());\n");
1214 + return;
1215 + }
1216 +
1193 1217 // Find replacement variable's type
1194 1218 const Form *form = _localNames[rep_var];
1195 1219 if (form == NULL) {
1196 1220 fprintf(stderr, "unknown replacement variable in format statement: '%s'\n", rep_var);
1197 1221 assert(false, "ShouldNotReachHere()");
1198 1222 }
1199 1223 OpClassForm *opc = form->is_opclass();
1200 1224 assert( opc, "replacement variable was not found in local names");
1201 1225 // Lookup the index position of the replacement variable
1202 1226 int idx = operand_position_format(rep_var);
1203 1227 if ( idx == -1 ) {
1204 1228 assert( strcmp(opc->_ident,"label")==0, "Unimplemented");
1205 1229 assert( false, "ShouldNotReachHere()");
1206 1230 }
1207 1231
1208 1232 if (is_noninput_operand(idx)) {
1209 1233 // This component isn't in the input array. Print out the static
1210 1234 // name of the register.
1211 1235 OperandForm* oper = form->is_operand();
1212 1236 if (oper != NULL && oper->is_bound_register()) {
1213 1237 const RegDef* first = oper->get_RegClass()->find_first_elem();
1214 1238 fprintf(fp, " tty->print(\"%s\");\n", first->_regname);
1215 1239 } else {
1216 1240 globalAD->syntax_err(_linenum, "In %s can't find format for %s %s", _ident, opc->_ident, rep_var);
1217 1241 }
1218 1242 } else {
1219 1243 // Output the format call for this operand
1220 1244 fprintf(fp,"opnd_array(%d)->",idx);
1221 1245 if (idx == 0)
1222 1246 fprintf(fp,"int_format(ra, this, st); // %s\n", rep_var);
1223 1247 else
1224 1248 fprintf(fp,"ext_format(ra, this,idx%d, st); // %s\n", idx, rep_var );
1225 1249 }
1226 1250 }
1227 1251
1228 1252 // Seach through operands to determine parameters unique positions.
1229 1253 void InstructForm::set_unique_opnds() {
1230 1254 uint* uniq_idx = NULL;
1231 1255 int nopnds = num_opnds();
1232 1256 uint num_uniq = nopnds;
1233 1257 int i;
1234 1258 _uniq_idx_length = 0;
1235 1259 if ( nopnds > 0 ) {
1236 1260 // Allocate index array. Worst case we're mapping from each
1237 1261 // component back to an index and any DEF always goes at 0 so the
1238 1262 // length of the array has to be the number of components + 1.
1239 1263 _uniq_idx_length = _components.count() + 1;
1240 1264 uniq_idx = (uint*) malloc(sizeof(uint)*(_uniq_idx_length));
1241 1265 for( i = 0; i < _uniq_idx_length; i++ ) {
1242 1266 uniq_idx[i] = i;
1243 1267 }
1244 1268 }
1245 1269 // Do it only if there is a match rule and no expand rule. With an
1246 1270 // expand rule it is done by creating new mach node in Expand()
1247 1271 // method.
1248 1272 if ( nopnds > 0 && _matrule != NULL && _exprule == NULL ) {
1249 1273 const char *name;
1250 1274 uint count;
1251 1275 bool has_dupl_use = false;
1252 1276
1253 1277 _parameters.reset();
1254 1278 while( (name = _parameters.iter()) != NULL ) {
1255 1279 count = 0;
1256 1280 int position = 0;
1257 1281 int uniq_position = 0;
1258 1282 _components.reset();
1259 1283 Component *comp = NULL;
1260 1284 if( sets_result() ) {
1261 1285 comp = _components.iter();
1262 1286 position++;
1263 1287 }
1264 1288 // The next code is copied from the method operand_position().
1265 1289 for (; (comp = _components.iter()) != NULL; ++position) {
1266 1290 // When the first component is not a DEF,
1267 1291 // leave space for the result operand!
1268 1292 if ( position==0 && (! comp->isa(Component::DEF)) ) {
1269 1293 ++position;
1270 1294 }
1271 1295 if( strcmp(name, comp->_name)==0 ) {
1272 1296 if( ++count > 1 ) {
1273 1297 assert(position < _uniq_idx_length, "out of bounds");
1274 1298 uniq_idx[position] = uniq_position;
1275 1299 has_dupl_use = true;
1276 1300 } else {
1277 1301 uniq_position = position;
1278 1302 }
1279 1303 }
1280 1304 if( comp->isa(Component::DEF)
1281 1305 && comp->isa(Component::USE) ) {
1282 1306 ++position;
1283 1307 if( position != 1 )
1284 1308 --position; // only use two slots for the 1st USE_DEF
1285 1309 }
1286 1310 }
1287 1311 }
1288 1312 if( has_dupl_use ) {
1289 1313 for( i = 1; i < nopnds; i++ )
1290 1314 if( i != uniq_idx[i] )
1291 1315 break;
1292 1316 int j = i;
1293 1317 for( ; i < nopnds; i++ )
1294 1318 if( i == uniq_idx[i] )
1295 1319 uniq_idx[i] = j++;
1296 1320 num_uniq = j;
1297 1321 }
1298 1322 }
1299 1323 _uniq_idx = uniq_idx;
1300 1324 _num_uniq = num_uniq;
1301 1325 }
1302 1326
1303 1327 // Generate index values needed for determining the operand position
1304 1328 void InstructForm::index_temps(FILE *fp, FormDict &globals, const char *prefix, const char *receiver) {
1305 1329 uint idx = 0; // position of operand in match rule
1306 1330 int cur_num_opnds = num_opnds();
1307 1331
1308 1332 // Compute the index into vector of operand pointers:
1309 1333 // idx0=0 is used to indicate that info comes from this same node, not from input edge.
1310 1334 // idx1 starts at oper_input_base()
1311 1335 if ( cur_num_opnds >= 1 ) {
1312 1336 fprintf(fp," // Start at oper_input_base() and count operands\n");
1313 1337 fprintf(fp," unsigned %sidx0 = %d;\n", prefix, oper_input_base(globals));
1314 1338 fprintf(fp," unsigned %sidx1 = %d;\n", prefix, oper_input_base(globals));
1315 1339
1316 1340 // Generate starting points for other unique operands if they exist
1317 1341 for ( idx = 2; idx < num_unique_opnds(); ++idx ) {
1318 1342 if( *receiver == 0 ) {
1319 1343 fprintf(fp," unsigned %sidx%d = %sidx%d + opnd_array(%d)->num_edges();\n",
1320 1344 prefix, idx, prefix, idx-1, idx-1 );
1321 1345 } else {
1322 1346 fprintf(fp," unsigned %sidx%d = %sidx%d + %s_opnds[%d]->num_edges();\n",
1323 1347 prefix, idx, prefix, idx-1, receiver, idx-1 );
1324 1348 }
1325 1349 }
1326 1350 }
1327 1351 if( *receiver != 0 ) {
1328 1352 // This value is used by generate_peepreplace when copying a node.
1329 1353 // Don't emit it in other cases since it can hide bugs with the
1330 1354 // use invalid idx's.
1331 1355 fprintf(fp," unsigned %sidx%d = %sreq(); \n", prefix, idx, receiver);
1332 1356 }
1333 1357
1334 1358 }
1335 1359
1336 1360 // ---------------------------
1337 1361 bool InstructForm::verify() {
1338 1362 // !!!!! !!!!!
1339 1363 // Check that a "label" operand occurs last in the operand list, if present
1340 1364 return true;
↓ open down ↓ |
138 lines elided |
↑ open up ↑ |
1341 1365 }
1342 1366
1343 1367 void InstructForm::dump() {
1344 1368 output(stderr);
1345 1369 }
1346 1370
1347 1371 void InstructForm::output(FILE *fp) {
1348 1372 fprintf(fp,"\nInstruction: %s\n", (_ident?_ident:""));
1349 1373 if (_matrule) _matrule->output(fp);
1350 1374 if (_insencode) _insencode->output(fp);
1375 + if (_constant) _constant->output(fp);
1351 1376 if (_opcode) _opcode->output(fp);
1352 1377 if (_attribs) _attribs->output(fp);
1353 1378 if (_predicate) _predicate->output(fp);
1354 1379 if (_effects.Size()) {
1355 1380 fprintf(fp,"Effects\n");
1356 1381 _effects.dump();
1357 1382 }
1358 1383 if (_exprule) _exprule->output(fp);
1359 1384 if (_rewrule) _rewrule->output(fp);
1360 1385 if (_format) _format->output(fp);
1361 1386 if (_peephole) _peephole->output(fp);
1362 1387 }
1363 1388
1364 1389 void MachNodeForm::dump() {
1365 1390 output(stderr);
1366 1391 }
1367 1392
1368 1393 void MachNodeForm::output(FILE *fp) {
1369 1394 fprintf(fp,"\nMachNode: %s\n", (_ident?_ident:""));
1370 1395 }
1371 1396
1372 1397 //------------------------------build_predicate--------------------------------
1373 1398 // Build instruction predicates. If the user uses the same operand name
1374 1399 // twice, we need to check that the operands are pointer-eequivalent in
1375 1400 // the DFA during the labeling process.
1376 1401 Predicate *InstructForm::build_predicate() {
1377 1402 char buf[1024], *s=buf;
1378 1403 Dict names(cmpstr,hashstr,Form::arena); // Map Names to counts
1379 1404
1380 1405 MatchNode *mnode =
1381 1406 strcmp(_matrule->_opType, "Set") ? _matrule : _matrule->_rChild;
1382 1407 mnode->count_instr_names(names);
1383 1408
1384 1409 uint first = 1;
1385 1410 // Start with the predicate supplied in the .ad file.
1386 1411 if( _predicate ) {
1387 1412 if( first ) first=0;
1388 1413 strcpy(s,"("); s += strlen(s);
1389 1414 strcpy(s,_predicate->_pred);
1390 1415 s += strlen(s);
1391 1416 strcpy(s,")"); s += strlen(s);
1392 1417 }
1393 1418 for( DictI i(&names); i.test(); ++i ) {
1394 1419 uintptr_t cnt = (uintptr_t)i._value;
1395 1420 if( cnt > 1 ) { // Need a predicate at all?
1396 1421 assert( cnt == 2, "Unimplemented" );
1397 1422 // Handle many pairs
1398 1423 if( first ) first=0;
1399 1424 else { // All tests must pass, so use '&&'
1400 1425 strcpy(s," && ");
1401 1426 s += strlen(s);
1402 1427 }
1403 1428 // Add predicate to working buffer
1404 1429 sprintf(s,"/*%s*/(",(char*)i._key);
1405 1430 s += strlen(s);
1406 1431 mnode->build_instr_pred(s,(char*)i._key,0);
1407 1432 s += strlen(s);
1408 1433 strcpy(s," == "); s += strlen(s);
1409 1434 mnode->build_instr_pred(s,(char*)i._key,1);
1410 1435 s += strlen(s);
1411 1436 strcpy(s,")"); s += strlen(s);
1412 1437 }
1413 1438 }
1414 1439 if( s == buf ) s = NULL;
1415 1440 else {
1416 1441 assert( strlen(buf) < sizeof(buf), "String buffer overflow" );
1417 1442 s = strdup(buf);
1418 1443 }
1419 1444 return new Predicate(s);
1420 1445 }
1421 1446
1422 1447 //------------------------------EncodeForm-------------------------------------
1423 1448 // Constructor
1424 1449 EncodeForm::EncodeForm()
1425 1450 : _encClass(cmpstr,hashstr, Form::arena) {
1426 1451 }
1427 1452 EncodeForm::~EncodeForm() {
1428 1453 }
1429 1454
1430 1455 // record a new register class
1431 1456 EncClass *EncodeForm::add_EncClass(const char *className) {
1432 1457 EncClass *encClass = new EncClass(className);
1433 1458 _eclasses.addName(className);
1434 1459 _encClass.Insert(className,encClass);
1435 1460 return encClass;
1436 1461 }
1437 1462
1438 1463 // Lookup the function body for an encoding class
1439 1464 EncClass *EncodeForm::encClass(const char *className) {
1440 1465 assert( className != NULL, "Must provide a defined encoding name");
1441 1466
1442 1467 EncClass *encClass = (EncClass*)_encClass[className];
1443 1468 return encClass;
1444 1469 }
1445 1470
1446 1471 // Lookup the function body for an encoding class
1447 1472 const char *EncodeForm::encClassBody(const char *className) {
1448 1473 if( className == NULL ) return NULL;
1449 1474
1450 1475 EncClass *encClass = (EncClass*)_encClass[className];
1451 1476 assert( encClass != NULL, "Encode Class is missing.");
1452 1477 encClass->_code.reset();
1453 1478 const char *code = (const char*)encClass->_code.iter();
1454 1479 assert( code != NULL, "Found an empty encode class body.");
1455 1480
1456 1481 return code;
1457 1482 }
1458 1483
1459 1484 // Lookup the function body for an encoding class
1460 1485 const char *EncodeForm::encClassPrototype(const char *className) {
1461 1486 assert( className != NULL, "Encode class name must be non NULL.");
1462 1487
1463 1488 return className;
1464 1489 }
1465 1490
1466 1491 void EncodeForm::dump() { // Debug printer
1467 1492 output(stderr);
1468 1493 }
1469 1494
1470 1495 void EncodeForm::output(FILE *fp) { // Write info to output files
1471 1496 const char *name;
1472 1497 fprintf(fp,"\n");
1473 1498 fprintf(fp,"-------------------- Dump EncodeForm --------------------\n");
1474 1499 for (_eclasses.reset(); (name = _eclasses.iter()) != NULL;) {
1475 1500 ((EncClass*)_encClass[name])->output(fp);
1476 1501 }
1477 1502 fprintf(fp,"-------------------- end EncodeForm --------------------\n");
1478 1503 }
1479 1504 //------------------------------EncClass---------------------------------------
1480 1505 EncClass::EncClass(const char *name)
1481 1506 : _localNames(cmpstr,hashstr, Form::arena), _name(name) {
1482 1507 }
1483 1508 EncClass::~EncClass() {
1484 1509 }
1485 1510
1486 1511 // Add a parameter <type,name> pair
1487 1512 void EncClass::add_parameter(const char *parameter_type, const char *parameter_name) {
1488 1513 _parameter_type.addName( parameter_type );
1489 1514 _parameter_name.addName( parameter_name );
1490 1515 }
1491 1516
1492 1517 // Verify operand types in parameter list
1493 1518 bool EncClass::check_parameter_types(FormDict &globals) {
1494 1519 // !!!!!
1495 1520 return false;
1496 1521 }
1497 1522
1498 1523 // Add the decomposed "code" sections of an encoding's code-block
1499 1524 void EncClass::add_code(const char *code) {
1500 1525 _code.addName(code);
1501 1526 }
1502 1527
1503 1528 // Add the decomposed "replacement variables" of an encoding's code-block
1504 1529 void EncClass::add_rep_var(char *replacement_var) {
1505 1530 _code.addName(NameList::_signal);
1506 1531 _rep_vars.addName(replacement_var);
1507 1532 }
1508 1533
1509 1534 // Lookup the function body for an encoding class
1510 1535 int EncClass::rep_var_index(const char *rep_var) {
1511 1536 uint position = 0;
1512 1537 const char *name = NULL;
1513 1538
1514 1539 _parameter_name.reset();
1515 1540 while ( (name = _parameter_name.iter()) != NULL ) {
1516 1541 if ( strcmp(rep_var,name) == 0 ) return position;
1517 1542 ++position;
1518 1543 }
1519 1544
1520 1545 return -1;
1521 1546 }
1522 1547
1523 1548 // Check after parsing
1524 1549 bool EncClass::verify() {
1525 1550 // 1!!!!
1526 1551 // Check that each replacement variable, '$name' in architecture description
1527 1552 // is actually a local variable for this encode class, or a reserved name
1528 1553 // "primary, secondary, tertiary"
1529 1554 return true;
1530 1555 }
1531 1556
1532 1557 void EncClass::dump() {
1533 1558 output(stderr);
1534 1559 }
1535 1560
1536 1561 // Write info to output files
1537 1562 void EncClass::output(FILE *fp) {
1538 1563 fprintf(fp,"EncClass: %s", (_name ? _name : ""));
1539 1564
1540 1565 // Output the parameter list
1541 1566 _parameter_type.reset();
1542 1567 _parameter_name.reset();
1543 1568 const char *type = _parameter_type.iter();
1544 1569 const char *name = _parameter_name.iter();
1545 1570 fprintf(fp, " ( ");
1546 1571 for ( ; (type != NULL) && (name != NULL);
1547 1572 (type = _parameter_type.iter()), (name = _parameter_name.iter()) ) {
1548 1573 fprintf(fp, " %s %s,", type, name);
1549 1574 }
1550 1575 fprintf(fp, " ) ");
1551 1576
1552 1577 // Output the code block
1553 1578 _code.reset();
1554 1579 _rep_vars.reset();
1555 1580 const char *code;
1556 1581 while ( (code = _code.iter()) != NULL ) {
1557 1582 if ( _code.is_signal(code) ) {
1558 1583 // A replacement variable
1559 1584 const char *rep_var = _rep_vars.iter();
1560 1585 fprintf(fp,"($%s)", rep_var);
1561 1586 } else {
1562 1587 // A section of code
1563 1588 fprintf(fp,"%s", code);
1564 1589 }
1565 1590 }
1566 1591
1567 1592 }
1568 1593
1569 1594 //------------------------------Opcode-----------------------------------------
1570 1595 Opcode::Opcode(char *primary, char *secondary, char *tertiary)
1571 1596 : _primary(primary), _secondary(secondary), _tertiary(tertiary) {
1572 1597 }
1573 1598
1574 1599 Opcode::~Opcode() {
1575 1600 }
1576 1601
1577 1602 Opcode::opcode_type Opcode::as_opcode_type(const char *param) {
1578 1603 if( strcmp(param,"primary") == 0 ) {
1579 1604 return Opcode::PRIMARY;
1580 1605 }
1581 1606 else if( strcmp(param,"secondary") == 0 ) {
1582 1607 return Opcode::SECONDARY;
1583 1608 }
1584 1609 else if( strcmp(param,"tertiary") == 0 ) {
1585 1610 return Opcode::TERTIARY;
1586 1611 }
1587 1612 return Opcode::NOT_AN_OPCODE;
1588 1613 }
1589 1614
1590 1615 bool Opcode::print_opcode(FILE *fp, Opcode::opcode_type desired_opcode) {
1591 1616 // Default values previously provided by MachNode::primary()...
1592 1617 const char *description = NULL;
1593 1618 const char *value = NULL;
1594 1619 // Check if user provided any opcode definitions
1595 1620 if( this != NULL ) {
1596 1621 // Update 'value' if user provided a definition in the instruction
1597 1622 switch (desired_opcode) {
1598 1623 case PRIMARY:
1599 1624 description = "primary()";
1600 1625 if( _primary != NULL) { value = _primary; }
1601 1626 break;
1602 1627 case SECONDARY:
1603 1628 description = "secondary()";
1604 1629 if( _secondary != NULL ) { value = _secondary; }
1605 1630 break;
1606 1631 case TERTIARY:
1607 1632 description = "tertiary()";
1608 1633 if( _tertiary != NULL ) { value = _tertiary; }
1609 1634 break;
1610 1635 default:
1611 1636 assert( false, "ShouldNotReachHere();");
1612 1637 break;
1613 1638 }
1614 1639 }
1615 1640 if (value != NULL) {
1616 1641 fprintf(fp, "(%s /*%s*/)", value, description);
1617 1642 }
1618 1643 return value != NULL;
1619 1644 }
1620 1645
1621 1646 void Opcode::dump() {
1622 1647 output(stderr);
1623 1648 }
1624 1649
1625 1650 // Write info to output files
1626 1651 void Opcode::output(FILE *fp) {
1627 1652 if (_primary != NULL) fprintf(fp,"Primary opcode: %s\n", _primary);
1628 1653 if (_secondary != NULL) fprintf(fp,"Secondary opcode: %s\n", _secondary);
1629 1654 if (_tertiary != NULL) fprintf(fp,"Tertiary opcode: %s\n", _tertiary);
1630 1655 }
1631 1656
1632 1657 //------------------------------InsEncode--------------------------------------
1633 1658 InsEncode::InsEncode() {
1634 1659 }
1635 1660 InsEncode::~InsEncode() {
1636 1661 }
1637 1662
1638 1663 // Add "encode class name" and its parameters
1639 1664 NameAndList *InsEncode::add_encode(char *encoding) {
1640 1665 assert( encoding != NULL, "Must provide name for encoding");
1641 1666
1642 1667 // add_parameter(NameList::_signal);
1643 1668 NameAndList *encode = new NameAndList(encoding);
1644 1669 _encoding.addName((char*)encode);
1645 1670
1646 1671 return encode;
1647 1672 }
1648 1673
1649 1674 // Access the list of encodings
1650 1675 void InsEncode::reset() {
1651 1676 _encoding.reset();
1652 1677 // _parameter.reset();
1653 1678 }
1654 1679 const char* InsEncode::encode_class_iter() {
1655 1680 NameAndList *encode_class = (NameAndList*)_encoding.iter();
1656 1681 return ( encode_class != NULL ? encode_class->name() : NULL );
1657 1682 }
1658 1683 // Obtain parameter name from zero based index
1659 1684 const char *InsEncode::rep_var_name(InstructForm &inst, uint param_no) {
1660 1685 NameAndList *params = (NameAndList*)_encoding.current();
1661 1686 assert( params != NULL, "Internal Error");
1662 1687 const char *param = (*params)[param_no];
1663 1688
1664 1689 // Remove '$' if parser placed it there.
1665 1690 return ( param != NULL && *param == '$') ? (param+1) : param;
1666 1691 }
1667 1692
1668 1693 void InsEncode::dump() {
1669 1694 output(stderr);
1670 1695 }
1671 1696
1672 1697 // Write info to output files
1673 1698 void InsEncode::output(FILE *fp) {
1674 1699 NameAndList *encoding = NULL;
1675 1700 const char *parameter = NULL;
1676 1701
1677 1702 fprintf(fp,"InsEncode: ");
1678 1703 _encoding.reset();
1679 1704
1680 1705 while ( (encoding = (NameAndList*)_encoding.iter()) != 0 ) {
1681 1706 // Output the encoding being used
1682 1707 fprintf(fp,"%s(", encoding->name() );
1683 1708
1684 1709 // Output its parameter list, if any
1685 1710 bool first_param = true;
1686 1711 encoding->reset();
1687 1712 while ( (parameter = encoding->iter()) != 0 ) {
1688 1713 // Output the ',' between parameters
1689 1714 if ( ! first_param ) fprintf(fp,", ");
1690 1715 first_param = false;
1691 1716 // Output the parameter
1692 1717 fprintf(fp,"%s", parameter);
1693 1718 } // done with parameters
1694 1719 fprintf(fp,") ");
1695 1720 } // done with encodings
1696 1721
1697 1722 fprintf(fp,"\n");
1698 1723 }
1699 1724
1700 1725 //------------------------------Effect-----------------------------------------
1701 1726 static int effect_lookup(const char *name) {
1702 1727 if(!strcmp(name, "USE")) return Component::USE;
1703 1728 if(!strcmp(name, "DEF")) return Component::DEF;
1704 1729 if(!strcmp(name, "USE_DEF")) return Component::USE_DEF;
1705 1730 if(!strcmp(name, "KILL")) return Component::KILL;
1706 1731 if(!strcmp(name, "USE_KILL")) return Component::USE_KILL;
1707 1732 if(!strcmp(name, "TEMP")) return Component::TEMP;
1708 1733 if(!strcmp(name, "INVALID")) return Component::INVALID;
1709 1734 assert( false,"Invalid effect name specified\n");
1710 1735 return Component::INVALID;
1711 1736 }
1712 1737
1713 1738 Effect::Effect(const char *name) : _name(name), _use_def(effect_lookup(name)) {
1714 1739 _ftype = Form::EFF;
1715 1740 }
1716 1741 Effect::~Effect() {
1717 1742 }
1718 1743
1719 1744 // Dynamic type check
1720 1745 Effect *Effect::is_effect() const {
1721 1746 return (Effect*)this;
1722 1747 }
1723 1748
1724 1749
1725 1750 // True if this component is equal to the parameter.
1726 1751 bool Effect::is(int use_def_kill_enum) const {
1727 1752 return (_use_def == use_def_kill_enum ? true : false);
1728 1753 }
1729 1754 // True if this component is used/def'd/kill'd as the parameter suggests.
1730 1755 bool Effect::isa(int use_def_kill_enum) const {
1731 1756 return (_use_def & use_def_kill_enum) == use_def_kill_enum;
1732 1757 }
1733 1758
1734 1759 void Effect::dump() {
1735 1760 output(stderr);
1736 1761 }
1737 1762
1738 1763 void Effect::output(FILE *fp) { // Write info to output files
1739 1764 fprintf(fp,"Effect: %s\n", (_name?_name:""));
1740 1765 }
1741 1766
1742 1767 //------------------------------ExpandRule-------------------------------------
1743 1768 ExpandRule::ExpandRule() : _expand_instrs(),
1744 1769 _newopconst(cmpstr, hashstr, Form::arena) {
1745 1770 _ftype = Form::EXP;
1746 1771 }
1747 1772
1748 1773 ExpandRule::~ExpandRule() { // Destructor
1749 1774 }
1750 1775
1751 1776 void ExpandRule::add_instruction(NameAndList *instruction_name_and_operand_list) {
1752 1777 _expand_instrs.addName((char*)instruction_name_and_operand_list);
1753 1778 }
1754 1779
1755 1780 void ExpandRule::reset_instructions() {
1756 1781 _expand_instrs.reset();
1757 1782 }
1758 1783
1759 1784 NameAndList* ExpandRule::iter_instructions() {
1760 1785 return (NameAndList*)_expand_instrs.iter();
1761 1786 }
1762 1787
1763 1788
1764 1789 void ExpandRule::dump() {
1765 1790 output(stderr);
1766 1791 }
1767 1792
1768 1793 void ExpandRule::output(FILE *fp) { // Write info to output files
1769 1794 NameAndList *expand_instr = NULL;
1770 1795 const char *opid = NULL;
1771 1796
1772 1797 fprintf(fp,"\nExpand Rule:\n");
1773 1798
1774 1799 // Iterate over the instructions 'node' expands into
1775 1800 for(reset_instructions(); (expand_instr = iter_instructions()) != NULL; ) {
1776 1801 fprintf(fp,"%s(", expand_instr->name());
1777 1802
1778 1803 // iterate over the operand list
1779 1804 for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) {
1780 1805 fprintf(fp,"%s ", opid);
1781 1806 }
1782 1807 fprintf(fp,");\n");
1783 1808 }
1784 1809 }
1785 1810
1786 1811 //------------------------------RewriteRule------------------------------------
1787 1812 RewriteRule::RewriteRule(char* params, char* block)
1788 1813 : _tempParams(params), _tempBlock(block) { }; // Constructor
1789 1814 RewriteRule::~RewriteRule() { // Destructor
1790 1815 }
1791 1816
1792 1817 void RewriteRule::dump() {
1793 1818 output(stderr);
1794 1819 }
1795 1820
1796 1821 void RewriteRule::output(FILE *fp) { // Write info to output files
1797 1822 fprintf(fp,"\nRewrite Rule:\n%s\n%s\n",
1798 1823 (_tempParams?_tempParams:""),
1799 1824 (_tempBlock?_tempBlock:""));
1800 1825 }
1801 1826
1802 1827
1803 1828 //==============================MachNodes======================================
1804 1829 //------------------------------MachNodeForm-----------------------------------
1805 1830 MachNodeForm::MachNodeForm(char *id)
1806 1831 : _ident(id) {
1807 1832 }
1808 1833
1809 1834 MachNodeForm::~MachNodeForm() {
1810 1835 }
1811 1836
1812 1837 MachNodeForm *MachNodeForm::is_machnode() const {
1813 1838 return (MachNodeForm*)this;
1814 1839 }
1815 1840
1816 1841 //==============================Operand Classes================================
1817 1842 //------------------------------OpClassForm------------------------------------
1818 1843 OpClassForm::OpClassForm(const char* id) : _ident(id) {
1819 1844 _ftype = Form::OPCLASS;
1820 1845 }
1821 1846
1822 1847 OpClassForm::~OpClassForm() {
1823 1848 }
1824 1849
1825 1850 bool OpClassForm::ideal_only() const { return 0; }
1826 1851
1827 1852 OpClassForm *OpClassForm::is_opclass() const {
1828 1853 return (OpClassForm*)this;
1829 1854 }
1830 1855
1831 1856 Form::InterfaceType OpClassForm::interface_type(FormDict &globals) const {
1832 1857 if( _oplst.count() == 0 ) return Form::no_interface;
1833 1858
1834 1859 // Check that my operands have the same interface type
1835 1860 Form::InterfaceType interface;
1836 1861 bool first = true;
1837 1862 NameList &op_list = (NameList &)_oplst;
1838 1863 op_list.reset();
1839 1864 const char *op_name;
1840 1865 while( (op_name = op_list.iter()) != NULL ) {
1841 1866 const Form *form = globals[op_name];
1842 1867 OperandForm *operand = form->is_operand();
1843 1868 assert( operand, "Entry in operand class that is not an operand");
1844 1869 if( first ) {
1845 1870 first = false;
1846 1871 interface = operand->interface_type(globals);
1847 1872 } else {
1848 1873 interface = (interface == operand->interface_type(globals) ? interface : Form::no_interface);
1849 1874 }
1850 1875 }
1851 1876 return interface;
1852 1877 }
1853 1878
1854 1879 bool OpClassForm::stack_slots_only(FormDict &globals) const {
1855 1880 if( _oplst.count() == 0 ) return false; // how?
1856 1881
1857 1882 NameList &op_list = (NameList &)_oplst;
1858 1883 op_list.reset();
1859 1884 const char *op_name;
1860 1885 while( (op_name = op_list.iter()) != NULL ) {
1861 1886 const Form *form = globals[op_name];
1862 1887 OperandForm *operand = form->is_operand();
1863 1888 assert( operand, "Entry in operand class that is not an operand");
1864 1889 if( !operand->stack_slots_only(globals) ) return false;
1865 1890 }
1866 1891 return true;
1867 1892 }
1868 1893
1869 1894
1870 1895 void OpClassForm::dump() {
1871 1896 output(stderr);
1872 1897 }
1873 1898
1874 1899 void OpClassForm::output(FILE *fp) {
1875 1900 const char *name;
1876 1901 fprintf(fp,"\nOperand Class: %s\n", (_ident?_ident:""));
1877 1902 fprintf(fp,"\nCount = %d\n", _oplst.count());
1878 1903 for(_oplst.reset(); (name = _oplst.iter()) != NULL;) {
1879 1904 fprintf(fp,"%s, ",name);
1880 1905 }
1881 1906 fprintf(fp,"\n");
1882 1907 }
1883 1908
1884 1909
1885 1910 //==============================Operands=======================================
1886 1911 //------------------------------OperandForm------------------------------------
1887 1912 OperandForm::OperandForm(const char* id)
1888 1913 : OpClassForm(id), _ideal_only(false),
1889 1914 _localNames(cmpstr, hashstr, Form::arena) {
1890 1915 _ftype = Form::OPER;
1891 1916
1892 1917 _matrule = NULL;
1893 1918 _interface = NULL;
1894 1919 _attribs = NULL;
1895 1920 _predicate = NULL;
1896 1921 _constraint= NULL;
1897 1922 _construct = NULL;
1898 1923 _format = NULL;
1899 1924 }
1900 1925 OperandForm::OperandForm(const char* id, bool ideal_only)
1901 1926 : OpClassForm(id), _ideal_only(ideal_only),
1902 1927 _localNames(cmpstr, hashstr, Form::arena) {
1903 1928 _ftype = Form::OPER;
1904 1929
1905 1930 _matrule = NULL;
1906 1931 _interface = NULL;
1907 1932 _attribs = NULL;
1908 1933 _predicate = NULL;
1909 1934 _constraint= NULL;
1910 1935 _construct = NULL;
1911 1936 _format = NULL;
1912 1937 }
1913 1938 OperandForm::~OperandForm() {
1914 1939 }
1915 1940
1916 1941
1917 1942 OperandForm *OperandForm::is_operand() const {
1918 1943 return (OperandForm*)this;
1919 1944 }
1920 1945
1921 1946 bool OperandForm::ideal_only() const {
1922 1947 return _ideal_only;
1923 1948 }
1924 1949
1925 1950 Form::InterfaceType OperandForm::interface_type(FormDict &globals) const {
1926 1951 if( _interface == NULL ) return Form::no_interface;
1927 1952
1928 1953 return _interface->interface_type(globals);
1929 1954 }
1930 1955
1931 1956
1932 1957 bool OperandForm::stack_slots_only(FormDict &globals) const {
1933 1958 if( _constraint == NULL ) return false;
1934 1959 return _constraint->stack_slots_only();
1935 1960 }
1936 1961
1937 1962
1938 1963 // Access op_cost attribute or return NULL.
1939 1964 const char* OperandForm::cost() {
1940 1965 for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) {
1941 1966 if( strcmp(cur->_ident,AttributeForm::_op_cost) == 0 ) {
1942 1967 return cur->_val;
1943 1968 }
1944 1969 }
1945 1970 return NULL;
1946 1971 }
1947 1972
1948 1973 // Return the number of leaves below this complex operand
1949 1974 uint OperandForm::num_leaves() const {
1950 1975 if ( ! _matrule) return 0;
1951 1976
1952 1977 int num_leaves = _matrule->_numleaves;
1953 1978 return num_leaves;
1954 1979 }
1955 1980
1956 1981 // Return the number of constants contained within this complex operand
1957 1982 uint OperandForm::num_consts(FormDict &globals) const {
1958 1983 if ( ! _matrule) return 0;
1959 1984
1960 1985 // This is a recursive invocation on all operands in the matchrule
1961 1986 return _matrule->num_consts(globals);
1962 1987 }
1963 1988
1964 1989 // Return the number of constants in match rule with specified type
1965 1990 uint OperandForm::num_consts(FormDict &globals, Form::DataType type) const {
1966 1991 if ( ! _matrule) return 0;
1967 1992
1968 1993 // This is a recursive invocation on all operands in the matchrule
1969 1994 return _matrule->num_consts(globals, type);
1970 1995 }
1971 1996
1972 1997 // Return the number of pointer constants contained within this complex operand
1973 1998 uint OperandForm::num_const_ptrs(FormDict &globals) const {
1974 1999 if ( ! _matrule) return 0;
1975 2000
1976 2001 // This is a recursive invocation on all operands in the matchrule
1977 2002 return _matrule->num_const_ptrs(globals);
1978 2003 }
1979 2004
1980 2005 uint OperandForm::num_edges(FormDict &globals) const {
1981 2006 uint edges = 0;
1982 2007 uint leaves = num_leaves();
1983 2008 uint consts = num_consts(globals);
1984 2009
1985 2010 // If we are matching a constant directly, there are no leaves.
1986 2011 edges = ( leaves > consts ) ? leaves - consts : 0;
1987 2012
1988 2013 // !!!!!
1989 2014 // Special case operands that do not have a corresponding ideal node.
1990 2015 if( (edges == 0) && (consts == 0) ) {
1991 2016 if( constrained_reg_class() != NULL ) {
1992 2017 edges = 1;
1993 2018 } else {
1994 2019 if( _matrule
1995 2020 && (_matrule->_lChild == NULL) && (_matrule->_rChild == NULL) ) {
1996 2021 const Form *form = globals[_matrule->_opType];
1997 2022 OperandForm *oper = form ? form->is_operand() : NULL;
1998 2023 if( oper ) {
1999 2024 return oper->num_edges(globals);
2000 2025 }
2001 2026 }
2002 2027 }
2003 2028 }
2004 2029
2005 2030 return edges;
2006 2031 }
2007 2032
2008 2033
2009 2034 // Check if this operand is usable for cisc-spilling
2010 2035 bool OperandForm::is_cisc_reg(FormDict &globals) const {
2011 2036 const char *ideal = ideal_type(globals);
2012 2037 bool is_cisc_reg = (ideal && (ideal_to_Reg_type(ideal) != none));
2013 2038 return is_cisc_reg;
2014 2039 }
2015 2040
2016 2041 bool OpClassForm::is_cisc_mem(FormDict &globals) const {
2017 2042 Form::InterfaceType my_interface = interface_type(globals);
2018 2043 return (my_interface == memory_interface);
2019 2044 }
2020 2045
2021 2046
2022 2047 // node matches ideal 'Bool'
2023 2048 bool OperandForm::is_ideal_bool() const {
2024 2049 if( _matrule == NULL ) return false;
2025 2050
2026 2051 return _matrule->is_ideal_bool();
2027 2052 }
2028 2053
2029 2054 // Require user's name for an sRegX to be stackSlotX
2030 2055 Form::DataType OperandForm::is_user_name_for_sReg() const {
2031 2056 DataType data_type = none;
2032 2057 if( _ident != NULL ) {
2033 2058 if( strcmp(_ident,"stackSlotI") == 0 ) data_type = Form::idealI;
2034 2059 else if( strcmp(_ident,"stackSlotP") == 0 ) data_type = Form::idealP;
2035 2060 else if( strcmp(_ident,"stackSlotD") == 0 ) data_type = Form::idealD;
2036 2061 else if( strcmp(_ident,"stackSlotF") == 0 ) data_type = Form::idealF;
2037 2062 else if( strcmp(_ident,"stackSlotL") == 0 ) data_type = Form::idealL;
2038 2063 }
2039 2064 assert((data_type == none) || (_matrule == NULL), "No match-rule for stackSlotX");
2040 2065
2041 2066 return data_type;
2042 2067 }
2043 2068
2044 2069
2045 2070 // Return ideal type, if there is a single ideal type for this operand
2046 2071 const char *OperandForm::ideal_type(FormDict &globals, RegisterForm *registers) const {
2047 2072 const char *type = NULL;
2048 2073 if (ideal_only()) type = _ident;
2049 2074 else if( _matrule == NULL ) {
2050 2075 // Check for condition code register
2051 2076 const char *rc_name = constrained_reg_class();
2052 2077 // !!!!!
2053 2078 if (rc_name == NULL) return NULL;
2054 2079 // !!!!! !!!!!
2055 2080 // Check constraints on result's register class
2056 2081 if( registers ) {
2057 2082 RegClass *reg_class = registers->getRegClass(rc_name);
2058 2083 assert( reg_class != NULL, "Register class is not defined");
2059 2084
2060 2085 // Check for ideal type of entries in register class, all are the same type
2061 2086 reg_class->reset();
2062 2087 RegDef *reg_def = reg_class->RegDef_iter();
2063 2088 assert( reg_def != NULL, "No entries in register class");
2064 2089 assert( reg_def->_idealtype != NULL, "Did not define ideal type for register");
2065 2090 // Return substring that names the register's ideal type
2066 2091 type = reg_def->_idealtype + 3;
2067 2092 assert( *(reg_def->_idealtype + 0) == 'O', "Expect Op_ prefix");
2068 2093 assert( *(reg_def->_idealtype + 1) == 'p', "Expect Op_ prefix");
2069 2094 assert( *(reg_def->_idealtype + 2) == '_', "Expect Op_ prefix");
2070 2095 }
2071 2096 }
2072 2097 else if( _matrule->_lChild == NULL && _matrule->_rChild == NULL ) {
2073 2098 // This operand matches a single type, at the top level.
2074 2099 // Check for ideal type
2075 2100 type = _matrule->_opType;
2076 2101 if( strcmp(type,"Bool") == 0 )
2077 2102 return "Bool";
2078 2103 // transitive lookup
2079 2104 const Form *frm = globals[type];
2080 2105 OperandForm *op = frm->is_operand();
2081 2106 type = op->ideal_type(globals, registers);
2082 2107 }
2083 2108 return type;
2084 2109 }
2085 2110
2086 2111
2087 2112 // If there is a single ideal type for this interface field, return it.
2088 2113 const char *OperandForm::interface_ideal_type(FormDict &globals,
2089 2114 const char *field) const {
2090 2115 const char *ideal_type = NULL;
2091 2116 const char *value = NULL;
2092 2117
2093 2118 // Check if "field" is valid for this operand's interface
2094 2119 if ( ! is_interface_field(field, value) ) return ideal_type;
2095 2120
2096 2121 // !!!!! !!!!! !!!!!
2097 2122 // If a valid field has a constant value, identify "ConI" or "ConP" or ...
2098 2123
2099 2124 // Else, lookup type of field's replacement variable
2100 2125
2101 2126 return ideal_type;
2102 2127 }
2103 2128
2104 2129
2105 2130 RegClass* OperandForm::get_RegClass() const {
2106 2131 if (_interface && !_interface->is_RegInterface()) return NULL;
2107 2132 return globalAD->get_registers()->getRegClass(constrained_reg_class());
2108 2133 }
2109 2134
2110 2135
2111 2136 bool OperandForm::is_bound_register() const {
2112 2137 RegClass *reg_class = get_RegClass();
2113 2138 if (reg_class == NULL) return false;
2114 2139
2115 2140 const char * name = ideal_type(globalAD->globalNames());
2116 2141 if (name == NULL) return false;
2117 2142
2118 2143 int size = 0;
2119 2144 if (strcmp(name,"RegFlags")==0) size = 1;
2120 2145 if (strcmp(name,"RegI")==0) size = 1;
2121 2146 if (strcmp(name,"RegF")==0) size = 1;
2122 2147 if (strcmp(name,"RegD")==0) size = 2;
2123 2148 if (strcmp(name,"RegL")==0) size = 2;
2124 2149 if (strcmp(name,"RegN")==0) size = 1;
2125 2150 if (strcmp(name,"RegP")==0) size = globalAD->get_preproc_def("_LP64") ? 2 : 1;
2126 2151 if (size == 0) return false;
2127 2152 return size == reg_class->size();
2128 2153 }
2129 2154
2130 2155
2131 2156 // Check if this is a valid field for this operand,
2132 2157 // Return 'true' if valid, and set the value to the string the user provided.
2133 2158 bool OperandForm::is_interface_field(const char *field,
2134 2159 const char * &value) const {
2135 2160 return false;
2136 2161 }
2137 2162
2138 2163
2139 2164 // Return register class name if a constraint specifies the register class.
2140 2165 const char *OperandForm::constrained_reg_class() const {
2141 2166 const char *reg_class = NULL;
2142 2167 if ( _constraint ) {
2143 2168 // !!!!!
2144 2169 Constraint *constraint = _constraint;
2145 2170 if ( strcmp(_constraint->_func,"ALLOC_IN_RC") == 0 ) {
2146 2171 reg_class = _constraint->_arg;
2147 2172 }
2148 2173 }
2149 2174
2150 2175 return reg_class;
2151 2176 }
2152 2177
2153 2178
2154 2179 // Return the register class associated with 'leaf'.
2155 2180 const char *OperandForm::in_reg_class(uint leaf, FormDict &globals) {
2156 2181 const char *reg_class = NULL; // "RegMask::Empty";
2157 2182
2158 2183 if((_matrule == NULL) || (_matrule->is_chain_rule(globals))) {
2159 2184 reg_class = constrained_reg_class();
2160 2185 return reg_class;
2161 2186 }
2162 2187 const char *result = NULL;
2163 2188 const char *name = NULL;
2164 2189 const char *type = NULL;
2165 2190 // iterate through all base operands
2166 2191 // until we reach the register that corresponds to "leaf"
2167 2192 // This function is not looking for an ideal type. It needs the first
2168 2193 // level user type associated with the leaf.
2169 2194 for(uint idx = 0;_matrule->base_operand(idx,globals,result,name,type);++idx) {
2170 2195 const Form *form = (_localNames[name] ? _localNames[name] : globals[result]);
2171 2196 OperandForm *oper = form ? form->is_operand() : NULL;
2172 2197 if( oper ) {
2173 2198 reg_class = oper->constrained_reg_class();
2174 2199 if( reg_class ) {
2175 2200 reg_class = reg_class;
2176 2201 } else {
2177 2202 // ShouldNotReachHere();
2178 2203 }
2179 2204 } else {
2180 2205 // ShouldNotReachHere();
2181 2206 }
2182 2207
2183 2208 // Increment our target leaf position if current leaf is not a candidate.
2184 2209 if( reg_class == NULL) ++leaf;
2185 2210 // Exit the loop with the value of reg_class when at the correct index
2186 2211 if( idx == leaf ) break;
2187 2212 // May iterate through all base operands if reg_class for 'leaf' is NULL
2188 2213 }
2189 2214 return reg_class;
2190 2215 }
2191 2216
2192 2217
2193 2218 // Recursive call to construct list of top-level operands.
2194 2219 // Implementation does not modify state of internal structures
2195 2220 void OperandForm::build_components() {
2196 2221 if (_matrule) _matrule->append_components(_localNames, _components);
2197 2222
2198 2223 // Add parameters that "do not appear in match rule".
2199 2224 const char *name;
2200 2225 for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
2201 2226 OperandForm *opForm = (OperandForm*)_localNames[name];
2202 2227
2203 2228 if ( _components.operand_position(name) == -1 ) {
2204 2229 _components.insert(name, opForm->_ident, Component::INVALID, false);
2205 2230 }
2206 2231 }
2207 2232
2208 2233 return;
2209 2234 }
2210 2235
2211 2236 int OperandForm::operand_position(const char *name, int usedef) {
2212 2237 return _components.operand_position(name, usedef);
2213 2238 }
2214 2239
2215 2240
2216 2241 // Return zero-based position in component list, only counting constants;
2217 2242 // Return -1 if not in list.
2218 2243 int OperandForm::constant_position(FormDict &globals, const Component *last) {
2219 2244 // Iterate through components and count constants preceding 'constant'
2220 2245 int position = 0;
2221 2246 Component *comp;
2222 2247 _components.reset();
2223 2248 while( (comp = _components.iter()) != NULL && (comp != last) ) {
2224 2249 // Special case for operands that take a single user-defined operand
2225 2250 // Skip the initial definition in the component list.
2226 2251 if( strcmp(comp->_name,this->_ident) == 0 ) continue;
2227 2252
2228 2253 const char *type = comp->_type;
2229 2254 // Lookup operand form for replacement variable's type
2230 2255 const Form *form = globals[type];
2231 2256 assert( form != NULL, "Component's type not found");
2232 2257 OperandForm *oper = form ? form->is_operand() : NULL;
2233 2258 if( oper ) {
2234 2259 if( oper->_matrule->is_base_constant(globals) != Form::none ) {
2235 2260 ++position;
2236 2261 }
2237 2262 }
2238 2263 }
2239 2264
2240 2265 // Check for being passed a component that was not in the list
2241 2266 if( comp != last ) position = -1;
2242 2267
2243 2268 return position;
2244 2269 }
2245 2270 // Provide position of constant by "name"
2246 2271 int OperandForm::constant_position(FormDict &globals, const char *name) {
2247 2272 const Component *comp = _components.search(name);
2248 2273 int idx = constant_position( globals, comp );
2249 2274
2250 2275 return idx;
2251 2276 }
2252 2277
2253 2278
2254 2279 // Return zero-based position in component list, only counting constants;
2255 2280 // Return -1 if not in list.
2256 2281 int OperandForm::register_position(FormDict &globals, const char *reg_name) {
2257 2282 // Iterate through components and count registers preceding 'last'
2258 2283 uint position = 0;
2259 2284 Component *comp;
2260 2285 _components.reset();
2261 2286 while( (comp = _components.iter()) != NULL
2262 2287 && (strcmp(comp->_name,reg_name) != 0) ) {
2263 2288 // Special case for operands that take a single user-defined operand
2264 2289 // Skip the initial definition in the component list.
2265 2290 if( strcmp(comp->_name,this->_ident) == 0 ) continue;
2266 2291
2267 2292 const char *type = comp->_type;
2268 2293 // Lookup operand form for component's type
2269 2294 const Form *form = globals[type];
2270 2295 assert( form != NULL, "Component's type not found");
2271 2296 OperandForm *oper = form ? form->is_operand() : NULL;
2272 2297 if( oper ) {
2273 2298 if( oper->_matrule->is_base_register(globals) ) {
2274 2299 ++position;
2275 2300 }
2276 2301 }
2277 2302 }
2278 2303
2279 2304 return position;
2280 2305 }
2281 2306
2282 2307
2283 2308 const char *OperandForm::reduce_result() const {
2284 2309 return _ident;
2285 2310 }
2286 2311 // Return the name of the operand on the right hand side of the binary match
2287 2312 // Return NULL if there is no right hand side
2288 2313 const char *OperandForm::reduce_right(FormDict &globals) const {
2289 2314 return ( _matrule ? _matrule->reduce_right(globals) : NULL );
2290 2315 }
2291 2316
2292 2317 // Similar for left
2293 2318 const char *OperandForm::reduce_left(FormDict &globals) const {
2294 2319 return ( _matrule ? _matrule->reduce_left(globals) : NULL );
2295 2320 }
2296 2321
2297 2322
2298 2323 // --------------------------- FILE *output_routines
2299 2324 //
2300 2325 // Output code for disp_is_oop, if true.
2301 2326 void OperandForm::disp_is_oop(FILE *fp, FormDict &globals) {
2302 2327 // Check it is a memory interface with a non-user-constant disp field
2303 2328 if ( this->_interface == NULL ) return;
2304 2329 MemInterface *mem_interface = this->_interface->is_MemInterface();
2305 2330 if ( mem_interface == NULL ) return;
2306 2331 const char *disp = mem_interface->_disp;
2307 2332 if ( *disp != '$' ) return;
2308 2333
2309 2334 // Lookup replacement variable in operand's component list
2310 2335 const char *rep_var = disp + 1;
2311 2336 const Component *comp = this->_components.search(rep_var);
2312 2337 assert( comp != NULL, "Replacement variable not found in components");
2313 2338 // Lookup operand form for replacement variable's type
2314 2339 const char *type = comp->_type;
2315 2340 Form *form = (Form*)globals[type];
2316 2341 assert( form != NULL, "Replacement variable's type not found");
2317 2342 OperandForm *op = form->is_operand();
2318 2343 assert( op, "Memory Interface 'disp' can only emit an operand form");
2319 2344 // Check if this is a ConP, which may require relocation
2320 2345 if ( op->is_base_constant(globals) == Form::idealP ) {
2321 2346 // Find the constant's index: _c0, _c1, _c2, ... , _cN
2322 2347 uint idx = op->constant_position( globals, rep_var);
2323 2348 fprintf(fp," virtual bool disp_is_oop() const {");
2324 2349 fprintf(fp, " return _c%d->isa_oop_ptr();", idx);
2325 2350 fprintf(fp, " }\n");
2326 2351 }
2327 2352 }
2328 2353
2329 2354 // Generate code for internal and external format methods
2330 2355 //
2331 2356 // internal access to reg# node->_idx
2332 2357 // access to subsumed constant _c0, _c1,
2333 2358 void OperandForm::int_format(FILE *fp, FormDict &globals, uint index) {
2334 2359 Form::DataType dtype;
2335 2360 if (_matrule && (_matrule->is_base_register(globals) ||
2336 2361 strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) {
2337 2362 // !!!!! !!!!!
2338 2363 fprintf(fp, "{ char reg_str[128];\n");
2339 2364 fprintf(fp," ra->dump_register(node,reg_str);\n");
2340 2365 fprintf(fp," tty->print(\"%cs\",reg_str);\n",'%');
2341 2366 fprintf(fp," }\n");
2342 2367 } else if (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) {
2343 2368 format_constant( fp, index, dtype );
2344 2369 } else if (ideal_to_sReg_type(_ident) != Form::none) {
2345 2370 // Special format for Stack Slot Register
2346 2371 fprintf(fp, "{ char reg_str[128];\n");
2347 2372 fprintf(fp," ra->dump_register(node,reg_str);\n");
2348 2373 fprintf(fp," tty->print(\"%cs\",reg_str);\n",'%');
2349 2374 fprintf(fp," }\n");
2350 2375 } else {
2351 2376 fprintf(fp,"tty->print(\"No format defined for %s\n\");\n", _ident);
2352 2377 fflush(fp);
2353 2378 fprintf(stderr,"No format defined for %s\n", _ident);
2354 2379 dump();
2355 2380 assert( false,"Internal error:\n output_internal_operand() attempting to output other than a Register or Constant");
2356 2381 }
2357 2382 }
2358 2383
2359 2384 // Similar to "int_format" but for cases where data is external to operand
2360 2385 // external access to reg# node->in(idx)->_idx,
2361 2386 void OperandForm::ext_format(FILE *fp, FormDict &globals, uint index) {
2362 2387 Form::DataType dtype;
2363 2388 if (_matrule && (_matrule->is_base_register(globals) ||
2364 2389 strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) {
2365 2390 fprintf(fp, "{ char reg_str[128];\n");
2366 2391 fprintf(fp," ra->dump_register(node->in(idx");
2367 2392 if ( index != 0 ) fprintf(fp, "+%d",index);
2368 2393 fprintf(fp, "),reg_str);\n");
2369 2394 fprintf(fp," tty->print(\"%cs\",reg_str);\n",'%');
2370 2395 fprintf(fp," }\n");
2371 2396 } else if (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) {
2372 2397 format_constant( fp, index, dtype );
2373 2398 } else if (ideal_to_sReg_type(_ident) != Form::none) {
2374 2399 // Special format for Stack Slot Register
2375 2400 fprintf(fp, "{ char reg_str[128];\n");
2376 2401 fprintf(fp," ra->dump_register(node->in(idx");
2377 2402 if ( index != 0 ) fprintf(fp, "+%d",index);
2378 2403 fprintf(fp, "),reg_str);\n");
2379 2404 fprintf(fp," tty->print(\"%cs\",reg_str);\n",'%');
2380 2405 fprintf(fp," }\n");
2381 2406 } else {
2382 2407 fprintf(fp,"tty->print(\"No format defined for %s\n\");\n", _ident);
2383 2408 assert( false,"Internal error:\n output_external_operand() attempting to output other than a Register or Constant");
2384 2409 }
2385 2410 }
2386 2411
2387 2412 void OperandForm::format_constant(FILE *fp, uint const_index, uint const_type) {
2388 2413 switch(const_type) {
2389 2414 case Form::idealI: fprintf(fp,"st->print(\"#%%d\", _c%d);\n", const_index); break;
2390 2415 case Form::idealP: fprintf(fp,"_c%d->dump_on(st);\n", const_index); break;
2391 2416 case Form::idealN: fprintf(fp,"_c%d->dump_on(st);\n", const_index); break;
2392 2417 case Form::idealL: fprintf(fp,"st->print(\"#%%lld\", _c%d);\n", const_index); break;
2393 2418 case Form::idealF: fprintf(fp,"st->print(\"#%%f\", _c%d);\n", const_index); break;
2394 2419 case Form::idealD: fprintf(fp,"st->print(\"#%%f\", _c%d);\n", const_index); break;
2395 2420 default:
2396 2421 assert( false, "ShouldNotReachHere()");
2397 2422 }
2398 2423 }
2399 2424
2400 2425 // Return the operand form corresponding to the given index, else NULL.
2401 2426 OperandForm *OperandForm::constant_operand(FormDict &globals,
2402 2427 uint index) {
2403 2428 // !!!!!
2404 2429 // Check behavior on complex operands
2405 2430 uint n_consts = num_consts(globals);
2406 2431 if( n_consts > 0 ) {
2407 2432 uint i = 0;
2408 2433 const char *type;
2409 2434 Component *comp;
2410 2435 _components.reset();
2411 2436 if ((comp = _components.iter()) == NULL) {
2412 2437 assert(n_consts == 1, "Bad component list detected.\n");
2413 2438 // Current operand is THE operand
2414 2439 if ( index == 0 ) {
2415 2440 return this;
2416 2441 }
2417 2442 } // end if NULL
2418 2443 else {
2419 2444 // Skip the first component, it can not be a DEF of a constant
2420 2445 do {
2421 2446 type = comp->base_type(globals);
2422 2447 // Check that "type" is a 'ConI', 'ConP', ...
2423 2448 if ( ideal_to_const_type(type) != Form::none ) {
2424 2449 // When at correct component, get corresponding Operand
2425 2450 if ( index == 0 ) {
2426 2451 return globals[comp->_type]->is_operand();
2427 2452 }
2428 2453 // Decrement number of constants to go
2429 2454 --index;
2430 2455 }
2431 2456 } while((comp = _components.iter()) != NULL);
2432 2457 }
2433 2458 }
2434 2459
2435 2460 // Did not find a constant for this index.
2436 2461 return NULL;
2437 2462 }
2438 2463
2439 2464 // If this operand has a single ideal type, return its type
2440 2465 Form::DataType OperandForm::simple_type(FormDict &globals) const {
2441 2466 const char *type_name = ideal_type(globals);
2442 2467 Form::DataType type = type_name ? ideal_to_const_type( type_name )
2443 2468 : Form::none;
2444 2469 return type;
2445 2470 }
2446 2471
2447 2472 Form::DataType OperandForm::is_base_constant(FormDict &globals) const {
2448 2473 if ( _matrule == NULL ) return Form::none;
2449 2474
2450 2475 return _matrule->is_base_constant(globals);
2451 2476 }
2452 2477
2453 2478 // "true" if this operand is a simple type that is swallowed
2454 2479 bool OperandForm::swallowed(FormDict &globals) const {
2455 2480 Form::DataType type = simple_type(globals);
2456 2481 if( type != Form::none ) {
2457 2482 return true;
2458 2483 }
2459 2484
2460 2485 return false;
2461 2486 }
2462 2487
2463 2488 // Output code to access the value of the index'th constant
2464 2489 void OperandForm::access_constant(FILE *fp, FormDict &globals,
2465 2490 uint const_index) {
2466 2491 OperandForm *oper = constant_operand(globals, const_index);
2467 2492 assert( oper, "Index exceeds number of constants in operand");
2468 2493 Form::DataType dtype = oper->is_base_constant(globals);
2469 2494
2470 2495 switch(dtype) {
2471 2496 case idealI: fprintf(fp,"_c%d", const_index); break;
2472 2497 case idealP: fprintf(fp,"_c%d->get_con()",const_index); break;
2473 2498 case idealL: fprintf(fp,"_c%d", const_index); break;
2474 2499 case idealF: fprintf(fp,"_c%d", const_index); break;
2475 2500 case idealD: fprintf(fp,"_c%d", const_index); break;
2476 2501 default:
2477 2502 assert( false, "ShouldNotReachHere()");
2478 2503 }
2479 2504 }
2480 2505
2481 2506
2482 2507 void OperandForm::dump() {
2483 2508 output(stderr);
2484 2509 }
2485 2510
2486 2511 void OperandForm::output(FILE *fp) {
2487 2512 fprintf(fp,"\nOperand: %s\n", (_ident?_ident:""));
2488 2513 if (_matrule) _matrule->dump();
2489 2514 if (_interface) _interface->dump();
2490 2515 if (_attribs) _attribs->dump();
2491 2516 if (_predicate) _predicate->dump();
2492 2517 if (_constraint) _constraint->dump();
2493 2518 if (_construct) _construct->dump();
2494 2519 if (_format) _format->dump();
2495 2520 }
2496 2521
2497 2522 //------------------------------Constraint-------------------------------------
2498 2523 Constraint::Constraint(const char *func, const char *arg)
2499 2524 : _func(func), _arg(arg) {
2500 2525 }
2501 2526 Constraint::~Constraint() { /* not owner of char* */
2502 2527 }
2503 2528
2504 2529 bool Constraint::stack_slots_only() const {
2505 2530 return strcmp(_func, "ALLOC_IN_RC") == 0
2506 2531 && strcmp(_arg, "stack_slots") == 0;
2507 2532 }
2508 2533
2509 2534 void Constraint::dump() {
2510 2535 output(stderr);
2511 2536 }
2512 2537
2513 2538 void Constraint::output(FILE *fp) { // Write info to output files
2514 2539 assert((_func != NULL && _arg != NULL),"missing constraint function or arg");
2515 2540 fprintf(fp,"Constraint: %s ( %s )\n", _func, _arg);
2516 2541 }
2517 2542
2518 2543 //------------------------------Predicate--------------------------------------
2519 2544 Predicate::Predicate(char *pr)
2520 2545 : _pred(pr) {
2521 2546 }
2522 2547 Predicate::~Predicate() {
2523 2548 }
2524 2549
2525 2550 void Predicate::dump() {
2526 2551 output(stderr);
2527 2552 }
2528 2553
2529 2554 void Predicate::output(FILE *fp) {
2530 2555 fprintf(fp,"Predicate"); // Write to output files
2531 2556 }
2532 2557 //------------------------------Interface--------------------------------------
2533 2558 Interface::Interface(const char *name) : _name(name) {
2534 2559 }
2535 2560 Interface::~Interface() {
2536 2561 }
2537 2562
2538 2563 Form::InterfaceType Interface::interface_type(FormDict &globals) const {
2539 2564 Interface *thsi = (Interface*)this;
2540 2565 if ( thsi->is_RegInterface() ) return Form::register_interface;
2541 2566 if ( thsi->is_MemInterface() ) return Form::memory_interface;
2542 2567 if ( thsi->is_ConstInterface() ) return Form::constant_interface;
2543 2568 if ( thsi->is_CondInterface() ) return Form::conditional_interface;
2544 2569
2545 2570 return Form::no_interface;
2546 2571 }
2547 2572
2548 2573 RegInterface *Interface::is_RegInterface() {
2549 2574 if ( strcmp(_name,"REG_INTER") != 0 )
2550 2575 return NULL;
2551 2576 return (RegInterface*)this;
2552 2577 }
2553 2578 MemInterface *Interface::is_MemInterface() {
2554 2579 if ( strcmp(_name,"MEMORY_INTER") != 0 ) return NULL;
2555 2580 return (MemInterface*)this;
2556 2581 }
2557 2582 ConstInterface *Interface::is_ConstInterface() {
2558 2583 if ( strcmp(_name,"CONST_INTER") != 0 ) return NULL;
2559 2584 return (ConstInterface*)this;
2560 2585 }
2561 2586 CondInterface *Interface::is_CondInterface() {
2562 2587 if ( strcmp(_name,"COND_INTER") != 0 ) return NULL;
2563 2588 return (CondInterface*)this;
2564 2589 }
2565 2590
2566 2591
2567 2592 void Interface::dump() {
2568 2593 output(stderr);
2569 2594 }
2570 2595
2571 2596 // Write info to output files
2572 2597 void Interface::output(FILE *fp) {
2573 2598 fprintf(fp,"Interface: %s\n", (_name ? _name : "") );
2574 2599 }
2575 2600
2576 2601 //------------------------------RegInterface-----------------------------------
2577 2602 RegInterface::RegInterface() : Interface("REG_INTER") {
2578 2603 }
2579 2604 RegInterface::~RegInterface() {
2580 2605 }
2581 2606
2582 2607 void RegInterface::dump() {
2583 2608 output(stderr);
2584 2609 }
2585 2610
2586 2611 // Write info to output files
2587 2612 void RegInterface::output(FILE *fp) {
2588 2613 Interface::output(fp);
2589 2614 }
2590 2615
2591 2616 //------------------------------ConstInterface---------------------------------
2592 2617 ConstInterface::ConstInterface() : Interface("CONST_INTER") {
2593 2618 }
2594 2619 ConstInterface::~ConstInterface() {
2595 2620 }
2596 2621
2597 2622 void ConstInterface::dump() {
2598 2623 output(stderr);
2599 2624 }
2600 2625
2601 2626 // Write info to output files
2602 2627 void ConstInterface::output(FILE *fp) {
2603 2628 Interface::output(fp);
2604 2629 }
2605 2630
2606 2631 //------------------------------MemInterface-----------------------------------
2607 2632 MemInterface::MemInterface(char *base, char *index, char *scale, char *disp)
2608 2633 : Interface("MEMORY_INTER"), _base(base), _index(index), _scale(scale), _disp(disp) {
2609 2634 }
2610 2635 MemInterface::~MemInterface() {
2611 2636 // not owner of any character arrays
2612 2637 }
2613 2638
2614 2639 void MemInterface::dump() {
2615 2640 output(stderr);
2616 2641 }
2617 2642
2618 2643 // Write info to output files
2619 2644 void MemInterface::output(FILE *fp) {
2620 2645 Interface::output(fp);
2621 2646 if ( _base != NULL ) fprintf(fp," base == %s\n", _base);
2622 2647 if ( _index != NULL ) fprintf(fp," index == %s\n", _index);
2623 2648 if ( _scale != NULL ) fprintf(fp," scale == %s\n", _scale);
2624 2649 if ( _disp != NULL ) fprintf(fp," disp == %s\n", _disp);
2625 2650 // fprintf(fp,"\n");
2626 2651 }
2627 2652
2628 2653 //------------------------------CondInterface----------------------------------
2629 2654 CondInterface::CondInterface(const char* equal, const char* equal_format,
2630 2655 const char* not_equal, const char* not_equal_format,
2631 2656 const char* less, const char* less_format,
2632 2657 const char* greater_equal, const char* greater_equal_format,
2633 2658 const char* less_equal, const char* less_equal_format,
2634 2659 const char* greater, const char* greater_format)
2635 2660 : Interface("COND_INTER"),
2636 2661 _equal(equal), _equal_format(equal_format),
2637 2662 _not_equal(not_equal), _not_equal_format(not_equal_format),
2638 2663 _less(less), _less_format(less_format),
2639 2664 _greater_equal(greater_equal), _greater_equal_format(greater_equal_format),
2640 2665 _less_equal(less_equal), _less_equal_format(less_equal_format),
2641 2666 _greater(greater), _greater_format(greater_format) {
2642 2667 }
2643 2668 CondInterface::~CondInterface() {
2644 2669 // not owner of any character arrays
2645 2670 }
2646 2671
2647 2672 void CondInterface::dump() {
2648 2673 output(stderr);
2649 2674 }
2650 2675
2651 2676 // Write info to output files
2652 2677 void CondInterface::output(FILE *fp) {
2653 2678 Interface::output(fp);
2654 2679 if ( _equal != NULL ) fprintf(fp," equal == %s\n", _equal);
2655 2680 if ( _not_equal != NULL ) fprintf(fp," not_equal == %s\n", _not_equal);
2656 2681 if ( _less != NULL ) fprintf(fp," less == %s\n", _less);
2657 2682 if ( _greater_equal != NULL ) fprintf(fp," greater_equal == %s\n", _greater_equal);
2658 2683 if ( _less_equal != NULL ) fprintf(fp," less_equal == %s\n", _less_equal);
2659 2684 if ( _greater != NULL ) fprintf(fp," greater == %s\n", _greater);
2660 2685 // fprintf(fp,"\n");
2661 2686 }
2662 2687
2663 2688 //------------------------------ConstructRule----------------------------------
2664 2689 ConstructRule::ConstructRule(char *cnstr)
2665 2690 : _construct(cnstr) {
2666 2691 }
2667 2692 ConstructRule::~ConstructRule() {
2668 2693 }
2669 2694
2670 2695 void ConstructRule::dump() {
2671 2696 output(stderr);
2672 2697 }
2673 2698
2674 2699 void ConstructRule::output(FILE *fp) {
2675 2700 fprintf(fp,"\nConstruct Rule\n"); // Write to output files
2676 2701 }
2677 2702
2678 2703
2679 2704 //==============================Shared Forms===================================
2680 2705 //------------------------------AttributeForm----------------------------------
2681 2706 int AttributeForm::_insId = 0; // start counter at 0
2682 2707 int AttributeForm::_opId = 0; // start counter at 0
2683 2708 const char* AttributeForm::_ins_cost = "ins_cost"; // required name
2684 2709 const char* AttributeForm::_ins_pc_relative = "ins_pc_relative";
2685 2710 const char* AttributeForm::_op_cost = "op_cost"; // required name
2686 2711
2687 2712 AttributeForm::AttributeForm(char *attr, int type, char *attrdef)
2688 2713 : Form(Form::ATTR), _attrname(attr), _atype(type), _attrdef(attrdef) {
2689 2714 if (type==OP_ATTR) {
2690 2715 id = ++_opId;
2691 2716 }
2692 2717 else if (type==INS_ATTR) {
2693 2718 id = ++_insId;
2694 2719 }
2695 2720 else assert( false,"");
2696 2721 }
2697 2722 AttributeForm::~AttributeForm() {
2698 2723 }
2699 2724
2700 2725 // Dynamic type check
2701 2726 AttributeForm *AttributeForm::is_attribute() const {
2702 2727 return (AttributeForm*)this;
2703 2728 }
2704 2729
2705 2730
2706 2731 // inlined // int AttributeForm::type() { return id;}
2707 2732
2708 2733 void AttributeForm::dump() {
2709 2734 output(stderr);
2710 2735 }
2711 2736
2712 2737 void AttributeForm::output(FILE *fp) {
2713 2738 if( _attrname && _attrdef ) {
2714 2739 fprintf(fp,"\n// AttributeForm \nstatic const int %s = %s;\n",
2715 2740 _attrname, _attrdef);
2716 2741 }
2717 2742 else {
2718 2743 fprintf(fp,"\n// AttributeForm missing name %s or definition %s\n",
2719 2744 (_attrname?_attrname:""), (_attrdef?_attrdef:"") );
2720 2745 }
2721 2746 }
2722 2747
2723 2748 //------------------------------Component--------------------------------------
2724 2749 Component::Component(const char *name, const char *type, int usedef)
2725 2750 : _name(name), _type(type), _usedef(usedef) {
2726 2751 _ftype = Form::COMP;
2727 2752 }
2728 2753 Component::~Component() {
2729 2754 }
2730 2755
2731 2756 // True if this component is equal to the parameter.
2732 2757 bool Component::is(int use_def_kill_enum) const {
2733 2758 return (_usedef == use_def_kill_enum ? true : false);
2734 2759 }
2735 2760 // True if this component is used/def'd/kill'd as the parameter suggests.
2736 2761 bool Component::isa(int use_def_kill_enum) const {
2737 2762 return (_usedef & use_def_kill_enum) == use_def_kill_enum;
2738 2763 }
2739 2764
2740 2765 // Extend this component with additional use/def/kill behavior
2741 2766 int Component::promote_use_def_info(int new_use_def) {
2742 2767 _usedef |= new_use_def;
2743 2768
2744 2769 return _usedef;
2745 2770 }
2746 2771
2747 2772 // Check the base type of this component, if it has one
2748 2773 const char *Component::base_type(FormDict &globals) {
2749 2774 const Form *frm = globals[_type];
2750 2775 if (frm == NULL) return NULL;
2751 2776 OperandForm *op = frm->is_operand();
2752 2777 if (op == NULL) return NULL;
2753 2778 if (op->ideal_only()) return op->_ident;
2754 2779 return (char *)op->ideal_type(globals);
2755 2780 }
2756 2781
2757 2782 void Component::dump() {
2758 2783 output(stderr);
2759 2784 }
2760 2785
2761 2786 void Component::output(FILE *fp) {
2762 2787 fprintf(fp,"Component:"); // Write to output files
2763 2788 fprintf(fp, " name = %s", _name);
2764 2789 fprintf(fp, ", type = %s", _type);
2765 2790 const char * usedef = "Undefined Use/Def info";
2766 2791 switch (_usedef) {
2767 2792 case USE: usedef = "USE"; break;
2768 2793 case USE_DEF: usedef = "USE_DEF"; break;
2769 2794 case USE_KILL: usedef = "USE_KILL"; break;
2770 2795 case KILL: usedef = "KILL"; break;
2771 2796 case TEMP: usedef = "TEMP"; break;
2772 2797 case DEF: usedef = "DEF"; break;
2773 2798 default: assert(false, "unknown effect");
2774 2799 }
2775 2800 fprintf(fp, ", use/def = %s\n", usedef);
2776 2801 }
2777 2802
2778 2803
2779 2804 //------------------------------ComponentList---------------------------------
2780 2805 ComponentList::ComponentList() : NameList(), _matchcnt(0) {
2781 2806 }
2782 2807 ComponentList::~ComponentList() {
2783 2808 // // This list may not own its elements if copied via assignment
2784 2809 // Component *component;
2785 2810 // for (reset(); (component = iter()) != NULL;) {
2786 2811 // delete component;
2787 2812 // }
2788 2813 }
2789 2814
2790 2815 void ComponentList::insert(Component *component, bool mflag) {
2791 2816 NameList::addName((char *)component);
2792 2817 if(mflag) _matchcnt++;
2793 2818 }
2794 2819 void ComponentList::insert(const char *name, const char *opType, int usedef,
2795 2820 bool mflag) {
2796 2821 Component * component = new Component(name, opType, usedef);
2797 2822 insert(component, mflag);
2798 2823 }
2799 2824 Component *ComponentList::current() { return (Component*)NameList::current(); }
2800 2825 Component *ComponentList::iter() { return (Component*)NameList::iter(); }
2801 2826 Component *ComponentList::match_iter() {
2802 2827 if(_iter < _matchcnt) return (Component*)NameList::iter();
2803 2828 return NULL;
2804 2829 }
2805 2830 Component *ComponentList::post_match_iter() {
2806 2831 Component *comp = iter();
2807 2832 // At end of list?
2808 2833 if ( comp == NULL ) {
2809 2834 return comp;
2810 2835 }
2811 2836 // In post-match components?
2812 2837 if (_iter > match_count()-1) {
2813 2838 return comp;
2814 2839 }
2815 2840
2816 2841 return post_match_iter();
2817 2842 }
2818 2843
2819 2844 void ComponentList::reset() { NameList::reset(); }
2820 2845 int ComponentList::count() { return NameList::count(); }
2821 2846
2822 2847 Component *ComponentList::operator[](int position) {
2823 2848 // Shortcut complete iteration if there are not enough entries
2824 2849 if (position >= count()) return NULL;
2825 2850
2826 2851 int index = 0;
2827 2852 Component *component = NULL;
2828 2853 for (reset(); (component = iter()) != NULL;) {
2829 2854 if (index == position) {
2830 2855 return component;
2831 2856 }
2832 2857 ++index;
2833 2858 }
2834 2859
2835 2860 return NULL;
2836 2861 }
2837 2862
2838 2863 const Component *ComponentList::search(const char *name) {
2839 2864 PreserveIter pi(this);
2840 2865 reset();
2841 2866 for( Component *comp = NULL; ((comp = iter()) != NULL); ) {
2842 2867 if( strcmp(comp->_name,name) == 0 ) return comp;
2843 2868 }
2844 2869
2845 2870 return NULL;
2846 2871 }
2847 2872
2848 2873 // Return number of USEs + number of DEFs
2849 2874 // When there are no components, or the first component is a USE,
2850 2875 // then we add '1' to hold a space for the 'result' operand.
2851 2876 int ComponentList::num_operands() {
2852 2877 PreserveIter pi(this);
2853 2878 uint count = 1; // result operand
2854 2879 uint position = 0;
2855 2880
2856 2881 Component *component = NULL;
2857 2882 for( reset(); (component = iter()) != NULL; ++position ) {
2858 2883 if( component->isa(Component::USE) ||
2859 2884 ( position == 0 && (! component->isa(Component::DEF))) ) {
2860 2885 ++count;
2861 2886 }
2862 2887 }
2863 2888
2864 2889 return count;
2865 2890 }
2866 2891
2867 2892 // Return zero-based position in list; -1 if not in list.
2868 2893 // if parameter 'usedef' is ::USE, it will match USE, USE_DEF, ...
2869 2894 int ComponentList::operand_position(const char *name, int usedef) {
2870 2895 PreserveIter pi(this);
2871 2896 int position = 0;
2872 2897 int num_opnds = num_operands();
2873 2898 Component *component;
2874 2899 Component* preceding_non_use = NULL;
2875 2900 Component* first_def = NULL;
2876 2901 for (reset(); (component = iter()) != NULL; ++position) {
2877 2902 // When the first component is not a DEF,
2878 2903 // leave space for the result operand!
2879 2904 if ( position==0 && (! component->isa(Component::DEF)) ) {
2880 2905 ++position;
2881 2906 ++num_opnds;
2882 2907 }
2883 2908 if (strcmp(name, component->_name)==0 && (component->isa(usedef))) {
2884 2909 // When the first entry in the component list is a DEF and a USE
2885 2910 // Treat them as being separate, a DEF first, then a USE
2886 2911 if( position==0
2887 2912 && usedef==Component::USE && component->isa(Component::DEF) ) {
2888 2913 assert(position+1 < num_opnds, "advertised index in bounds");
2889 2914 return position+1;
2890 2915 } else {
2891 2916 if( preceding_non_use && strcmp(component->_name, preceding_non_use->_name) ) {
2892 2917 fprintf(stderr, "the name '%s' should not precede the name '%s'\n", preceding_non_use->_name, name);
2893 2918 }
2894 2919 if( position >= num_opnds ) {
2895 2920 fprintf(stderr, "the name '%s' is too late in its name list\n", name);
2896 2921 }
2897 2922 assert(position < num_opnds, "advertised index in bounds");
2898 2923 return position;
2899 2924 }
2900 2925 }
2901 2926 if( component->isa(Component::DEF)
2902 2927 && component->isa(Component::USE) ) {
2903 2928 ++position;
2904 2929 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
2905 2930 }
2906 2931 if( component->isa(Component::DEF) && !first_def ) {
2907 2932 first_def = component;
2908 2933 }
2909 2934 if( !component->isa(Component::USE) && component != first_def ) {
2910 2935 preceding_non_use = component;
2911 2936 } else if( preceding_non_use && !strcmp(component->_name, preceding_non_use->_name) ) {
2912 2937 preceding_non_use = NULL;
2913 2938 }
2914 2939 }
2915 2940 return Not_in_list;
2916 2941 }
2917 2942
2918 2943 // Find position for this name, regardless of use/def information
2919 2944 int ComponentList::operand_position(const char *name) {
2920 2945 PreserveIter pi(this);
2921 2946 int position = 0;
2922 2947 Component *component;
2923 2948 for (reset(); (component = iter()) != NULL; ++position) {
2924 2949 // When the first component is not a DEF,
2925 2950 // leave space for the result operand!
2926 2951 if ( position==0 && (! component->isa(Component::DEF)) ) {
2927 2952 ++position;
2928 2953 }
2929 2954 if (strcmp(name, component->_name)==0) {
2930 2955 return position;
2931 2956 }
2932 2957 if( component->isa(Component::DEF)
2933 2958 && component->isa(Component::USE) ) {
2934 2959 ++position;
2935 2960 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
2936 2961 }
2937 2962 }
2938 2963 return Not_in_list;
2939 2964 }
2940 2965
2941 2966 int ComponentList::operand_position_format(const char *name) {
2942 2967 PreserveIter pi(this);
2943 2968 int first_position = operand_position(name);
2944 2969 int use_position = operand_position(name, Component::USE);
2945 2970
2946 2971 return ((first_position < use_position) ? use_position : first_position);
2947 2972 }
2948 2973
2949 2974 int ComponentList::label_position() {
2950 2975 PreserveIter pi(this);
2951 2976 int position = 0;
2952 2977 reset();
2953 2978 for( Component *comp; (comp = iter()) != NULL; ++position) {
2954 2979 // When the first component is not a DEF,
2955 2980 // leave space for the result operand!
2956 2981 if ( position==0 && (! comp->isa(Component::DEF)) ) {
2957 2982 ++position;
2958 2983 }
2959 2984 if (strcmp(comp->_type, "label")==0) {
2960 2985 return position;
2961 2986 }
2962 2987 if( comp->isa(Component::DEF)
2963 2988 && comp->isa(Component::USE) ) {
2964 2989 ++position;
2965 2990 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
2966 2991 }
2967 2992 }
2968 2993
2969 2994 return -1;
2970 2995 }
2971 2996
2972 2997 int ComponentList::method_position() {
2973 2998 PreserveIter pi(this);
2974 2999 int position = 0;
2975 3000 reset();
2976 3001 for( Component *comp; (comp = iter()) != NULL; ++position) {
2977 3002 // When the first component is not a DEF,
2978 3003 // leave space for the result operand!
2979 3004 if ( position==0 && (! comp->isa(Component::DEF)) ) {
2980 3005 ++position;
2981 3006 }
2982 3007 if (strcmp(comp->_type, "method")==0) {
2983 3008 return position;
2984 3009 }
2985 3010 if( comp->isa(Component::DEF)
2986 3011 && comp->isa(Component::USE) ) {
2987 3012 ++position;
2988 3013 if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
2989 3014 }
2990 3015 }
2991 3016
2992 3017 return -1;
2993 3018 }
2994 3019
2995 3020 void ComponentList::dump() { output(stderr); }
2996 3021
2997 3022 void ComponentList::output(FILE *fp) {
2998 3023 PreserveIter pi(this);
2999 3024 fprintf(fp, "\n");
3000 3025 Component *component;
3001 3026 for (reset(); (component = iter()) != NULL;) {
3002 3027 component->output(fp);
3003 3028 }
3004 3029 fprintf(fp, "\n");
3005 3030 }
3006 3031
3007 3032 //------------------------------MatchNode--------------------------------------
3008 3033 MatchNode::MatchNode(ArchDesc &ad, const char *result, const char *mexpr,
3009 3034 const char *opType, MatchNode *lChild, MatchNode *rChild)
3010 3035 : _AD(ad), _result(result), _name(mexpr), _opType(opType),
3011 3036 _lChild(lChild), _rChild(rChild), _internalop(0), _numleaves(0),
3012 3037 _commutative_id(0) {
3013 3038 _numleaves = (lChild ? lChild->_numleaves : 0)
3014 3039 + (rChild ? rChild->_numleaves : 0);
3015 3040 }
3016 3041
3017 3042 MatchNode::MatchNode(ArchDesc &ad, MatchNode& mnode)
3018 3043 : _AD(ad), _result(mnode._result), _name(mnode._name),
3019 3044 _opType(mnode._opType), _lChild(mnode._lChild), _rChild(mnode._rChild),
3020 3045 _internalop(0), _numleaves(mnode._numleaves),
3021 3046 _commutative_id(mnode._commutative_id) {
3022 3047 }
3023 3048
3024 3049 MatchNode::MatchNode(ArchDesc &ad, MatchNode& mnode, int clone)
3025 3050 : _AD(ad), _result(mnode._result), _name(mnode._name),
3026 3051 _opType(mnode._opType),
3027 3052 _internalop(0), _numleaves(mnode._numleaves),
3028 3053 _commutative_id(mnode._commutative_id) {
3029 3054 if (mnode._lChild) {
3030 3055 _lChild = new MatchNode(ad, *mnode._lChild, clone);
3031 3056 } else {
3032 3057 _lChild = NULL;
3033 3058 }
3034 3059 if (mnode._rChild) {
3035 3060 _rChild = new MatchNode(ad, *mnode._rChild, clone);
3036 3061 } else {
3037 3062 _rChild = NULL;
3038 3063 }
3039 3064 }
3040 3065
3041 3066 MatchNode::~MatchNode() {
3042 3067 // // This node may not own its children if copied via assignment
3043 3068 // if( _lChild ) delete _lChild;
3044 3069 // if( _rChild ) delete _rChild;
3045 3070 }
3046 3071
3047 3072 bool MatchNode::find_type(const char *type, int &position) const {
3048 3073 if ( (_lChild != NULL) && (_lChild->find_type(type, position)) ) return true;
3049 3074 if ( (_rChild != NULL) && (_rChild->find_type(type, position)) ) return true;
3050 3075
3051 3076 if (strcmp(type,_opType)==0) {
3052 3077 return true;
3053 3078 } else {
3054 3079 ++position;
3055 3080 }
3056 3081 return false;
3057 3082 }
3058 3083
3059 3084 // Recursive call collecting info on top-level operands, not transitive.
3060 3085 // Implementation does not modify state of internal structures.
3061 3086 void MatchNode::append_components(FormDict& locals, ComponentList& components,
3062 3087 bool def_flag) const {
3063 3088 int usedef = def_flag ? Component::DEF : Component::USE;
3064 3089 FormDict &globals = _AD.globalNames();
3065 3090
3066 3091 assert (_name != NULL, "MatchNode::build_components encountered empty node\n");
3067 3092 // Base case
3068 3093 if (_lChild==NULL && _rChild==NULL) {
3069 3094 // If _opType is not an operation, do not build a component for it #####
3070 3095 const Form *f = globals[_opType];
3071 3096 if( f != NULL ) {
3072 3097 // Add non-ideals that are operands, operand-classes,
3073 3098 if( ! f->ideal_only()
3074 3099 && (f->is_opclass() || f->is_operand()) ) {
3075 3100 components.insert(_name, _opType, usedef, true);
3076 3101 }
3077 3102 }
3078 3103 return;
3079 3104 }
3080 3105 // Promote results of "Set" to DEF
3081 3106 bool tmpdef_flag = (!strcmp(_opType, "Set")) ? true : false;
3082 3107 if (_lChild) _lChild->append_components(locals, components, tmpdef_flag);
3083 3108 tmpdef_flag = false; // only applies to component immediately following 'Set'
3084 3109 if (_rChild) _rChild->append_components(locals, components, tmpdef_flag);
3085 3110 }
3086 3111
3087 3112 // Find the n'th base-operand in the match node,
3088 3113 // recursively investigates match rules of user-defined operands.
3089 3114 //
3090 3115 // Implementation does not modify state of internal structures since they
3091 3116 // can be shared.
3092 3117 bool MatchNode::base_operand(uint &position, FormDict &globals,
3093 3118 const char * &result, const char * &name,
3094 3119 const char * &opType) const {
3095 3120 assert (_name != NULL, "MatchNode::base_operand encountered empty node\n");
3096 3121 // Base case
3097 3122 if (_lChild==NULL && _rChild==NULL) {
3098 3123 // Check for special case: "Universe", "label"
3099 3124 if (strcmp(_opType,"Universe") == 0 || strcmp(_opType,"label")==0 ) {
3100 3125 if (position == 0) {
3101 3126 result = _result;
3102 3127 name = _name;
3103 3128 opType = _opType;
3104 3129 return 1;
3105 3130 } else {
3106 3131 -- position;
3107 3132 return 0;
3108 3133 }
3109 3134 }
3110 3135
3111 3136 const Form *form = globals[_opType];
3112 3137 MatchNode *matchNode = NULL;
3113 3138 // Check for user-defined type
3114 3139 if (form) {
3115 3140 // User operand or instruction?
3116 3141 OperandForm *opForm = form->is_operand();
3117 3142 InstructForm *inForm = form->is_instruction();
3118 3143 if ( opForm ) {
3119 3144 matchNode = (MatchNode*)opForm->_matrule;
3120 3145 } else if ( inForm ) {
3121 3146 matchNode = (MatchNode*)inForm->_matrule;
3122 3147 }
3123 3148 }
3124 3149 // if this is user-defined, recurse on match rule
3125 3150 // User-defined operand and instruction forms have a match-rule.
3126 3151 if (matchNode) {
3127 3152 return (matchNode->base_operand(position,globals,result,name,opType));
3128 3153 } else {
3129 3154 // Either not a form, or a system-defined form (no match rule).
3130 3155 if (position==0) {
3131 3156 result = _result;
3132 3157 name = _name;
3133 3158 opType = _opType;
3134 3159 return 1;
3135 3160 } else {
3136 3161 --position;
3137 3162 return 0;
3138 3163 }
3139 3164 }
3140 3165
3141 3166 } else {
3142 3167 // Examine the left child and right child as well
3143 3168 if (_lChild) {
3144 3169 if (_lChild->base_operand(position, globals, result, name, opType))
3145 3170 return 1;
3146 3171 }
3147 3172
3148 3173 if (_rChild) {
3149 3174 if (_rChild->base_operand(position, globals, result, name, opType))
3150 3175 return 1;
3151 3176 }
3152 3177 }
3153 3178
3154 3179 return 0;
3155 3180 }
3156 3181
3157 3182 // Recursive call on all operands' match rules in my match rule.
3158 3183 uint MatchNode::num_consts(FormDict &globals) const {
3159 3184 uint index = 0;
3160 3185 uint num_consts = 0;
3161 3186 const char *result;
3162 3187 const char *name;
3163 3188 const char *opType;
3164 3189
3165 3190 for (uint position = index;
3166 3191 base_operand(position,globals,result,name,opType); position = index) {
3167 3192 ++index;
3168 3193 if( ideal_to_const_type(opType) ) num_consts++;
3169 3194 }
3170 3195
3171 3196 return num_consts;
3172 3197 }
3173 3198
3174 3199 // Recursive call on all operands' match rules in my match rule.
3175 3200 // Constants in match rule subtree with specified type
3176 3201 uint MatchNode::num_consts(FormDict &globals, Form::DataType type) const {
3177 3202 uint index = 0;
3178 3203 uint num_consts = 0;
3179 3204 const char *result;
3180 3205 const char *name;
3181 3206 const char *opType;
3182 3207
3183 3208 for (uint position = index;
3184 3209 base_operand(position,globals,result,name,opType); position = index) {
3185 3210 ++index;
3186 3211 if( ideal_to_const_type(opType) == type ) num_consts++;
3187 3212 }
3188 3213
3189 3214 return num_consts;
3190 3215 }
3191 3216
3192 3217 // Recursive call on all operands' match rules in my match rule.
3193 3218 uint MatchNode::num_const_ptrs(FormDict &globals) const {
3194 3219 return num_consts( globals, Form::idealP );
3195 3220 }
3196 3221
3197 3222 bool MatchNode::sets_result() const {
3198 3223 return ( (strcmp(_name,"Set") == 0) ? true : false );
3199 3224 }
3200 3225
3201 3226 const char *MatchNode::reduce_right(FormDict &globals) const {
3202 3227 // If there is no right reduction, return NULL.
3203 3228 const char *rightStr = NULL;
3204 3229
3205 3230 // If we are a "Set", start from the right child.
3206 3231 const MatchNode *const mnode = sets_result() ?
3207 3232 (const MatchNode *const)this->_rChild :
3208 3233 (const MatchNode *const)this;
3209 3234
3210 3235 // If our right child exists, it is the right reduction
3211 3236 if ( mnode->_rChild ) {
3212 3237 rightStr = mnode->_rChild->_internalop ? mnode->_rChild->_internalop
3213 3238 : mnode->_rChild->_opType;
3214 3239 }
3215 3240 // Else, May be simple chain rule: (Set dst operand_form), rightStr=NULL;
3216 3241 return rightStr;
3217 3242 }
3218 3243
3219 3244 const char *MatchNode::reduce_left(FormDict &globals) const {
3220 3245 // If there is no left reduction, return NULL.
3221 3246 const char *leftStr = NULL;
3222 3247
3223 3248 // If we are a "Set", start from the right child.
3224 3249 const MatchNode *const mnode = sets_result() ?
3225 3250 (const MatchNode *const)this->_rChild :
3226 3251 (const MatchNode *const)this;
3227 3252
3228 3253 // If our left child exists, it is the left reduction
3229 3254 if ( mnode->_lChild ) {
3230 3255 leftStr = mnode->_lChild->_internalop ? mnode->_lChild->_internalop
3231 3256 : mnode->_lChild->_opType;
3232 3257 } else {
3233 3258 // May be simple chain rule: (Set dst operand_form_source)
3234 3259 if ( sets_result() ) {
3235 3260 OperandForm *oper = globals[mnode->_opType]->is_operand();
3236 3261 if( oper ) {
3237 3262 leftStr = mnode->_opType;
3238 3263 }
3239 3264 }
3240 3265 }
3241 3266 return leftStr;
3242 3267 }
3243 3268
3244 3269 //------------------------------count_instr_names------------------------------
3245 3270 // Count occurrences of operands names in the leaves of the instruction
3246 3271 // match rule.
3247 3272 void MatchNode::count_instr_names( Dict &names ) {
3248 3273 if( !this ) return;
3249 3274 if( _lChild ) _lChild->count_instr_names(names);
3250 3275 if( _rChild ) _rChild->count_instr_names(names);
3251 3276 if( !_lChild && !_rChild ) {
3252 3277 uintptr_t cnt = (uintptr_t)names[_name];
3253 3278 cnt++; // One more name found
3254 3279 names.Insert(_name,(void*)cnt);
3255 3280 }
3256 3281 }
3257 3282
3258 3283 //------------------------------build_instr_pred-------------------------------
3259 3284 // Build a path to 'name' in buf. Actually only build if cnt is zero, so we
3260 3285 // can skip some leading instances of 'name'.
3261 3286 int MatchNode::build_instr_pred( char *buf, const char *name, int cnt ) {
3262 3287 if( _lChild ) {
3263 3288 if( !cnt ) strcpy( buf, "_kids[0]->" );
3264 3289 cnt = _lChild->build_instr_pred( buf+strlen(buf), name, cnt );
3265 3290 if( cnt < 0 ) return cnt; // Found it, all done
3266 3291 }
3267 3292 if( _rChild ) {
3268 3293 if( !cnt ) strcpy( buf, "_kids[1]->" );
3269 3294 cnt = _rChild->build_instr_pred( buf+strlen(buf), name, cnt );
3270 3295 if( cnt < 0 ) return cnt; // Found it, all done
3271 3296 }
3272 3297 if( !_lChild && !_rChild ) { // Found a leaf
3273 3298 // Wrong name? Give up...
3274 3299 if( strcmp(name,_name) ) return cnt;
3275 3300 if( !cnt ) strcpy(buf,"_leaf");
3276 3301 return cnt-1;
3277 3302 }
3278 3303 return cnt;
3279 3304 }
3280 3305
3281 3306
3282 3307 //------------------------------build_internalop-------------------------------
3283 3308 // Build string representation of subtree
3284 3309 void MatchNode::build_internalop( ) {
3285 3310 char *iop, *subtree;
3286 3311 const char *lstr, *rstr;
3287 3312 // Build string representation of subtree
3288 3313 // Operation lchildType rchildType
3289 3314 int len = (int)strlen(_opType) + 4;
3290 3315 lstr = (_lChild) ? ((_lChild->_internalop) ?
3291 3316 _lChild->_internalop : _lChild->_opType) : "";
3292 3317 rstr = (_rChild) ? ((_rChild->_internalop) ?
3293 3318 _rChild->_internalop : _rChild->_opType) : "";
3294 3319 len += (int)strlen(lstr) + (int)strlen(rstr);
3295 3320 subtree = (char *)malloc(len);
3296 3321 sprintf(subtree,"_%s_%s_%s", _opType, lstr, rstr);
3297 3322 // Hash the subtree string in _internalOps; if a name exists, use it
3298 3323 iop = (char *)_AD._internalOps[subtree];
3299 3324 // Else create a unique name, and add it to the hash table
3300 3325 if (iop == NULL) {
3301 3326 iop = subtree;
3302 3327 _AD._internalOps.Insert(subtree, iop);
3303 3328 _AD._internalOpNames.addName(iop);
3304 3329 _AD._internalMatch.Insert(iop, this);
3305 3330 }
3306 3331 // Add the internal operand name to the MatchNode
3307 3332 _internalop = iop;
3308 3333 _result = iop;
3309 3334 }
3310 3335
3311 3336
3312 3337 void MatchNode::dump() {
3313 3338 output(stderr);
3314 3339 }
3315 3340
3316 3341 void MatchNode::output(FILE *fp) {
3317 3342 if (_lChild==0 && _rChild==0) {
3318 3343 fprintf(fp," %s",_name); // operand
3319 3344 }
3320 3345 else {
3321 3346 fprintf(fp," (%s ",_name); // " (opcodeName "
3322 3347 if(_lChild) _lChild->output(fp); // left operand
3323 3348 if(_rChild) _rChild->output(fp); // right operand
3324 3349 fprintf(fp,")"); // ")"
3325 3350 }
3326 3351 }
3327 3352
3328 3353 int MatchNode::needs_ideal_memory_edge(FormDict &globals) const {
3329 3354 static const char *needs_ideal_memory_list[] = {
3330 3355 "StoreI","StoreL","StoreP","StoreN","StoreD","StoreF" ,
3331 3356 "StoreB","StoreC","Store" ,"StoreFP",
3332 3357 "LoadI", "LoadUI2L", "LoadL", "LoadP" ,"LoadN", "LoadD" ,"LoadF" ,
3333 3358 "LoadB" , "LoadUB", "LoadUS" ,"LoadS" ,"Load" ,
3334 3359 "Store4I","Store2I","Store2L","Store2D","Store4F","Store2F","Store16B",
3335 3360 "Store8B","Store4B","Store8C","Store4C","Store2C",
3336 3361 "Load4I" ,"Load2I" ,"Load2L" ,"Load2D" ,"Load4F" ,"Load2F" ,"Load16B" ,
3337 3362 "Load8B" ,"Load4B" ,"Load8C" ,"Load4C" ,"Load2C" ,"Load8S", "Load4S","Load2S",
3338 3363 "LoadRange", "LoadKlass", "LoadNKlass", "LoadL_unaligned", "LoadD_unaligned",
3339 3364 "LoadPLocked", "LoadLLocked",
3340 3365 "StorePConditional", "StoreIConditional", "StoreLConditional",
3341 3366 "CompareAndSwapI", "CompareAndSwapL", "CompareAndSwapP", "CompareAndSwapN",
3342 3367 "StoreCM",
3343 3368 "ClearArray"
3344 3369 };
3345 3370 int cnt = sizeof(needs_ideal_memory_list)/sizeof(char*);
3346 3371 if( strcmp(_opType,"PrefetchRead")==0 || strcmp(_opType,"PrefetchWrite")==0 )
3347 3372 return 1;
3348 3373 if( _lChild ) {
3349 3374 const char *opType = _lChild->_opType;
3350 3375 for( int i=0; i<cnt; i++ )
3351 3376 if( strcmp(opType,needs_ideal_memory_list[i]) == 0 )
3352 3377 return 1;
3353 3378 if( _lChild->needs_ideal_memory_edge(globals) )
3354 3379 return 1;
3355 3380 }
3356 3381 if( _rChild ) {
3357 3382 const char *opType = _rChild->_opType;
3358 3383 for( int i=0; i<cnt; i++ )
3359 3384 if( strcmp(opType,needs_ideal_memory_list[i]) == 0 )
3360 3385 return 1;
3361 3386 if( _rChild->needs_ideal_memory_edge(globals) )
3362 3387 return 1;
3363 3388 }
3364 3389
3365 3390 return 0;
3366 3391 }
3367 3392
3368 3393 // TRUE if defines a derived oop, and so needs a base oop edge present
3369 3394 // post-matching.
3370 3395 int MatchNode::needs_base_oop_edge() const {
3371 3396 if( !strcmp(_opType,"AddP") ) return 1;
3372 3397 if( strcmp(_opType,"Set") ) return 0;
3373 3398 return !strcmp(_rChild->_opType,"AddP");
3374 3399 }
3375 3400
3376 3401 int InstructForm::needs_base_oop_edge(FormDict &globals) const {
3377 3402 if( is_simple_chain_rule(globals) ) {
3378 3403 const char *src = _matrule->_rChild->_opType;
3379 3404 OperandForm *src_op = globals[src]->is_operand();
3380 3405 assert( src_op, "Not operand class of chain rule" );
3381 3406 return src_op->_matrule ? src_op->_matrule->needs_base_oop_edge() : 0;
3382 3407 } // Else check instruction
3383 3408
3384 3409 return _matrule ? _matrule->needs_base_oop_edge() : 0;
3385 3410 }
3386 3411
3387 3412
3388 3413 //-------------------------cisc spilling methods-------------------------------
3389 3414 // helper routines and methods for detecting cisc-spilling instructions
3390 3415 //-------------------------cisc_spill_merge------------------------------------
3391 3416 int MatchNode::cisc_spill_merge(int left_spillable, int right_spillable) {
3392 3417 int cisc_spillable = Maybe_cisc_spillable;
3393 3418
3394 3419 // Combine results of left and right checks
3395 3420 if( (left_spillable == Maybe_cisc_spillable) && (right_spillable == Maybe_cisc_spillable) ) {
3396 3421 // neither side is spillable, nor prevents cisc spilling
3397 3422 cisc_spillable = Maybe_cisc_spillable;
3398 3423 }
3399 3424 else if( (left_spillable == Maybe_cisc_spillable) && (right_spillable > Maybe_cisc_spillable) ) {
3400 3425 // right side is spillable
3401 3426 cisc_spillable = right_spillable;
3402 3427 }
3403 3428 else if( (right_spillable == Maybe_cisc_spillable) && (left_spillable > Maybe_cisc_spillable) ) {
3404 3429 // left side is spillable
3405 3430 cisc_spillable = left_spillable;
3406 3431 }
3407 3432 else if( (left_spillable == Not_cisc_spillable) || (right_spillable == Not_cisc_spillable) ) {
3408 3433 // left or right prevents cisc spilling this instruction
3409 3434 cisc_spillable = Not_cisc_spillable;
3410 3435 }
3411 3436 else {
3412 3437 // Only allow one to spill
3413 3438 cisc_spillable = Not_cisc_spillable;
3414 3439 }
3415 3440
3416 3441 return cisc_spillable;
3417 3442 }
3418 3443
3419 3444 //-------------------------root_ops_match--------------------------------------
3420 3445 bool static root_ops_match(FormDict &globals, const char *op1, const char *op2) {
3421 3446 // Base Case: check that the current operands/operations match
3422 3447 assert( op1, "Must have op's name");
3423 3448 assert( op2, "Must have op's name");
3424 3449 const Form *form1 = globals[op1];
3425 3450 const Form *form2 = globals[op2];
3426 3451
3427 3452 return (form1 == form2);
3428 3453 }
3429 3454
3430 3455 //-------------------------cisc_spill_match_node-------------------------------
3431 3456 // Recursively check two MatchRules for legal conversion via cisc-spilling
3432 3457 int MatchNode::cisc_spill_match(FormDict& globals, RegisterForm* registers, MatchNode* mRule2, const char* &operand, const char* ®_type) {
3433 3458 int cisc_spillable = Maybe_cisc_spillable;
3434 3459 int left_spillable = Maybe_cisc_spillable;
3435 3460 int right_spillable = Maybe_cisc_spillable;
3436 3461
3437 3462 // Check that each has same number of operands at this level
3438 3463 if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) )
3439 3464 return Not_cisc_spillable;
3440 3465
3441 3466 // Base Case: check that the current operands/operations match
3442 3467 // or are CISC spillable
3443 3468 assert( _opType, "Must have _opType");
3444 3469 assert( mRule2->_opType, "Must have _opType");
3445 3470 const Form *form = globals[_opType];
3446 3471 const Form *form2 = globals[mRule2->_opType];
3447 3472 if( form == form2 ) {
3448 3473 cisc_spillable = Maybe_cisc_spillable;
3449 3474 } else {
3450 3475 const InstructForm *form2_inst = form2 ? form2->is_instruction() : NULL;
3451 3476 const char *name_left = mRule2->_lChild ? mRule2->_lChild->_opType : NULL;
3452 3477 const char *name_right = mRule2->_rChild ? mRule2->_rChild->_opType : NULL;
3453 3478 DataType data_type = Form::none;
3454 3479 if (form->is_operand()) {
3455 3480 // Make sure the loadX matches the type of the reg
3456 3481 data_type = form->ideal_to_Reg_type(form->is_operand()->ideal_type(globals));
3457 3482 }
3458 3483 // Detect reg vs (loadX memory)
3459 3484 if( form->is_cisc_reg(globals)
3460 3485 && form2_inst
3461 3486 && data_type != Form::none
3462 3487 && (is_load_from_memory(mRule2->_opType) == data_type) // reg vs. (load memory)
3463 3488 && (name_left != NULL) // NOT (load)
3464 3489 && (name_right == NULL) ) { // NOT (load memory foo)
3465 3490 const Form *form2_left = name_left ? globals[name_left] : NULL;
3466 3491 if( form2_left && form2_left->is_cisc_mem(globals) ) {
3467 3492 cisc_spillable = Is_cisc_spillable;
3468 3493 operand = _name;
3469 3494 reg_type = _result;
3470 3495 return Is_cisc_spillable;
3471 3496 } else {
3472 3497 cisc_spillable = Not_cisc_spillable;
3473 3498 }
3474 3499 }
3475 3500 // Detect reg vs memory
3476 3501 else if( form->is_cisc_reg(globals) && form2->is_cisc_mem(globals) ) {
3477 3502 cisc_spillable = Is_cisc_spillable;
3478 3503 operand = _name;
3479 3504 reg_type = _result;
3480 3505 return Is_cisc_spillable;
3481 3506 } else {
3482 3507 cisc_spillable = Not_cisc_spillable;
3483 3508 }
3484 3509 }
3485 3510
3486 3511 // If cisc is still possible, check rest of tree
3487 3512 if( cisc_spillable == Maybe_cisc_spillable ) {
3488 3513 // Check that each has same number of operands at this level
3489 3514 if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable;
3490 3515
3491 3516 // Check left operands
3492 3517 if( (_lChild == NULL) && (mRule2->_lChild == NULL) ) {
3493 3518 left_spillable = Maybe_cisc_spillable;
3494 3519 } else {
3495 3520 left_spillable = _lChild->cisc_spill_match(globals, registers, mRule2->_lChild, operand, reg_type);
3496 3521 }
3497 3522
3498 3523 // Check right operands
3499 3524 if( (_rChild == NULL) && (mRule2->_rChild == NULL) ) {
3500 3525 right_spillable = Maybe_cisc_spillable;
3501 3526 } else {
3502 3527 right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type);
3503 3528 }
3504 3529
3505 3530 // Combine results of left and right checks
3506 3531 cisc_spillable = cisc_spill_merge(left_spillable, right_spillable);
3507 3532 }
3508 3533
3509 3534 return cisc_spillable;
3510 3535 }
3511 3536
3512 3537 //---------------------------cisc_spill_match_rule------------------------------
3513 3538 // Recursively check two MatchRules for legal conversion via cisc-spilling
3514 3539 // This method handles the root of Match tree,
3515 3540 // general recursive checks done in MatchNode
3516 3541 int MatchRule::matchrule_cisc_spill_match(FormDict& globals, RegisterForm* registers,
3517 3542 MatchRule* mRule2, const char* &operand,
3518 3543 const char* ®_type) {
3519 3544 int cisc_spillable = Maybe_cisc_spillable;
3520 3545 int left_spillable = Maybe_cisc_spillable;
3521 3546 int right_spillable = Maybe_cisc_spillable;
3522 3547
3523 3548 // Check that each sets a result
3524 3549 if( !(sets_result() && mRule2->sets_result()) ) return Not_cisc_spillable;
3525 3550 // Check that each has same number of operands at this level
3526 3551 if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable;
3527 3552
3528 3553 // Check left operands: at root, must be target of 'Set'
3529 3554 if( (_lChild == NULL) || (mRule2->_lChild == NULL) ) {
3530 3555 left_spillable = Not_cisc_spillable;
3531 3556 } else {
3532 3557 // Do not support cisc-spilling instruction's target location
3533 3558 if( root_ops_match(globals, _lChild->_opType, mRule2->_lChild->_opType) ) {
3534 3559 left_spillable = Maybe_cisc_spillable;
3535 3560 } else {
3536 3561 left_spillable = Not_cisc_spillable;
3537 3562 }
3538 3563 }
3539 3564
3540 3565 // Check right operands: recursive walk to identify reg->mem operand
3541 3566 if( (_rChild == NULL) && (mRule2->_rChild == NULL) ) {
3542 3567 right_spillable = Maybe_cisc_spillable;
3543 3568 } else {
3544 3569 right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type);
3545 3570 }
3546 3571
3547 3572 // Combine results of left and right checks
3548 3573 cisc_spillable = cisc_spill_merge(left_spillable, right_spillable);
3549 3574
3550 3575 return cisc_spillable;
3551 3576 }
3552 3577
3553 3578 //----------------------------- equivalent ------------------------------------
3554 3579 // Recursively check to see if two match rules are equivalent.
3555 3580 // This rule handles the root.
3556 3581 bool MatchRule::equivalent(FormDict &globals, MatchNode *mRule2) {
3557 3582 // Check that each sets a result
3558 3583 if (sets_result() != mRule2->sets_result()) {
3559 3584 return false;
3560 3585 }
3561 3586
3562 3587 // Check that the current operands/operations match
3563 3588 assert( _opType, "Must have _opType");
3564 3589 assert( mRule2->_opType, "Must have _opType");
3565 3590 const Form *form = globals[_opType];
3566 3591 const Form *form2 = globals[mRule2->_opType];
3567 3592 if( form != form2 ) {
3568 3593 return false;
3569 3594 }
3570 3595
3571 3596 if (_lChild ) {
3572 3597 if( !_lChild->equivalent(globals, mRule2->_lChild) )
3573 3598 return false;
3574 3599 } else if (mRule2->_lChild) {
3575 3600 return false; // I have NULL left child, mRule2 has non-NULL left child.
3576 3601 }
3577 3602
3578 3603 if (_rChild ) {
3579 3604 if( !_rChild->equivalent(globals, mRule2->_rChild) )
3580 3605 return false;
3581 3606 } else if (mRule2->_rChild) {
3582 3607 return false; // I have NULL right child, mRule2 has non-NULL right child.
3583 3608 }
3584 3609
3585 3610 // We've made it through the gauntlet.
3586 3611 return true;
3587 3612 }
3588 3613
3589 3614 //----------------------------- equivalent ------------------------------------
3590 3615 // Recursively check to see if two match rules are equivalent.
3591 3616 // This rule handles the operands.
3592 3617 bool MatchNode::equivalent(FormDict &globals, MatchNode *mNode2) {
3593 3618 if( !mNode2 )
3594 3619 return false;
3595 3620
3596 3621 // Check that the current operands/operations match
3597 3622 assert( _opType, "Must have _opType");
3598 3623 assert( mNode2->_opType, "Must have _opType");
3599 3624 const Form *form = globals[_opType];
3600 3625 const Form *form2 = globals[mNode2->_opType];
3601 3626 return (form == form2);
3602 3627 }
3603 3628
3604 3629 //-------------------------- has_commutative_op -------------------------------
3605 3630 // Recursively check for commutative operations with subtree operands
3606 3631 // which could be swapped.
3607 3632 void MatchNode::count_commutative_op(int& count) {
3608 3633 static const char *commut_op_list[] = {
3609 3634 "AddI","AddL","AddF","AddD",
3610 3635 "AndI","AndL",
3611 3636 "MaxI","MinI",
3612 3637 "MulI","MulL","MulF","MulD",
3613 3638 "OrI" ,"OrL" ,
3614 3639 "XorI","XorL"
3615 3640 };
3616 3641 int cnt = sizeof(commut_op_list)/sizeof(char*);
3617 3642
3618 3643 if( _lChild && _rChild && (_lChild->_lChild || _rChild->_lChild) ) {
3619 3644 // Don't swap if right operand is an immediate constant.
3620 3645 bool is_const = false;
3621 3646 if( _rChild->_lChild == NULL && _rChild->_rChild == NULL ) {
3622 3647 FormDict &globals = _AD.globalNames();
3623 3648 const Form *form = globals[_rChild->_opType];
3624 3649 if ( form ) {
3625 3650 OperandForm *oper = form->is_operand();
3626 3651 if( oper && oper->interface_type(globals) == Form::constant_interface )
3627 3652 is_const = true;
3628 3653 }
3629 3654 }
3630 3655 if( !is_const ) {
3631 3656 for( int i=0; i<cnt; i++ ) {
3632 3657 if( strcmp(_opType, commut_op_list[i]) == 0 ) {
3633 3658 count++;
3634 3659 _commutative_id = count; // id should be > 0
3635 3660 break;
3636 3661 }
3637 3662 }
3638 3663 }
3639 3664 }
3640 3665 if( _lChild )
3641 3666 _lChild->count_commutative_op(count);
3642 3667 if( _rChild )
3643 3668 _rChild->count_commutative_op(count);
3644 3669 }
3645 3670
3646 3671 //-------------------------- swap_commutative_op ------------------------------
3647 3672 // Recursively swap specified commutative operation with subtree operands.
3648 3673 void MatchNode::swap_commutative_op(bool atroot, int id) {
3649 3674 if( _commutative_id == id ) { // id should be > 0
3650 3675 assert(_lChild && _rChild && (_lChild->_lChild || _rChild->_lChild ),
3651 3676 "not swappable operation");
3652 3677 MatchNode* tmp = _lChild;
3653 3678 _lChild = _rChild;
3654 3679 _rChild = tmp;
3655 3680 // Don't exit here since we need to build internalop.
3656 3681 }
3657 3682
3658 3683 bool is_set = ( strcmp(_opType, "Set") == 0 );
3659 3684 if( _lChild )
3660 3685 _lChild->swap_commutative_op(is_set, id);
3661 3686 if( _rChild )
3662 3687 _rChild->swap_commutative_op(is_set, id);
3663 3688
3664 3689 // If not the root, reduce this subtree to an internal operand
3665 3690 if( !atroot && (_lChild || _rChild) ) {
3666 3691 build_internalop();
3667 3692 }
3668 3693 }
3669 3694
3670 3695 //-------------------------- swap_commutative_op ------------------------------
3671 3696 // Recursively swap specified commutative operation with subtree operands.
3672 3697 void MatchRule::matchrule_swap_commutative_op(const char* instr_ident, int count, int& match_rules_cnt) {
3673 3698 assert(match_rules_cnt < 100," too many match rule clones");
3674 3699 // Clone
3675 3700 MatchRule* clone = new MatchRule(_AD, this);
3676 3701 // Swap operands of commutative operation
3677 3702 ((MatchNode*)clone)->swap_commutative_op(true, count);
3678 3703 char* buf = (char*) malloc(strlen(instr_ident) + 4);
3679 3704 sprintf(buf, "%s_%d", instr_ident, match_rules_cnt++);
3680 3705 clone->_result = buf;
3681 3706
3682 3707 clone->_next = this->_next;
3683 3708 this-> _next = clone;
3684 3709 if( (--count) > 0 ) {
3685 3710 this-> matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
3686 3711 clone->matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
3687 3712 }
3688 3713 }
3689 3714
3690 3715 //------------------------------MatchRule--------------------------------------
3691 3716 MatchRule::MatchRule(ArchDesc &ad)
3692 3717 : MatchNode(ad), _depth(0), _construct(NULL), _numchilds(0) {
3693 3718 _next = NULL;
3694 3719 }
3695 3720
3696 3721 MatchRule::MatchRule(ArchDesc &ad, MatchRule* mRule)
3697 3722 : MatchNode(ad, *mRule, 0), _depth(mRule->_depth),
3698 3723 _construct(mRule->_construct), _numchilds(mRule->_numchilds) {
3699 3724 _next = NULL;
3700 3725 }
3701 3726
3702 3727 MatchRule::MatchRule(ArchDesc &ad, MatchNode* mroot, int depth, char *cnstr,
3703 3728 int numleaves)
3704 3729 : MatchNode(ad,*mroot), _depth(depth), _construct(cnstr),
3705 3730 _numchilds(0) {
3706 3731 _next = NULL;
3707 3732 mroot->_lChild = NULL;
3708 3733 mroot->_rChild = NULL;
3709 3734 delete mroot;
3710 3735 _numleaves = numleaves;
3711 3736 _numchilds = (_lChild ? 1 : 0) + (_rChild ? 1 : 0);
3712 3737 }
3713 3738 MatchRule::~MatchRule() {
3714 3739 }
3715 3740
3716 3741 // Recursive call collecting info on top-level operands, not transitive.
3717 3742 // Implementation does not modify state of internal structures.
3718 3743 void MatchRule::append_components(FormDict& locals, ComponentList& components, bool def_flag) const {
3719 3744 assert (_name != NULL, "MatchNode::build_components encountered empty node\n");
3720 3745
3721 3746 MatchNode::append_components(locals, components,
3722 3747 false /* not necessarily a def */);
3723 3748 }
3724 3749
3725 3750 // Recursive call on all operands' match rules in my match rule.
3726 3751 // Implementation does not modify state of internal structures since they
3727 3752 // can be shared.
3728 3753 // The MatchNode that is called first treats its
3729 3754 bool MatchRule::base_operand(uint &position0, FormDict &globals,
3730 3755 const char *&result, const char * &name,
3731 3756 const char * &opType)const{
3732 3757 uint position = position0;
3733 3758
3734 3759 return (MatchNode::base_operand( position, globals, result, name, opType));
3735 3760 }
3736 3761
3737 3762
3738 3763 bool MatchRule::is_base_register(FormDict &globals) const {
3739 3764 uint position = 1;
3740 3765 const char *result = NULL;
3741 3766 const char *name = NULL;
3742 3767 const char *opType = NULL;
3743 3768 if (!base_operand(position, globals, result, name, opType)) {
3744 3769 position = 0;
3745 3770 if( base_operand(position, globals, result, name, opType) &&
3746 3771 (strcmp(opType,"RegI")==0 ||
3747 3772 strcmp(opType,"RegP")==0 ||
3748 3773 strcmp(opType,"RegN")==0 ||
3749 3774 strcmp(opType,"RegL")==0 ||
3750 3775 strcmp(opType,"RegF")==0 ||
3751 3776 strcmp(opType,"RegD")==0 ||
3752 3777 strcmp(opType,"Reg" )==0) ) {
3753 3778 return 1;
3754 3779 }
3755 3780 }
3756 3781 return 0;
3757 3782 }
3758 3783
3759 3784 Form::DataType MatchRule::is_base_constant(FormDict &globals) const {
3760 3785 uint position = 1;
3761 3786 const char *result = NULL;
3762 3787 const char *name = NULL;
3763 3788 const char *opType = NULL;
3764 3789 if (!base_operand(position, globals, result, name, opType)) {
3765 3790 position = 0;
3766 3791 if (base_operand(position, globals, result, name, opType)) {
3767 3792 return ideal_to_const_type(opType);
3768 3793 }
3769 3794 }
3770 3795 return Form::none;
3771 3796 }
3772 3797
3773 3798 bool MatchRule::is_chain_rule(FormDict &globals) const {
3774 3799
3775 3800 // Check for chain rule, and do not generate a match list for it
3776 3801 if ((_lChild == NULL) && (_rChild == NULL) ) {
3777 3802 const Form *form = globals[_opType];
3778 3803 // If this is ideal, then it is a base match, not a chain rule.
3779 3804 if ( form && form->is_operand() && (!form->ideal_only())) {
3780 3805 return true;
3781 3806 }
3782 3807 }
3783 3808 // Check for "Set" form of chain rule, and do not generate a match list
3784 3809 if (_rChild) {
3785 3810 const char *rch = _rChild->_opType;
3786 3811 const Form *form = globals[rch];
3787 3812 if ((!strcmp(_opType,"Set") &&
3788 3813 ((form) && form->is_operand()))) {
3789 3814 return true;
3790 3815 }
3791 3816 }
3792 3817 return false;
3793 3818 }
3794 3819
3795 3820 int MatchRule::is_ideal_copy() const {
3796 3821 if( _rChild ) {
3797 3822 const char *opType = _rChild->_opType;
3798 3823 #if 1
3799 3824 if( strcmp(opType,"CastIP")==0 )
3800 3825 return 1;
3801 3826 #else
3802 3827 if( strcmp(opType,"CastII")==0 )
3803 3828 return 1;
3804 3829 // Do not treat *CastPP this way, because it
3805 3830 // may transfer a raw pointer to an oop.
3806 3831 // If the register allocator were to coalesce this
3807 3832 // into a single LRG, the GC maps would be incorrect.
3808 3833 //if( strcmp(opType,"CastPP")==0 )
3809 3834 // return 1;
3810 3835 //if( strcmp(opType,"CheckCastPP")==0 )
3811 3836 // return 1;
3812 3837 //
3813 3838 // Do not treat CastX2P or CastP2X this way, because
3814 3839 // raw pointers and int types are treated differently
3815 3840 // when saving local & stack info for safepoints in
3816 3841 // Output().
3817 3842 //if( strcmp(opType,"CastX2P")==0 )
3818 3843 // return 1;
3819 3844 //if( strcmp(opType,"CastP2X")==0 )
3820 3845 // return 1;
3821 3846 #endif
3822 3847 }
3823 3848 if( is_chain_rule(_AD.globalNames()) &&
3824 3849 _lChild && strncmp(_lChild->_opType,"stackSlot",9)==0 )
3825 3850 return 1;
3826 3851 return 0;
3827 3852 }
3828 3853
3829 3854
3830 3855 int MatchRule::is_expensive() const {
3831 3856 if( _rChild ) {
3832 3857 const char *opType = _rChild->_opType;
3833 3858 if( strcmp(opType,"AtanD")==0 ||
3834 3859 strcmp(opType,"CosD")==0 ||
3835 3860 strcmp(opType,"DivD")==0 ||
3836 3861 strcmp(opType,"DivF")==0 ||
3837 3862 strcmp(opType,"DivI")==0 ||
3838 3863 strcmp(opType,"ExpD")==0 ||
3839 3864 strcmp(opType,"LogD")==0 ||
3840 3865 strcmp(opType,"Log10D")==0 ||
3841 3866 strcmp(opType,"ModD")==0 ||
3842 3867 strcmp(opType,"ModF")==0 ||
3843 3868 strcmp(opType,"ModI")==0 ||
3844 3869 strcmp(opType,"PowD")==0 ||
3845 3870 strcmp(opType,"SinD")==0 ||
3846 3871 strcmp(opType,"SqrtD")==0 ||
3847 3872 strcmp(opType,"TanD")==0 ||
3848 3873 strcmp(opType,"ConvD2F")==0 ||
3849 3874 strcmp(opType,"ConvD2I")==0 ||
3850 3875 strcmp(opType,"ConvD2L")==0 ||
3851 3876 strcmp(opType,"ConvF2D")==0 ||
3852 3877 strcmp(opType,"ConvF2I")==0 ||
3853 3878 strcmp(opType,"ConvF2L")==0 ||
3854 3879 strcmp(opType,"ConvI2D")==0 ||
3855 3880 strcmp(opType,"ConvI2F")==0 ||
3856 3881 strcmp(opType,"ConvI2L")==0 ||
3857 3882 strcmp(opType,"ConvL2D")==0 ||
3858 3883 strcmp(opType,"ConvL2F")==0 ||
3859 3884 strcmp(opType,"ConvL2I")==0 ||
3860 3885 strcmp(opType,"DecodeN")==0 ||
3861 3886 strcmp(opType,"EncodeP")==0 ||
3862 3887 strcmp(opType,"RoundDouble")==0 ||
3863 3888 strcmp(opType,"RoundFloat")==0 ||
3864 3889 strcmp(opType,"ReverseBytesI")==0 ||
3865 3890 strcmp(opType,"ReverseBytesL")==0 ||
3866 3891 strcmp(opType,"ReverseBytesUS")==0 ||
3867 3892 strcmp(opType,"ReverseBytesS")==0 ||
3868 3893 strcmp(opType,"Replicate16B")==0 ||
3869 3894 strcmp(opType,"Replicate8B")==0 ||
3870 3895 strcmp(opType,"Replicate4B")==0 ||
3871 3896 strcmp(opType,"Replicate8C")==0 ||
3872 3897 strcmp(opType,"Replicate4C")==0 ||
3873 3898 strcmp(opType,"Replicate8S")==0 ||
3874 3899 strcmp(opType,"Replicate4S")==0 ||
3875 3900 strcmp(opType,"Replicate4I")==0 ||
3876 3901 strcmp(opType,"Replicate2I")==0 ||
3877 3902 strcmp(opType,"Replicate2L")==0 ||
3878 3903 strcmp(opType,"Replicate4F")==0 ||
3879 3904 strcmp(opType,"Replicate2F")==0 ||
3880 3905 strcmp(opType,"Replicate2D")==0 ||
3881 3906 0 /* 0 to line up columns nicely */ )
3882 3907 return 1;
3883 3908 }
3884 3909 return 0;
3885 3910 }
3886 3911
3887 3912 bool MatchRule::is_ideal_unlock() const {
3888 3913 if( !_opType ) return false;
3889 3914 return !strcmp(_opType,"Unlock") || !strcmp(_opType,"FastUnlock");
3890 3915 }
3891 3916
3892 3917
3893 3918 bool MatchRule::is_ideal_call_leaf() const {
3894 3919 if( !_opType ) return false;
3895 3920 return !strcmp(_opType,"CallLeaf") ||
3896 3921 !strcmp(_opType,"CallLeafNoFP");
3897 3922 }
3898 3923
3899 3924
3900 3925 bool MatchRule::is_ideal_if() const {
3901 3926 if( !_opType ) return false;
3902 3927 return
3903 3928 !strcmp(_opType,"If" ) ||
3904 3929 !strcmp(_opType,"CountedLoopEnd");
3905 3930 }
3906 3931
3907 3932 bool MatchRule::is_ideal_fastlock() const {
3908 3933 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
3909 3934 return (strcmp(_rChild->_opType,"FastLock") == 0);
3910 3935 }
3911 3936 return false;
3912 3937 }
3913 3938
3914 3939 bool MatchRule::is_ideal_membar() const {
3915 3940 if( !_opType ) return false;
3916 3941 return
3917 3942 !strcmp(_opType,"MemBarAcquire" ) ||
3918 3943 !strcmp(_opType,"MemBarRelease" ) ||
3919 3944 !strcmp(_opType,"MemBarVolatile" ) ||
3920 3945 !strcmp(_opType,"MemBarCPUOrder" ) ;
3921 3946 }
3922 3947
3923 3948 bool MatchRule::is_ideal_loadPC() const {
3924 3949 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
3925 3950 return (strcmp(_rChild->_opType,"LoadPC") == 0);
3926 3951 }
3927 3952 return false;
3928 3953 }
3929 3954
3930 3955 bool MatchRule::is_ideal_box() const {
3931 3956 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
3932 3957 return (strcmp(_rChild->_opType,"Box") == 0);
3933 3958 }
3934 3959 return false;
3935 3960 }
3936 3961
3937 3962 bool MatchRule::is_ideal_goto() const {
3938 3963 bool ideal_goto = false;
3939 3964
3940 3965 if( _opType && (strcmp(_opType,"Goto") == 0) ) {
3941 3966 ideal_goto = true;
3942 3967 }
3943 3968 return ideal_goto;
3944 3969 }
3945 3970
3946 3971 bool MatchRule::is_ideal_jump() const {
3947 3972 if( _opType ) {
3948 3973 if( !strcmp(_opType,"Jump") )
3949 3974 return true;
3950 3975 }
3951 3976 return false;
3952 3977 }
3953 3978
3954 3979 bool MatchRule::is_ideal_bool() const {
3955 3980 if( _opType ) {
3956 3981 if( !strcmp(_opType,"Bool") )
3957 3982 return true;
3958 3983 }
3959 3984 return false;
3960 3985 }
3961 3986
3962 3987
3963 3988 Form::DataType MatchRule::is_ideal_load() const {
3964 3989 Form::DataType ideal_load = Form::none;
3965 3990
3966 3991 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
3967 3992 const char *opType = _rChild->_opType;
3968 3993 ideal_load = is_load_from_memory(opType);
3969 3994 }
3970 3995
3971 3996 return ideal_load;
3972 3997 }
3973 3998
3974 3999
3975 4000 bool MatchRule::skip_antidep_check() const {
3976 4001 // Some loads operate on what is effectively immutable memory so we
3977 4002 // should skip the anti dep computations. For some of these nodes
3978 4003 // the rewritable field keeps the anti dep logic from triggering but
3979 4004 // for certain kinds of LoadKlass it does not since they are
3980 4005 // actually reading memory which could be rewritten by the runtime,
3981 4006 // though never by generated code. This disables it uniformly for
3982 4007 // the nodes that behave like this: LoadKlass, LoadNKlass and
3983 4008 // LoadRange.
3984 4009 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
3985 4010 const char *opType = _rChild->_opType;
3986 4011 if (strcmp("LoadKlass", opType) == 0 ||
3987 4012 strcmp("LoadNKlass", opType) == 0 ||
3988 4013 strcmp("LoadRange", opType) == 0) {
3989 4014 return true;
3990 4015 }
3991 4016 }
3992 4017
3993 4018 return false;
3994 4019 }
3995 4020
3996 4021
3997 4022 Form::DataType MatchRule::is_ideal_store() const {
3998 4023 Form::DataType ideal_store = Form::none;
3999 4024
4000 4025 if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) {
4001 4026 const char *opType = _rChild->_opType;
4002 4027 ideal_store = is_store_to_memory(opType);
4003 4028 }
4004 4029
4005 4030 return ideal_store;
4006 4031 }
4007 4032
4008 4033
4009 4034 void MatchRule::dump() {
4010 4035 output(stderr);
4011 4036 }
4012 4037
4013 4038 void MatchRule::output(FILE *fp) {
4014 4039 fprintf(fp,"MatchRule: ( %s",_name);
4015 4040 if (_lChild) _lChild->output(fp);
4016 4041 if (_rChild) _rChild->output(fp);
4017 4042 fprintf(fp," )\n");
4018 4043 fprintf(fp," nesting depth = %d\n", _depth);
4019 4044 if (_result) fprintf(fp," Result Type = %s", _result);
4020 4045 fprintf(fp,"\n");
4021 4046 }
4022 4047
4023 4048 //------------------------------Attribute--------------------------------------
4024 4049 Attribute::Attribute(char *id, char* val, int type)
4025 4050 : _ident(id), _val(val), _atype(type) {
4026 4051 }
4027 4052 Attribute::~Attribute() {
4028 4053 }
4029 4054
4030 4055 int Attribute::int_val(ArchDesc &ad) {
4031 4056 // Make sure it is an integer constant:
4032 4057 int result = 0;
4033 4058 if (!_val || !ADLParser::is_int_token(_val, result)) {
4034 4059 ad.syntax_err(0, "Attribute %s must have an integer value: %s",
4035 4060 _ident, _val ? _val : "");
4036 4061 }
4037 4062 return result;
4038 4063 }
4039 4064
4040 4065 void Attribute::dump() {
4041 4066 output(stderr);
4042 4067 } // Debug printer
4043 4068
4044 4069 // Write to output files
4045 4070 void Attribute::output(FILE *fp) {
4046 4071 fprintf(fp,"Attribute: %s %s\n", (_ident?_ident:""), (_val?_val:""));
4047 4072 }
4048 4073
4049 4074 //------------------------------FormatRule----------------------------------
4050 4075 FormatRule::FormatRule(char *temp)
4051 4076 : _temp(temp) {
4052 4077 }
4053 4078 FormatRule::~FormatRule() {
4054 4079 }
4055 4080
4056 4081 void FormatRule::dump() {
4057 4082 output(stderr);
4058 4083 }
4059 4084
4060 4085 // Write to output files
4061 4086 void FormatRule::output(FILE *fp) {
4062 4087 fprintf(fp,"\nFormat Rule: \n%s", (_temp?_temp:""));
4063 4088 fprintf(fp,"\n");
4064 4089 }
↓ open down ↓ |
2704 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX