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