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