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