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