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