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