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