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