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