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