src/share/vm/adlc/formssel.hpp

Tue, 09 Oct 2012 16:09:31 -0700

author
kvn
date
Tue, 09 Oct 2012 16:09:31 -0700
changeset 4161
d336b3173277
parent 3882
8c92982cbbc4
child 5221
f15fe46d8c00
permissions
-rw-r--r--

8000592: Improve adlc usability
Summary: several changes to adlc to improve its usability
Reviewed-by: kvn
Contributed-by: goetz.lindenmaier@sap.com

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

mercurial