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