src/share/vm/adlc/formssel.hpp

Wed, 04 Feb 2009 11:44:57 -0800

author
never
date
Wed, 04 Feb 2009 11:44:57 -0800
changeset 997
1580954e694c
parent 905
ad8c8ca4ab0f
child 1034
0ad1cb407fa1
permissions
-rw-r--r--

6798785: Crash in OopFlow::build_oop_map: incorrect comparison of 64bit pointers
Reviewed-by: phh, kvn

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

mercurial