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