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