Mercurial > hg > truffle
annotate src/share/vm/adlc/formssel.hpp @ 599:0ad1cb407fa1
6805427: adlc compiler may generate incorrect machnode emission code
Reviewed-by: kvn, twisti
author | never |
---|---|
date | Wed, 25 Feb 2009 10:53:14 -0800 |
parents | ad8c8ca4ab0f |
children | dbbe28fc66b5 |
rev | line source |
---|---|
0 | 1 /* |
470 | 2 * Copyright 1998-2008 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // FORMSSEL.HPP - ADL Parser Instruction Selection Forms Classes | |
26 | |
27 // Class List | |
28 class Form; | |
29 class InstructForm; | |
30 class MachNodeForm; | |
31 class OperandForm; | |
32 class OpClassForm; | |
33 class AttributeForm; | |
34 class RegisterForm; | |
35 class PipelineForm; | |
36 class SourceForm; | |
37 class EncodeForm; | |
38 class Component; | |
39 class Constraint; | |
40 class Predicate; | |
41 class MatchRule; | |
42 class Attribute; | |
43 class Effect; | |
44 class ExpandRule; | |
45 class RewriteRule; | |
46 class ConstructRule; | |
47 class FormatRule; | |
48 class Peephole; | |
49 class EncClass; | |
50 class Interface; | |
51 class RegInterface; | |
52 class ConstInterface; | |
53 class MemInterface; | |
54 class CondInterface; | |
55 class Opcode; | |
56 class InsEncode; | |
57 class RegDef; | |
58 class RegClass; | |
59 class AllocClass; | |
60 class ResourceForm; | |
61 class PipeDesc; | |
62 class PipeClass; | |
63 class PeepMatch; | |
64 class PeepConstraint; | |
65 class PeepReplace; | |
66 class MatchList; | |
67 | |
68 class ArchDesc; | |
69 | |
70 //==============================Instructions=================================== | |
71 //------------------------------InstructForm----------------------------------- | |
72 class InstructForm : public Form { | |
73 private: | |
74 bool _ideal_only; // Not a user-defined instruction | |
75 // Members used for tracking CISC-spilling | |
76 uint _cisc_spill_operand;// Which operand may cisc-spill | |
77 void set_cisc_spill_operand(uint op_index) { _cisc_spill_operand = op_index; } | |
78 bool _is_cisc_alternate; | |
79 InstructForm *_cisc_spill_alternate;// cisc possible replacement | |
80 const char *_cisc_reg_mask_name; | |
81 InstructForm *_short_branch_form; | |
82 bool _is_short_branch; | |
83 uint _alignment; | |
84 | |
85 public: | |
86 // Public Data | |
87 const char *_ident; // Name of this instruction | |
88 NameList _parameters; // Locally defined names | |
89 FormDict _localNames; // Table of operands & their types | |
90 MatchRule *_matrule; // Matching rule for this instruction | |
91 Opcode *_opcode; // Encoding of the opcode for instruction | |
92 char *_size; // Size of instruction | |
93 InsEncode *_insencode; // Encoding class instruction belongs to | |
94 Attribute *_attribs; // List of Attribute rules | |
95 Predicate *_predicate; // Predicate test for this instruction | |
96 FormDict _effects; // Dictionary of effect rules | |
97 ExpandRule *_exprule; // Expand rule for this instruction | |
98 RewriteRule *_rewrule; // Rewrite rule for this instruction | |
99 FormatRule *_format; // Format for assembly generation | |
100 Peephole *_peephole; // List of peephole rules for instruction | |
101 const char *_ins_pipe; // Instruction Scheduline description class | |
102 | |
103 uint *_uniq_idx; // Indexes of unique operands | |
599
0ad1cb407fa1
6805427: adlc compiler may generate incorrect machnode emission code
never
parents:
470
diff
changeset
|
104 int _uniq_idx_length; // Length of _uniq_idx array |
0 | 105 uint _num_uniq; // Number of unique operands |
106 ComponentList _components; // List of Components matches MachNode's | |
107 // operand structure | |
108 | |
109 // Public Methods | |
110 InstructForm(const char *id, bool ideal_only = false); | |
111 InstructForm(const char *id, InstructForm *instr, MatchRule *rule); | |
112 ~InstructForm(); | |
113 | |
114 // Dynamic type check | |
115 virtual InstructForm *is_instruction() const; | |
116 | |
117 virtual bool ideal_only() const; | |
118 | |
119 // This instruction sets a result | |
120 virtual bool sets_result() const; | |
121 // This instruction needs projections for additional DEFs or KILLs | |
122 virtual bool needs_projections(); | |
123 // This instruction needs extra nodes for temporary inputs | |
124 virtual bool has_temps(); | |
125 // This instruction defines or kills more than one object | |
126 virtual uint num_defs_or_kills(); | |
127 // This instruction has an expand rule? | |
128 virtual bool expands() const ; | |
129 // Return this instruction's first peephole rule, or NULL | |
130 virtual Peephole *peepholes() const; | |
131 // Add a peephole rule to this instruction | |
132 virtual void append_peephole(Peephole *peep); | |
133 | |
134 virtual bool is_pinned(FormDict &globals); // should be pinned inside block | |
135 virtual bool is_projection(FormDict &globals); // node requires projection | |
136 virtual bool is_parm(FormDict &globals); // node matches ideal 'Parm' | |
137 // ideal opcode enumeration | |
138 virtual const char *ideal_Opcode(FormDict &globals) const; | |
139 virtual int is_expensive() const; // node matches ideal 'CosD' | |
140 virtual int is_empty_encoding() const; // _size=0 and/or _insencode empty | |
141 virtual int is_tls_instruction() const; // tlsLoadP rule or ideal ThreadLocal | |
142 virtual int is_ideal_copy() const; // node matches ideal 'Copy*' | |
143 virtual bool is_ideal_unlock() const; // node matches ideal 'Unlock' | |
144 virtual bool is_ideal_call_leaf() const; // node matches ideal 'CallLeaf' | |
145 virtual bool is_ideal_if() const; // node matches ideal 'If' | |
146 virtual bool is_ideal_fastlock() const; // node matches 'FastLock' | |
147 virtual bool is_ideal_membar() const; // node matches ideal 'MemBarXXX' | |
148 virtual bool is_ideal_loadPC() const; // node matches ideal 'LoadPC' | |
149 virtual bool is_ideal_box() const; // node matches ideal 'Box' | |
150 virtual bool is_ideal_goto() const; // node matches ideal 'Goto' | |
151 virtual bool is_ideal_branch() const; // "" 'If' | 'Goto' | 'LoopEnd' | 'Jump' | |
152 virtual bool is_ideal_jump() const; // node matches ideal 'Jump' | |
153 virtual bool is_ideal_return() const; // node matches ideal 'Return' | |
154 virtual bool is_ideal_halt() const; // node matches ideal 'Halt' | |
155 virtual bool is_ideal_safepoint() const; // node matches 'SafePoint' | |
156 virtual bool is_ideal_nop() const; // node matches 'Nop' | |
157 virtual bool is_ideal_control() const; // control node | |
158 | |
159 virtual Form::CallType is_ideal_call() const; // matches ideal 'Call' | |
160 virtual Form::DataType is_ideal_load() const; // node matches ideal 'LoadXNode' | |
161 virtual Form::DataType is_ideal_store() const;// node matches ideal 'StoreXNode' | |
162 bool is_ideal_mem() const { return is_ideal_load() != Form::none || is_ideal_store() != Form::none; } | |
163 virtual uint two_address(FormDict &globals); // output reg must match input reg | |
164 // when chaining a constant to an instruction, return 'true' and set opType | |
165 virtual Form::DataType is_chain_of_constant(FormDict &globals); | |
166 virtual Form::DataType is_chain_of_constant(FormDict &globals, const char * &opType); | |
167 virtual Form::DataType is_chain_of_constant(FormDict &globals, const char * &opType, const char * &result_type); | |
168 | |
169 // Check if a simple chain rule | |
170 virtual bool is_simple_chain_rule(FormDict &globals) const; | |
171 | |
172 // check for structural rematerialization | |
173 virtual bool rematerialize(FormDict &globals, RegisterForm *registers); | |
174 | |
175 // loads from memory, so must check for anti-dependence | |
176 virtual bool needs_anti_dependence_check(FormDict &globals) const; | |
177 virtual int memory_operand(FormDict &globals) const; | |
178 bool is_wide_memory_kill(FormDict &globals) const; | |
179 | |
180 enum memory_operand_type { | |
181 NO_MEMORY_OPERAND = -1, | |
182 MANY_MEMORY_OPERANDS = 999999 | |
183 }; | |
184 | |
185 | |
186 // This instruction captures the machine-independent bottom_type | |
187 // Expected use is for pointer vs oop determination for LoadP | |
188 virtual bool captures_bottom_type() const; | |
189 | |
190 virtual const char *cost(); // Access ins_cost attribute | |
191 virtual uint num_opnds(); // Count of num_opnds for MachNode class | |
192 virtual uint num_post_match_opnds(); | |
193 virtual uint num_consts(FormDict &globals) const;// Constants in match rule | |
194 // Constants in match rule with specified type | |
195 virtual uint num_consts(FormDict &globals, Form::DataType type) const; | |
196 | |
197 // Return the register class associated with 'leaf'. | |
198 virtual const char *out_reg_class(FormDict &globals); | |
199 | |
200 // number of ideal node inputs to skip | |
201 virtual uint oper_input_base(FormDict &globals); | |
202 | |
203 // Does this instruction need a base-oop edge? | |
204 int needs_base_oop_edge(FormDict &globals) const; | |
205 | |
206 // Build instruction predicates. If the user uses the same operand name | |
207 // twice, we need to check that the operands are pointer-eequivalent in | |
208 // the DFA during the labeling process. | |
209 Predicate *build_predicate(); | |
210 | |
211 virtual void build_components(); // top-level operands | |
212 // Return zero-based position in component list; -1 if not in list. | |
213 virtual int operand_position(const char *name, int usedef); | |
214 virtual int operand_position_format(const char *name); | |
215 | |
216 // Return zero-based position in component list; -1 if not in list. | |
217 virtual int label_position(); | |
218 virtual int method_position(); | |
219 // Return number of relocation entries needed for this instruction. | |
220 virtual uint reloc(FormDict &globals); | |
221 | |
222 const char *reduce_result(); | |
223 // Return the name of the operand on the right hand side of the binary match | |
224 // Return NULL if there is no right hand side | |
225 const char *reduce_right(FormDict &globals) const; | |
226 const char *reduce_left(FormDict &globals) const; | |
227 | |
228 // Base class for this instruction, MachNode except for calls | |
229 virtual const char *mach_base_class() const; | |
230 | |
231 // Check if this instruction can cisc-spill to 'alternate' | |
232 bool cisc_spills_to(ArchDesc &AD, InstructForm *alternate); | |
233 InstructForm *cisc_spill_alternate() { return _cisc_spill_alternate; } | |
234 uint cisc_spill_operand() const { return _cisc_spill_operand; } | |
235 bool is_cisc_alternate() const { return _is_cisc_alternate; } | |
236 void set_cisc_alternate(bool val) { _is_cisc_alternate = val; } | |
237 const char *cisc_reg_mask_name() const { return _cisc_reg_mask_name; } | |
238 void set_cisc_reg_mask_name(const char *rm_name) { _cisc_reg_mask_name = rm_name; } | |
239 // Output cisc-method prototypes and method bodies | |
240 void declare_cisc_version(ArchDesc &AD, FILE *fp_cpp); | |
241 bool define_cisc_version (ArchDesc &AD, FILE *fp_cpp); | |
242 | |
243 bool check_branch_variant(ArchDesc &AD, InstructForm *short_branch); | |
244 | |
245 bool is_short_branch() { return _is_short_branch; } | |
246 void set_short_branch(bool val) { _is_short_branch = val; } | |
247 | |
248 InstructForm *short_branch_form() { return _short_branch_form; } | |
249 bool has_short_branch_form() { return _short_branch_form != NULL; } | |
250 // Output short branch prototypes and method bodies | |
251 void declare_short_branch_methods(FILE *fp_cpp); | |
252 bool define_short_branch_methods(FILE *fp_cpp); | |
253 | |
254 uint alignment() { return _alignment; } | |
255 void set_alignment(uint val) { _alignment = val; } | |
256 | |
257 // Seach through operands to determine operands unique positions. | |
258 void set_unique_opnds(); | |
259 uint num_unique_opnds() { return _num_uniq; } | |
260 uint unique_opnds_idx(int idx) { | |
599
0ad1cb407fa1
6805427: adlc compiler may generate incorrect machnode emission code
never
parents:
470
diff
changeset
|
261 if( _uniq_idx != NULL && idx > 0 ) { |
0ad1cb407fa1
6805427: adlc compiler may generate incorrect machnode emission code
never
parents:
470
diff
changeset
|
262 assert(idx < _uniq_idx_length, "out of bounds"); |
0 | 263 return _uniq_idx[idx]; |
599
0ad1cb407fa1
6805427: adlc compiler may generate incorrect machnode emission code
never
parents:
470
diff
changeset
|
264 } else { |
0 | 265 return idx; |
599
0ad1cb407fa1
6805427: adlc compiler may generate incorrect machnode emission code
never
parents:
470
diff
changeset
|
266 } |
0ad1cb407fa1
6805427: adlc compiler may generate incorrect machnode emission code
never
parents:
470
diff
changeset
|
267 } |
0 | 268 |
269 // Operands which are only KILLs aren't part of the input array and | |
270 // require special handling in some cases. Their position in this | |
271 // operand list is higher than the number of unique operands. | |
272 bool is_noninput_operand(uint idx) { | |
273 return (idx >= num_unique_opnds()); | |
274 } | |
275 | |
276 // --------------------------- FILE *output_routines | |
277 // | |
278 // Generate the format call for the replacement variable | |
279 void rep_var_format(FILE *fp, const char *rep_var); | |
280 // Generate index values needed for determing the operand position | |
281 void index_temps (FILE *fp, FormDict &globals, const char *prefix = "", const char *receiver = ""); | |
282 // --------------------------- | |
283 | |
284 virtual bool verify(); // Check consistency after parsing | |
285 | |
286 virtual void dump(); // Debug printer | |
287 virtual void output(FILE *fp); // Write to output files | |
288 }; | |
289 | |
290 //------------------------------EncodeForm------------------------------------- | |
291 class EncodeForm : public Form { | |
292 private: | |
293 | |
294 public: | |
295 // Public Data | |
296 NameList _eclasses; // List of encode class names | |
297 Dict _encClass; // Map encode class names to EncClass objects | |
298 | |
299 // Public Methods | |
300 EncodeForm(); | |
301 ~EncodeForm(); | |
302 | |
303 EncClass *add_EncClass(const char *className); | |
304 EncClass *encClass(const char *className); | |
305 | |
306 const char *encClassPrototype(const char *className); | |
307 const char *encClassBody(const char *className); | |
308 | |
309 void dump(); // Debug printer | |
310 void output(FILE *fp); // Write info to output files | |
311 }; | |
312 | |
313 //------------------------------EncClass--------------------------------------- | |
314 class EncClass : public Form { | |
315 public: | |
316 // NameList for parameter type and name | |
317 NameList _parameter_type; | |
318 NameList _parameter_name; | |
319 | |
320 // Breakdown the encoding into strings separated by $replacement_variables | |
321 // There is an entry in _strings, perhaps NULL, that precedes each _rep_vars | |
322 NameList _code; // Strings passed through to tty->print | |
323 NameList _rep_vars; // replacement variables | |
324 | |
325 NameList _parameters; // Locally defined names | |
326 FormDict _localNames; // Table of components & their types | |
327 | |
328 public: | |
329 // Public Data | |
330 const char *_name; // encoding class name | |
331 | |
332 // Public Methods | |
333 EncClass(const char *name); | |
334 ~EncClass(); | |
335 | |
336 // --------------------------- Parameters | |
337 // Add a parameter <type,name> pair | |
338 void add_parameter(const char *parameter_type, const char *parameter_name); | |
339 // Verify operand types in parameter list | |
340 bool check_parameter_types(FormDict &globals); | |
341 // Obtain the zero-based index corresponding to a replacement variable | |
342 int rep_var_index(const char *rep_var); | |
343 int num_args() { return _parameter_name.count(); } | |
344 | |
345 // --------------------------- Code Block | |
346 // Add code | |
347 void add_code(const char *string_preceeding_replacement_var); | |
348 // Add a replacement variable or one of its subfields | |
349 // Subfields are stored with a leading '$' | |
350 void add_rep_var(char *replacement_var); | |
351 | |
352 bool verify(); | |
353 void dump(); | |
354 void output(FILE *fp); | |
355 }; | |
356 | |
357 //------------------------------MachNode--------------------------------------- | |
358 class MachNodeForm: public Form { | |
359 private: | |
360 | |
361 public: | |
362 char *_ident; // Name of this instruction | |
363 const char *_machnode_pipe; // Instruction Scheduline description class | |
364 | |
365 // Public Methods | |
366 MachNodeForm(char *id); | |
367 ~MachNodeForm(); | |
368 | |
369 virtual MachNodeForm *is_machnode() const; | |
370 | |
371 void dump(); // Debug printer | |
372 void output(FILE *fp); // Write info to output files | |
373 }; | |
374 | |
375 //------------------------------Opcode----------------------------------------- | |
376 class Opcode : public Form { | |
377 private: | |
378 | |
379 public: | |
380 // Public Data | |
381 // Strings representing instruction opcodes, user defines placement in emit | |
382 char *_primary; | |
383 char *_secondary; | |
384 char *_tertiary; | |
385 | |
386 enum opcode_type { | |
387 NOT_AN_OPCODE = -1, | |
388 PRIMARY = 1, | |
389 SECONDARY = 2, | |
390 TERTIARY = 3 | |
391 }; | |
392 | |
393 // Public Methods | |
394 Opcode(char *primary, char *secondary, char *tertiary); | |
395 ~Opcode(); | |
396 | |
397 static Opcode::opcode_type as_opcode_type(const char *designator); | |
398 | |
399 void dump(); | |
400 void output(FILE *fp); | |
401 | |
402 // --------------------------- FILE *output_routines | |
415
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
403 bool print_opcode(FILE *fp, Opcode::opcode_type desired_opcode); |
0 | 404 }; |
405 | |
406 //------------------------------InsEncode-------------------------------------- | |
407 class InsEncode : public Form { | |
408 private: | |
409 // Public Data (access directly only for reads) | |
410 // The encodings can only have the values predefined by the ADLC: | |
411 // blank, RegReg, RegMem, MemReg, ... | |
412 NameList _encoding; | |
413 // NameList _parameter; | |
414 // The parameters for each encoding are preceeded by a NameList::_signal | |
415 // and follow the parameters for the previous encoding. | |
416 | |
417 // char *_encode; // Type of instruction encoding | |
418 | |
419 public: | |
420 // Public Methods | |
421 InsEncode(); | |
422 ~InsEncode(); | |
423 | |
424 // Add "encode class name" and its parameters | |
425 NameAndList *add_encode(char *encode_method_name); | |
426 // Parameters are added to the returned "NameAndList" by the parser | |
427 | |
428 // Access the list of encodings | |
429 void reset(); | |
430 const char *encode_class_iter(); | |
431 | |
432 // Returns the number of arguments to the current encoding in the iteration | |
433 int current_encoding_num_args() { | |
434 return ((NameAndList*)_encoding.current())->count(); | |
435 } | |
436 | |
437 // --------------------------- Parameters | |
438 // The following call depends upon position within encode_class_iteration | |
439 // | |
440 // Obtain parameter name from zero based index | |
441 const char *rep_var_name(InstructForm &inst, uint param_no); | |
442 // --------------------------- | |
443 | |
444 void dump(); | |
445 void output(FILE *fp); | |
446 }; | |
447 | |
448 //------------------------------Effect----------------------------------------- | |
449 class Effect : public Form { | |
450 private: | |
451 | |
452 public: | |
453 // Public Data | |
454 const char *_name; // Pre-defined name for effect | |
455 int _use_def; // Enumeration value of effect | |
456 | |
457 // Public Methods | |
458 Effect(const char *name); // Constructor | |
459 ~Effect(); // Destructor | |
460 | |
461 // Dynamic type check | |
462 virtual Effect *is_effect() const; | |
463 | |
464 // Return 'true' if this use def info equals the parameter | |
465 bool is(int use_def_kill_enum) const; | |
466 // Return 'true' if this use def info is a superset of parameter | |
467 bool isa(int use_def_kill_enum) const; | |
468 | |
469 void dump(); // Debug printer | |
470 void output(FILE *fp); // Write info to output files | |
471 }; | |
472 | |
473 //------------------------------ExpandRule------------------------------------- | |
474 class ExpandRule : public Form { | |
475 private: | |
476 NameList _expand_instrs; // ordered list of instructions and operands | |
477 | |
478 public: | |
479 // Public Data | |
480 NameList _newopers; // List of newly created operands | |
481 Dict _newopconst; // Map new operands to their constructors | |
482 | |
483 void add_instruction(NameAndList *instruction_name_and_operand_list); | |
484 void reset_instructions(); | |
485 NameAndList *iter_instructions(); | |
486 | |
487 // Public Methods | |
488 ExpandRule(); // Constructor | |
489 ~ExpandRule(); // Destructor | |
490 | |
491 void dump(); // Debug printer | |
492 void output(FILE *fp); // Write info to output files | |
493 }; | |
494 | |
495 //------------------------------RewriteRule------------------------------------ | |
496 class RewriteRule : public Form { | |
497 private: | |
498 | |
499 public: | |
500 // Public Data | |
501 SourceForm *_condition; // Rewrite condition code | |
502 InstructForm *_instrs; // List of instructions to expand to | |
503 OperandForm *_opers; // List of operands generated by expand | |
504 char *_tempParams; // Hold string until parser is finished. | |
505 char *_tempBlock; // Hold string until parser is finished. | |
506 | |
507 // Public Methods | |
508 RewriteRule(char* params, char* block) ; | |
509 ~RewriteRule(); // Destructor | |
510 void dump(); // Debug printer | |
511 void output(FILE *fp); // Write info to output files | |
512 }; | |
513 | |
514 | |
515 //==============================Operands======================================= | |
516 //------------------------------OpClassForm------------------------------------ | |
517 class OpClassForm : public Form { | |
518 public: | |
519 // Public Data | |
520 const char *_ident; // Name of this operand | |
521 NameList _oplst; // List of operand forms included in class | |
522 | |
523 // Public Methods | |
524 OpClassForm(const char *id); | |
525 ~OpClassForm(); | |
526 | |
527 // dynamic type check | |
528 virtual OpClassForm *is_opclass() const; | |
529 virtual Form::InterfaceType interface_type(FormDict &globals) const; | |
530 virtual bool stack_slots_only(FormDict &globals) const; | |
531 | |
532 virtual bool is_cisc_mem(FormDict &globals) const; | |
533 | |
534 | |
535 // Min and Max opcodes of operands in this operand class | |
536 int _minCode; | |
537 int _maxCode; | |
538 | |
539 virtual bool ideal_only() const; | |
540 virtual void dump(); // Debug printer | |
541 virtual void output(FILE *fp); // Write to output files | |
542 }; | |
543 | |
544 //------------------------------OperandForm------------------------------------ | |
545 class OperandForm : public OpClassForm { | |
546 private: | |
547 bool _ideal_only; // Not a user-defined instruction | |
548 | |
549 public: | |
550 // Public Data | |
551 NameList _parameters; // Locally defined names | |
552 FormDict _localNames; // Table of components & their types | |
553 MatchRule *_matrule; // Matching rule for this operand | |
554 Interface *_interface; // Encoding interface for this operand | |
555 Attribute *_attribs; // List of Attribute rules | |
556 Predicate *_predicate; // Predicate test for this operand | |
557 Constraint *_constraint; // Constraint Rule for this operand | |
558 ConstructRule *_construct; // Construction of operand data after matching | |
559 FormatRule *_format; // Format for assembly generation | |
560 NameList _classes; // List of opclasses which contain this oper | |
561 | |
562 ComponentList _components; // | |
563 | |
564 // Public Methods | |
565 OperandForm(const char *id); | |
566 OperandForm(const char *id, bool ideal_only); | |
567 ~OperandForm(); | |
568 | |
569 // Dynamic type check | |
570 virtual OperandForm *is_operand() const; | |
571 | |
572 virtual bool ideal_only() const; | |
573 virtual Form::InterfaceType interface_type(FormDict &globals) const; | |
574 virtual bool stack_slots_only(FormDict &globals) const; | |
575 | |
576 virtual const char *cost(); // Access ins_cost attribute | |
577 virtual uint num_leaves() const;// Leaves in complex operand | |
578 // Constants in operands' match rules | |
579 virtual uint num_consts(FormDict &globals) const; | |
580 // Constants in operand's match rule with specified type | |
581 virtual uint num_consts(FormDict &globals, Form::DataType type) const; | |
582 // Pointer Constants in operands' match rules | |
583 virtual uint num_const_ptrs(FormDict &globals) const; | |
584 // The number of input edges in the machine world == num_leaves - num_consts | |
585 virtual uint num_edges(FormDict &globals) const; | |
586 | |
587 // Check if this operand is usable for cisc-spilling | |
588 virtual bool is_cisc_reg(FormDict &globals) const; | |
589 | |
590 // node matches ideal 'Bool', grab condition codes from the ideal world | |
591 virtual bool is_ideal_bool() const; | |
592 | |
593 // Has an integer constant suitable for spill offsets | |
594 bool has_conI(FormDict &globals) const { | |
595 return (num_consts(globals,idealI) == 1) && !is_ideal_bool(); } | |
596 bool has_conL(FormDict &globals) const { | |
597 return (num_consts(globals,idealL) == 1) && !is_ideal_bool(); } | |
598 | |
599 // Node is user-defined operand for an sRegX | |
600 virtual Form::DataType is_user_name_for_sReg() const; | |
601 | |
602 // Return ideal type, if there is a single ideal type for this operand | |
603 virtual const char *ideal_type(FormDict &globals, RegisterForm *registers = NULL) const; | |
604 // If there is a single ideal type for this interface field, return it. | |
605 virtual const char *interface_ideal_type(FormDict &globals, | |
606 const char *field_name) const; | |
607 | |
608 // Return true if this operand represents a bound register class | |
609 bool is_bound_register() const; | |
610 | |
611 // Return the Register class for this operand. Returns NULL if | |
612 // operand isn't a register form. | |
613 RegClass* get_RegClass() const; | |
614 | |
615 virtual bool is_interface_field(const char *field_name, | |
616 const char * &value) const; | |
617 | |
618 // If this operand has a single ideal type, return its type | |
619 virtual Form::DataType simple_type(FormDict &globals) const; | |
620 // If this operand is an ideal constant, return its type | |
621 virtual Form::DataType is_base_constant(FormDict &globals) const; | |
622 | |
623 // "true" if this operand is a simple type that is swallowed | |
624 virtual bool swallowed(FormDict &globals) const; | |
625 | |
626 // Return register class name if a constraint specifies the register class. | |
627 virtual const char *constrained_reg_class() const; | |
628 // Return the register class associated with 'leaf'. | |
629 virtual const char *in_reg_class(uint leaf, FormDict &globals); | |
630 | |
631 // Build component list from MatchRule and operand's parameter list | |
632 virtual void build_components(); // top-level operands | |
633 | |
634 // Return zero-based position in component list; -1 if not in list. | |
635 virtual int operand_position(const char *name, int usedef); | |
636 | |
637 // Return zero-based position in component list; -1 if not in list. | |
638 virtual int constant_position(FormDict &globals, const Component *comp); | |
639 virtual int constant_position(FormDict &globals, const char *local_name); | |
640 // Return the operand form corresponding to the given index, else NULL. | |
641 virtual OperandForm *constant_operand(FormDict &globals, uint const_index); | |
642 | |
643 // Return zero-based position in component list; -1 if not in list. | |
644 virtual int register_position(FormDict &globals, const char *regname); | |
645 | |
646 const char *reduce_result() const; | |
647 // Return the name of the operand on the right hand side of the binary match | |
648 // Return NULL if there is no right hand side | |
649 const char *reduce_right(FormDict &globals) const; | |
650 const char *reduce_left(FormDict &globals) const; | |
651 | |
652 | |
653 // --------------------------- FILE *output_routines | |
654 // | |
655 // Output code for disp_is_oop, if true. | |
656 void disp_is_oop(FILE *fp, FormDict &globals); | |
657 // Generate code for internal and external format methods | |
658 void int_format(FILE *fp, FormDict &globals, uint index); | |
659 void ext_format(FILE *fp, FormDict &globals, uint index); | |
660 void format_constant(FILE *fp, uint con_index, uint con_type); | |
661 // Output code to access the value of the index'th constant | |
662 void access_constant(FILE *fp, FormDict &globals, | |
663 uint con_index); | |
664 // --------------------------- | |
665 | |
666 | |
667 virtual void dump(); // Debug printer | |
668 virtual void output(FILE *fp); // Write to output files | |
669 }; | |
670 | |
671 //------------------------------Constraint------------------------------------- | |
672 class Constraint : public Form { | |
673 private: | |
674 | |
675 public: | |
676 const char *_func; // Constraint function | |
677 const char *_arg; // function's argument | |
678 | |
679 // Public Methods | |
680 Constraint(const char *func, const char *arg); // Constructor | |
681 ~Constraint(); | |
682 | |
683 bool stack_slots_only() const; | |
684 | |
685 void dump(); // Debug printer | |
686 void output(FILE *fp); // Write info to output files | |
687 }; | |
688 | |
689 //------------------------------Predicate-------------------------------------- | |
690 class Predicate : public Form { | |
691 private: | |
692 | |
693 public: | |
694 // Public Data | |
695 char *_pred; // C++ source string for predicate | |
696 | |
697 // Public Methods | |
698 Predicate(char *pr); | |
699 ~Predicate(); | |
700 | |
701 void dump(); | |
702 void output(FILE *fp); | |
703 }; | |
704 | |
705 //------------------------------Interface-------------------------------------- | |
706 class Interface : public Form { | |
707 private: | |
708 | |
709 public: | |
710 // Public Data | |
711 const char *_name; // String representing the interface name | |
712 | |
713 // Public Methods | |
714 Interface(const char *name); | |
715 ~Interface(); | |
716 | |
717 virtual Form::InterfaceType interface_type(FormDict &globals) const; | |
718 | |
719 RegInterface *is_RegInterface(); | |
720 MemInterface *is_MemInterface(); | |
721 ConstInterface *is_ConstInterface(); | |
722 CondInterface *is_CondInterface(); | |
723 | |
724 | |
725 void dump(); | |
726 void output(FILE *fp); | |
727 }; | |
728 | |
729 //------------------------------RegInterface----------------------------------- | |
730 class RegInterface : public Interface { | |
731 private: | |
732 | |
733 public: | |
734 // Public Methods | |
735 RegInterface(); | |
736 ~RegInterface(); | |
737 | |
738 void dump(); | |
739 void output(FILE *fp); | |
740 }; | |
741 | |
742 //------------------------------ConstInterface--------------------------------- | |
743 class ConstInterface : public Interface { | |
744 private: | |
745 | |
746 public: | |
747 // Public Methods | |
748 ConstInterface(); | |
749 ~ConstInterface(); | |
750 | |
751 void dump(); | |
752 void output(FILE *fp); | |
753 }; | |
754 | |
755 //------------------------------MemInterface----------------------------------- | |
756 class MemInterface : public Interface { | |
757 private: | |
758 | |
759 public: | |
760 // Public Data | |
761 char *_base; // Base address | |
762 char *_index; // index | |
763 char *_scale; // scaling factor | |
764 char *_disp; // displacement | |
765 | |
766 // Public Methods | |
767 MemInterface(char *base, char *index, char *scale, char *disp); | |
768 ~MemInterface(); | |
769 | |
770 void dump(); | |
771 void output(FILE *fp); | |
772 }; | |
773 | |
774 //------------------------------CondInterface---------------------------------- | |
775 class CondInterface : public Interface { | |
776 private: | |
777 | |
778 public: | |
779 const char *_equal; | |
780 const char *_not_equal; | |
781 const char *_less; | |
782 const char *_greater_equal; | |
783 const char *_less_equal; | |
784 const char *_greater; | |
415
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
785 const char *_equal_format; |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
786 const char *_not_equal_format; |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
787 const char *_less_format; |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
788 const char *_greater_equal_format; |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
789 const char *_less_equal_format; |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
790 const char *_greater_format; |
0 | 791 |
792 // Public Methods | |
415
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
793 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:
0
diff
changeset
|
794 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:
0
diff
changeset
|
795 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:
0
diff
changeset
|
796 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:
0
diff
changeset
|
797 const char* less_equal, const char* less_equal_format, |
4d9884b01ba6
6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents:
0
diff
changeset
|
798 const char* greater, const char* greater_format); |
0 | 799 ~CondInterface(); |
800 | |
801 void dump(); | |
802 void output(FILE *fp); | |
803 }; | |
804 | |
805 //------------------------------ConstructRule---------------------------------- | |
806 class ConstructRule : public Form { | |
807 private: | |
808 | |
809 public: | |
810 // Public Data | |
811 char *_expr; // String representing the match expression | |
812 char *_construct; // String representing C++ constructor code | |
813 | |
814 // Public Methods | |
815 ConstructRule(char *cnstr); | |
816 ~ConstructRule(); | |
817 | |
818 void dump(); | |
819 void output(FILE *fp); | |
820 }; | |
821 | |
822 | |
823 //==============================Shared========================================= | |
824 //------------------------------AttributeForm---------------------------------- | |
825 class AttributeForm : public Form { | |
826 private: | |
827 // counters for unique instruction or operand ID | |
828 static int _insId; // user-defined machine instruction types | |
829 static int _opId; // user-defined operand types | |
830 | |
831 int id; // hold type for this object | |
832 | |
833 public: | |
834 // Public Data | |
835 char *_attrname; // Name of attribute | |
836 int _atype; // Either INS_ATTR or OP_ATTR | |
837 char *_attrdef; // C++ source which evaluates to constant | |
838 | |
839 // Public Methods | |
840 AttributeForm(char *attr, int type, char *attrdef); | |
841 ~AttributeForm(); | |
842 | |
843 // Dynamic type check | |
844 virtual AttributeForm *is_attribute() const; | |
845 | |
846 int type() { return id;} // return this object's "id" | |
847 | |
848 static const char* _ins_cost; // "ins_cost" | |
849 static const char* _ins_pc_relative; // "ins_pc_relative" | |
850 static const char* _op_cost; // "op_cost" | |
851 | |
852 void dump(); // Debug printer | |
853 void output(FILE *fp); // Write output files | |
854 }; | |
855 | |
856 //------------------------------Component-------------------------------------- | |
857 class Component : public Form { | |
858 private: | |
859 | |
860 public: | |
861 // Public Data | |
862 const char *_name; // Name of this component | |
863 const char *_type; // Type of this component | |
864 int _usedef; // Value of component | |
865 | |
866 // Public Methods | |
867 Component(const char *name, const char *type, int usedef); | |
868 ~Component(); | |
869 | |
870 | |
871 // Return 'true' if this use def info equals the parameter | |
872 bool is(int use_def_kill_enum) const; | |
873 // Return 'true' if this use def info is a superset of parameter | |
874 bool isa(int use_def_kill_enum) const; | |
875 int promote_use_def_info(int new_use_def); | |
876 const char *base_type(FormDict &globals); | |
877 // Form::DataType is_base_constant(FormDict &globals); | |
878 | |
879 void dump(); // Debug printer | |
880 void output(FILE *fp); // Write to output files | |
881 | |
882 public: | |
883 // Implementation depends upon working bit intersection and union. | |
884 enum use_def_enum { | |
885 INVALID = 0x0, | |
886 USE = 0x1, | |
887 DEF = 0x2, USE_DEF = 0x3, | |
888 KILL = 0x4, USE_KILL = 0x5, | |
889 SYNTHETIC = 0x8, | |
890 TEMP = USE | SYNTHETIC | |
891 }; | |
892 }; | |
893 | |
894 | |
895 //------------------------------MatchNode-------------------------------------- | |
896 class MatchNode : public Form { | |
897 private: | |
898 | |
899 public: | |
900 // Public Data | |
901 const char *_result; // The name of the output of this node | |
902 const char *_name; // The name that appeared in the match rule | |
903 const char *_opType; // The Operation/Type matched | |
904 MatchNode *_lChild; // Left child in expression tree | |
905 MatchNode *_rChild; // Right child in expression tree | |
906 int _numleaves; // Sum of numleaves for all direct children | |
907 ArchDesc &_AD; // Reference to ArchDesc object | |
908 char *_internalop; // String representing internal operand | |
909 int _commutative_id; // id of commutative operation | |
910 | |
911 // Public Methods | |
912 MatchNode(ArchDesc &ad, const char *result = 0, const char *expr = 0, | |
913 const char *opType=0, MatchNode *lChild=NULL, | |
914 MatchNode *rChild=NULL); | |
915 MatchNode(ArchDesc &ad, MatchNode& mNode); // Shallow copy constructor; | |
916 MatchNode(ArchDesc &ad, MatchNode& mNode, int clone); // Construct clone | |
917 ~MatchNode(); | |
918 | |
919 // return 0 if not found: | |
920 // return 1 if found and position is incremented by operand offset in rule | |
921 bool find_name(const char *str, int &position) const; | |
922 bool find_type(const char *str, int &position) const; | |
923 void append_components(FormDict &locals, ComponentList &components, | |
924 bool def_flag) const; | |
925 bool base_operand(uint &position, FormDict &globals, | |
926 const char * &result, const char * &name, | |
927 const char * &opType) const; | |
928 // recursive count on operands | |
929 uint num_consts(FormDict &globals) const; | |
930 uint num_const_ptrs(FormDict &globals) const; | |
931 // recursive count of constants with specified type | |
932 uint num_consts(FormDict &globals, Form::DataType type) const; | |
933 // uint num_consts() const; // Local inspection only | |
934 int needs_ideal_memory_edge(FormDict &globals) const; | |
935 int needs_base_oop_edge() const; | |
936 | |
937 // Help build instruction predicates. Search for operand names. | |
938 void count_instr_names( Dict &names ); | |
939 int build_instr_pred( char *buf, const char *name, int cnt ); | |
940 void build_internalop( ); | |
941 | |
942 // Return the name of the operands associated with reducing to this operand: | |
943 // The result type, plus the left and right sides of the binary match | |
944 // Return NULL if there is no left or right hand side | |
945 bool sets_result() const; // rule "Set"s result of match | |
946 const char *reduce_right(FormDict &globals) const; | |
947 const char *reduce_left (FormDict &globals) const; | |
948 | |
949 // Recursive version of check in MatchRule | |
950 int cisc_spill_match(FormDict &globals, RegisterForm *registers, | |
951 MatchNode *mRule2, const char * &operand, | |
952 const char * ®_type); | |
953 int cisc_spill_merge(int left_result, int right_result); | |
954 | |
955 bool equivalent(FormDict &globals, MatchNode *mNode2); | |
956 | |
957 void count_commutative_op(int& count); | |
958 void swap_commutative_op(bool atroot, int count); | |
959 | |
960 void dump(); | |
961 void output(FILE *fp); | |
962 }; | |
963 | |
964 //------------------------------MatchRule-------------------------------------- | |
965 class MatchRule : public MatchNode { | |
966 private: | |
967 | |
968 public: | |
969 // Public Data | |
970 const char *_machType; // Machine type index | |
971 int _depth; // Expression tree depth | |
972 char *_construct; // String representing C++ constructor code | |
973 int _numchilds; // Number of direct children | |
974 MatchRule *_next; // Pointer to next match rule | |
975 | |
976 // Public Methods | |
977 MatchRule(ArchDesc &ad); | |
978 MatchRule(ArchDesc &ad, MatchRule* mRule); // Shallow copy constructor; | |
979 MatchRule(ArchDesc &ad, MatchNode* mroot, int depth, char* construct, int numleaves); | |
980 ~MatchRule(); | |
981 | |
982 void append_components(FormDict &locals, ComponentList &components) const; | |
983 // Recursive call on all operands' match rules in my match rule. | |
984 bool base_operand(uint &position, FormDict &globals, | |
985 const char * &result, const char * &name, | |
986 const char * &opType) const; | |
987 | |
988 | |
989 bool is_base_register(FormDict &globals) const; | |
990 Form::DataType is_base_constant(FormDict &globals) const; | |
991 bool is_chain_rule(FormDict &globals) const; | |
992 int is_ideal_copy() const; | |
993 int is_expensive() const; // node matches ideal 'CosD' | |
994 bool is_ideal_unlock() const; | |
995 bool is_ideal_call_leaf() const; | |
996 bool is_ideal_if() const; // node matches ideal 'If' | |
997 bool is_ideal_fastlock() const; // node matches ideal 'FastLock' | |
998 bool is_ideal_jump() const; // node matches ideal 'Jump' | |
999 bool is_ideal_membar() const; // node matches ideal 'MemBarXXX' | |
1000 bool is_ideal_loadPC() const; // node matches ideal 'LoadPC' | |
1001 bool is_ideal_box() const; // node matches ideal 'Box' | |
1002 bool is_ideal_goto() const; // node matches ideal 'Goto' | |
1003 bool is_ideal_loopEnd() const; // node matches ideal 'LoopEnd' | |
1004 bool is_ideal_bool() const; // node matches ideal 'Bool' | |
1005 Form::DataType is_ideal_load() const;// node matches ideal 'LoadXNode' | |
1006 Form::DataType is_ideal_store() const;// node matches ideal 'StoreXNode' | |
1007 | |
1008 // Check if 'mRule2' is a cisc-spill variant of this MatchRule | |
1009 int cisc_spill_match(FormDict &globals, RegisterForm *registers, | |
1010 MatchRule *mRule2, const char * &operand, | |
1011 const char * ®_type); | |
1012 | |
1013 // Check if 'mRule2' is equivalent to this MatchRule | |
1014 bool equivalent(FormDict &globals, MatchRule *mRule2); | |
1015 | |
1016 void swap_commutative_op(const char* instr_ident, int count, int& match_rules_cnt); | |
1017 | |
1018 void dump(); | |
1019 void output(FILE *fp); | |
1020 }; | |
1021 | |
1022 //------------------------------Attribute-------------------------------------- | |
1023 class Attribute : public Form { | |
1024 private: | |
1025 | |
1026 public: | |
1027 // Public Data | |
1028 char *_ident; // Name of predefined attribute | |
1029 char *_val; // C++ source which evaluates to constant | |
1030 int _atype; // Either INS_ATTR or OP_ATTR | |
1031 int int_val(ArchDesc &ad); // Return atoi(_val), ensuring syntax. | |
1032 | |
1033 // Public Methods | |
1034 Attribute(char *id, char* val, int type); | |
1035 ~Attribute(); | |
1036 | |
1037 void dump(); | |
1038 void output(FILE *fp); | |
1039 }; | |
1040 | |
1041 //------------------------------FormatRule------------------------------------- | |
1042 class FormatRule : public Form { | |
1043 private: | |
1044 | |
1045 public: | |
1046 // Public Data | |
1047 // There is an entry in _strings, perhaps NULL, that precedes each _rep_vars | |
1048 NameList _strings; // Strings passed through to tty->print | |
1049 NameList _rep_vars; // replacement variables | |
1050 char *_temp; // String representing the assembly code | |
1051 | |
1052 // Public Methods | |
1053 FormatRule(char *temp); | |
1054 ~FormatRule(); | |
1055 | |
1056 void dump(); | |
1057 void output(FILE *fp); | |
1058 }; |