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