Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/formssel.hpp
32285 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_ADLC_FORMSSEL_HPP25#define SHARE_VM_ADLC_FORMSSEL_HPP2627// FORMSSEL.HPP - ADL Parser Instruction Selection Forms Classes2829// Class List30class Form;31class InstructForm;32class MachNodeForm;33class OperandForm;34class OpClassForm;35class AttributeForm;36class RegisterForm;37class PipelineForm;38class SourceForm;39class EncodeForm;40class Component;41class Constraint;42class Predicate;43class MatchRule;44class Attribute;45class Effect;46class ExpandRule;47class RewriteRule;48class ConstructRule;49class FormatRule;50class Peephole;51class EncClass;52class Interface;53class RegInterface;54class ConstInterface;55class MemInterface;56class CondInterface;57class Opcode;58class InsEncode;59class RegDef;60class RegClass;61class CodeSnippetRegClass;62class ConditionalRegClass;63class AllocClass;64class ResourceForm;65class PipeDesc;66class PipeClass;67class PeepMatch;68class PeepConstraint;69class PeepReplace;70class MatchList;7172class ArchDesc;7374//==============================Instructions===================================75//------------------------------InstructForm-----------------------------------76class InstructForm : public Form {77private:78bool _ideal_only; // Not a user-defined instruction79// Members used for tracking CISC-spilling80int _cisc_spill_operand;// Which operand may cisc-spill81void set_cisc_spill_operand(uint op_index) { _cisc_spill_operand = op_index; }82bool _is_cisc_alternate;83InstructForm *_cisc_spill_alternate;// cisc possible replacement84const char *_cisc_reg_mask_name;85InstructForm *_short_branch_form;86bool _is_short_branch;87bool _is_mach_constant; // True if Node is a MachConstantNode.88bool _needs_constant_base; // True if Node needs the mach_constant_base input.89uint _alignment;9091public:92// Public Data93const char *_ident; // Name of this instruction94NameList _parameters; // Locally defined names95FormDict _localNames; // Table of operands & their types96MatchRule *_matrule; // Matching rule for this instruction97Opcode *_opcode; // Encoding of the opcode for instruction98char *_size; // Size of instruction99InsEncode *_insencode; // Encoding class instruction belongs to100InsEncode *_constant; // Encoding class constant value belongs to101bool _is_postalloc_expand; // Indicates that encoding just does a lateExpand.102Attribute *_attribs; // List of Attribute rules103Predicate *_predicate; // Predicate test for this instruction104FormDict _effects; // Dictionary of effect rules105ExpandRule *_exprule; // Expand rule for this instruction106RewriteRule *_rewrule; // Rewrite rule for this instruction107FormatRule *_format; // Format for assembly generation108Peephole *_peephole; // List of peephole rules for instruction109const char *_ins_pipe; // Instruction Scheduling description class110111uint *_uniq_idx; // Indexes of unique operands112uint _uniq_idx_length; // Length of _uniq_idx array113uint _num_uniq; // Number of unique operands114ComponentList _components; // List of Components matches MachNode's115// operand structure116117bool _has_call; // contain a call and caller save registers should be saved?118119// Public Methods120InstructForm(const char *id, bool ideal_only = false);121InstructForm(const char *id, InstructForm *instr, MatchRule *rule);122~InstructForm();123124// Dynamic type check125virtual InstructForm *is_instruction() const;126127virtual bool ideal_only() const;128129// This instruction sets a result130virtual bool sets_result() const;131// This instruction needs projections for additional DEFs or KILLs132virtual bool needs_projections();133// This instruction needs extra nodes for temporary inputs134virtual bool has_temps();135// This instruction defines or kills more than one object136virtual uint num_defs_or_kills();137// This instruction has an expand rule?138virtual bool expands() const ;139// This instruction has a late expand rule?140virtual bool postalloc_expands() const;141// Return this instruction's first peephole rule, or NULL142virtual Peephole *peepholes() const;143// Add a peephole rule to this instruction144virtual void append_peephole(Peephole *peep);145146virtual bool is_pinned(FormDict &globals); // should be pinned inside block147virtual bool is_projection(FormDict &globals); // node requires projection148virtual bool is_parm(FormDict &globals); // node matches ideal 'Parm'149// ideal opcode enumeration150virtual const char *ideal_Opcode(FormDict &globals) const;151virtual int is_expensive() const; // node matches ideal 'CosD'152virtual int is_empty_encoding() const; // _size=0 and/or _insencode empty153virtual int is_tls_instruction() const; // tlsLoadP rule or ideal ThreadLocal154virtual int is_ideal_copy() const; // node matches ideal 'Copy*'155virtual bool is_ideal_negD() const; // node matches ideal 'NegD'156virtual bool is_ideal_if() const; // node matches ideal 'If'157virtual bool is_ideal_fastlock() const; // node matches 'FastLock'158virtual bool is_ideal_membar() const; // node matches ideal 'MemBarXXX'159virtual bool is_ideal_loadPC() const; // node matches ideal 'LoadPC'160virtual bool is_ideal_box() const; // node matches ideal 'Box'161virtual bool is_ideal_goto() const; // node matches ideal 'Goto'162virtual bool is_ideal_branch() const; // "" 'If' | 'Goto' | 'LoopEnd' | 'Jump'163virtual bool is_ideal_jump() const; // node matches ideal 'Jump'164virtual bool is_ideal_return() const; // node matches ideal 'Return'165virtual bool is_ideal_halt() const; // node matches ideal 'Halt'166virtual bool is_ideal_safepoint() const; // node matches 'SafePoint'167virtual bool is_ideal_nop() const; // node matches 'Nop'168virtual bool is_ideal_control() const; // control node169virtual bool is_vector() const; // vector instruction170171virtual Form::CallType is_ideal_call() const; // matches ideal 'Call'172virtual Form::DataType is_ideal_load() const; // node matches ideal 'LoadXNode'173// Should antidep checks be disabled for this Instruct174// See definition of MatchRule::skip_antidep_check175bool skip_antidep_check() const;176virtual Form::DataType is_ideal_store() const;// node matches ideal 'StoreXNode'177bool is_ideal_mem() const { return is_ideal_load() != Form::none || is_ideal_store() != Form::none; }178virtual uint two_address(FormDict &globals); // output reg must match input reg179// when chaining a constant to an instruction, return 'true' and set opType180virtual Form::DataType is_chain_of_constant(FormDict &globals);181virtual Form::DataType is_chain_of_constant(FormDict &globals, const char * &opType);182virtual Form::DataType is_chain_of_constant(FormDict &globals, const char * &opType, const char * &result_type);183184// Check if a simple chain rule185virtual bool is_simple_chain_rule(FormDict &globals) const;186187// check for structural rematerialization188virtual bool rematerialize(FormDict &globals, RegisterForm *registers);189190// loads from memory, so must check for anti-dependence191virtual bool needs_anti_dependence_check(FormDict &globals) const;192virtual int memory_operand(FormDict &globals) const;193194enum memory_operand_type {195NO_MEMORY_OPERAND = -1,196MANY_MEMORY_OPERANDS = 999999197};198199200// This instruction captures the machine-independent bottom_type201// Expected use is for pointer vs oop determination for LoadP202virtual bool captures_bottom_type(FormDict& globals) const;203204virtual const char *cost(); // Access ins_cost attribute205virtual uint num_opnds(); // Count of num_opnds for MachNode class206// Counts USE_DEF opnds twice. See also num_unique_opnds().207virtual uint num_post_match_opnds();208virtual uint num_consts(FormDict &globals) const;// Constants in match rule209// Constants in match rule with specified type210virtual uint num_consts(FormDict &globals, Form::DataType type) const;211212// Return the register class associated with 'leaf'.213virtual const char *out_reg_class(FormDict &globals);214215// number of ideal node inputs to skip216virtual uint oper_input_base(FormDict &globals);217218// Does this instruction need a base-oop edge?219int needs_base_oop_edge(FormDict &globals) const;220221// Build instruction predicates. If the user uses the same operand name222// twice, we need to check that the operands are pointer-eequivalent in223// the DFA during the labeling process.224Predicate *build_predicate();225226virtual void build_components(); // top-level operands227// Return zero-based position in component list; -1 if not in list.228virtual int operand_position(const char *name, int usedef);229virtual int operand_position_format(const char *name);230231// Return zero-based position in component list; -1 if not in list.232virtual int label_position();233virtual int method_position();234// Return number of relocation entries needed for this instruction.235virtual uint reloc(FormDict &globals);236237const char *opnd_ident(int idx); // Name of operand #idx.238const char *reduce_result();239// Return the name of the operand on the right hand side of the binary match240// Return NULL if there is no right hand side241const char *reduce_right(FormDict &globals) const;242const char *reduce_left(FormDict &globals) const;243244// Base class for this instruction, MachNode except for calls245virtual const char *mach_base_class(FormDict &globals) const;246247// Check if this instruction can cisc-spill to 'alternate'248bool cisc_spills_to(ArchDesc &AD, InstructForm *alternate);249InstructForm *cisc_spill_alternate() { return _cisc_spill_alternate; }250int cisc_spill_operand() const { return _cisc_spill_operand; }251bool is_cisc_alternate() const { return _is_cisc_alternate; }252void set_cisc_alternate(bool val) { _is_cisc_alternate = val; }253const char *cisc_reg_mask_name() const { return _cisc_reg_mask_name; }254void set_cisc_reg_mask_name(const char *rm_name) { _cisc_reg_mask_name = rm_name; }255// Output cisc-method prototypes and method bodies256void declare_cisc_version(ArchDesc &AD, FILE *fp_cpp);257bool define_cisc_version (ArchDesc &AD, FILE *fp_cpp);258259bool check_branch_variant(ArchDesc &AD, InstructForm *short_branch);260261bool is_short_branch() { return _is_short_branch; }262void set_short_branch(bool val) { _is_short_branch = val; }263264bool is_mach_constant() const { return _is_mach_constant; }265void set_is_mach_constant(bool x) { _is_mach_constant = x; }266bool needs_constant_base() const { return _needs_constant_base; }267void set_needs_constant_base(bool x) { _needs_constant_base = x; }268269InstructForm *short_branch_form() { return _short_branch_form; }270bool has_short_branch_form() { return _short_branch_form != NULL; }271// Output short branch prototypes and method bodies272void declare_short_branch_methods(FILE *fp_cpp);273bool define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp);274275uint alignment() { return _alignment; }276void set_alignment(uint val) { _alignment = val; }277278// Seach through operands to determine operands unique positions.279void set_unique_opnds();280uint num_unique_opnds() { return _num_uniq; }281uint unique_opnds_idx(int idx) {282if (_uniq_idx != NULL && idx > 0) {283assert((uint)idx < _uniq_idx_length, "out of bounds");284return _uniq_idx[idx];285} else {286return idx;287}288}289const char *unique_opnd_ident(uint idx); // Name of operand at unique idx.290291// Operands which are only KILLs aren't part of the input array and292// require special handling in some cases. Their position in this293// operand list is higher than the number of unique operands.294bool is_noninput_operand(uint idx) {295return (idx >= num_unique_opnds());296}297298// --------------------------- FILE *output_routines299//300// Generate the format call for the replacement variable301void rep_var_format(FILE *fp, const char *rep_var);302// Generate index values needed for determining the operand position303void index_temps (FILE *fp, FormDict &globals, const char *prefix = "", const char *receiver = "");304// ---------------------------305306virtual bool verify(); // Check consistency after parsing307308virtual void dump(); // Debug printer309virtual void output(FILE *fp); // Write to output files310};311312//------------------------------EncodeForm-------------------------------------313class EncodeForm : public Form {314private:315316public:317// Public Data318NameList _eclasses; // List of encode class names319Dict _encClass; // Map encode class names to EncClass objects320321// Public Methods322EncodeForm();323~EncodeForm();324325EncClass *add_EncClass(const char *className);326EncClass *encClass(const char *className);327328const char *encClassPrototype(const char *className);329const char *encClassBody(const char *className);330331void dump(); // Debug printer332void output(FILE *fp); // Write info to output files333};334335//------------------------------EncClass---------------------------------------336class EncClass : public Form {337public:338// NameList for parameter type and name339NameList _parameter_type;340NameList _parameter_name;341342// Breakdown the encoding into strings separated by $replacement_variables343// There is an entry in _strings, perhaps NULL, that precedes each _rep_vars344NameList _code; // Strings passed through to tty->print345NameList _rep_vars; // replacement variables346347NameList _parameters; // Locally defined names348FormDict _localNames; // Table of components & their types349350public:351// Public Data352const char *_name; // encoding class name353354// Public Methods355EncClass(const char *name);356~EncClass();357358// --------------------------- Parameters359// Add a parameter <type,name> pair360void add_parameter(const char *parameter_type, const char *parameter_name);361// Verify operand types in parameter list362bool check_parameter_types(FormDict &globals);363// Obtain the zero-based index corresponding to a replacement variable364int rep_var_index(const char *rep_var);365int num_args() { return _parameter_name.count(); }366367// --------------------------- Code Block368// Add code369void add_code(const char *string_preceding_replacement_var);370// Add a replacement variable or one of its subfields371// Subfields are stored with a leading '$'372void add_rep_var(char *replacement_var);373374bool verify();375void dump();376void output(FILE *fp);377};378379//------------------------------MachNode---------------------------------------380class MachNodeForm: public Form {381private:382383public:384char *_ident; // Name of this instruction385const char *_machnode_pipe; // Instruction Scheduline description class386387// Public Methods388MachNodeForm(char *id);389~MachNodeForm();390391virtual MachNodeForm *is_machnode() const;392393void dump(); // Debug printer394void output(FILE *fp); // Write info to output files395};396397//------------------------------Opcode-----------------------------------------398class Opcode : public Form {399private:400401public:402// Public Data403// Strings representing instruction opcodes, user defines placement in emit404char *_primary;405char *_secondary;406char *_tertiary;407408enum opcode_type {409NOT_AN_OPCODE = -1,410PRIMARY = 1,411SECONDARY = 2,412TERTIARY = 3413};414415// Public Methods416Opcode(char *primary, char *secondary, char *tertiary);417~Opcode();418419static Opcode::opcode_type as_opcode_type(const char *designator);420421void dump();422void output(FILE *fp);423424// --------------------------- FILE *output_routines425bool print_opcode(FILE *fp, Opcode::opcode_type desired_opcode);426};427428//------------------------------InsEncode--------------------------------------429class InsEncode : public Form {430private: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, ...434NameList _encoding;435// NameList _parameter;436// The parameters for each encoding are preceeded by a NameList::_signal437// and follow the parameters for the previous encoding.438439// char *_encode; // Type of instruction encoding440441public:442// Public Methods443InsEncode();444~InsEncode();445446// Add "encode class name" and its parameters447NameAndList *add_encode(char *encode_method_name);448// Parameters are added to the returned "NameAndList" by the parser449450// Access the list of encodings451void reset();452const char *encode_class_iter();453454// Returns the number of arguments to the current encoding in the iteration455int current_encoding_num_args() {456return ((NameAndList*)_encoding.current())->count();457}458459// --------------------------- Parameters460// The following call depends upon position within encode_class_iteration461//462// Obtain parameter name from zero based index463const char *rep_var_name(InstructForm &inst, uint param_no);464// ---------------------------465466void dump();467void output(FILE *fp);468};469470//------------------------------Effect-----------------------------------------471class Effect : public Form {472private:473474public:475// Public Data476const char *_name; // Pre-defined name for effect477int _use_def; // Enumeration value of effect478479// Public Methods480Effect(const char *name); // Constructor481~Effect(); // Destructor482483// Dynamic type check484virtual Effect *is_effect() const;485486// Return 'true' if this use def info equals the parameter487bool is(int use_def_kill_enum) const;488// Return 'true' if this use def info is a superset of parameter489bool isa(int use_def_kill_enum) const;490491void dump(); // Debug printer492void output(FILE *fp); // Write info to output files493};494495//------------------------------ExpandRule-------------------------------------496class ExpandRule : public Form {497private:498NameList _expand_instrs; // ordered list of instructions and operands499500public:501// Public Data502NameList _newopers; // List of newly created operands503Dict _newopconst; // Map new operands to their constructors504505void add_instruction(NameAndList *instruction_name_and_operand_list);506void reset_instructions();507NameAndList *iter_instructions();508509// Public Methods510ExpandRule(); // Constructor511~ExpandRule(); // Destructor512513void dump(); // Debug printer514void output(FILE *fp); // Write info to output files515};516517//------------------------------RewriteRule------------------------------------518class RewriteRule : public Form {519private:520521public:522// Public Data523SourceForm *_condition; // Rewrite condition code524InstructForm *_instrs; // List of instructions to expand to525OperandForm *_opers; // List of operands generated by expand526char *_tempParams; // Hold string until parser is finished.527char *_tempBlock; // Hold string until parser is finished.528529// Public Methods530RewriteRule(char* params, char* block) ;531~RewriteRule(); // Destructor532void dump(); // Debug printer533void output(FILE *fp); // Write info to output files534};535536537//==============================Operands=======================================538//------------------------------OpClassForm------------------------------------539class OpClassForm : public Form {540public:541// Public Data542const char *_ident; // Name of this operand543NameList _oplst; // List of operand forms included in class544545// Public Methods546OpClassForm(const char *id);547~OpClassForm();548549// dynamic type check550virtual OpClassForm *is_opclass() const;551virtual Form::InterfaceType interface_type(FormDict &globals) const;552virtual bool stack_slots_only(FormDict &globals) const;553554virtual bool is_cisc_mem(FormDict &globals) const;555556557// Min and Max opcodes of operands in this operand class558int _minCode;559int _maxCode;560561virtual bool ideal_only() const;562virtual void dump(); // Debug printer563virtual void output(FILE *fp); // Write to output files564};565566//------------------------------OperandForm------------------------------------567class OperandForm : public OpClassForm {568private:569bool _ideal_only; // Not a user-defined instruction570571public:572// Public Data573NameList _parameters; // Locally defined names574FormDict _localNames; // Table of components & their types575MatchRule *_matrule; // Matching rule for this operand576Interface *_interface; // Encoding interface for this operand577Attribute *_attribs; // List of Attribute rules578Predicate *_predicate; // Predicate test for this operand579Constraint *_constraint; // Constraint Rule for this operand580ConstructRule *_construct; // Construction of operand data after matching581FormatRule *_format; // Format for assembly generation582NameList _classes; // List of opclasses which contain this oper583584ComponentList _components; //585586// Public Methods587OperandForm(const char *id);588OperandForm(const char *id, bool ideal_only);589~OperandForm();590591// Dynamic type check592virtual OperandForm *is_operand() const;593594virtual bool ideal_only() const;595virtual Form::InterfaceType interface_type(FormDict &globals) const;596virtual bool stack_slots_only(FormDict &globals) const;597598virtual const char *cost(); // Access ins_cost attribute599virtual uint num_leaves() const;// Leaves in complex operand600// Constants in operands' match rules601virtual uint num_consts(FormDict &globals) const;602// Constants in operand's match rule with specified type603virtual uint num_consts(FormDict &globals, Form::DataType type) const;604// Pointer Constants in operands' match rules605virtual uint num_const_ptrs(FormDict &globals) const;606// The number of input edges in the machine world == num_leaves - num_consts607virtual uint num_edges(FormDict &globals) const;608609// Check if this operand is usable for cisc-spilling610virtual bool is_cisc_reg(FormDict &globals) const;611612// node matches ideal 'Bool', grab condition codes from the ideal world613virtual bool is_ideal_bool() const;614615// Has an integer constant suitable for spill offsets616bool has_conI(FormDict &globals) const {617return (num_consts(globals,idealI) == 1) && !is_ideal_bool(); }618bool has_conL(FormDict &globals) const {619return (num_consts(globals,idealL) == 1) && !is_ideal_bool(); }620621// Node is user-defined operand for an sRegX622virtual Form::DataType is_user_name_for_sReg() const;623624// Return ideal type, if there is a single ideal type for this operand625virtual const char *ideal_type(FormDict &globals, RegisterForm *registers = NULL) const;626// If there is a single ideal type for this interface field, return it.627virtual const char *interface_ideal_type(FormDict &globals,628const char *field_name) const;629630// Return true if this operand represents a bound register class631bool is_bound_register() const;632633// Return the Register class for this operand. Returns NULL if634// operand isn't a register form.635RegClass* get_RegClass() const;636637virtual bool is_interface_field(const char *field_name,638const char * &value) const;639640// If this operand has a single ideal type, return its type641virtual Form::DataType simple_type(FormDict &globals) const;642// If this operand is an ideal constant, return its type643virtual Form::DataType is_base_constant(FormDict &globals) const;644645// "true" if this operand is a simple type that is swallowed646virtual bool swallowed(FormDict &globals) const;647648// Return register class name if a constraint specifies the register class.649virtual const char *constrained_reg_class() const;650// Return the register class associated with 'leaf'.651virtual const char *in_reg_class(uint leaf, FormDict &globals);652653// Build component list from MatchRule and operand's parameter list654virtual void build_components(); // top-level operands655656// Return zero-based position in component list; -1 if not in list.657virtual int operand_position(const char *name, int usedef);658659// Return zero-based position in component list; -1 if not in list.660virtual int constant_position(FormDict &globals, const Component *comp);661virtual int constant_position(FormDict &globals, const char *local_name);662// Return the operand form corresponding to the given index, else NULL.663virtual OperandForm *constant_operand(FormDict &globals, uint const_index);664665// Return zero-based position in component list; -1 if not in list.666virtual int register_position(FormDict &globals, const char *regname);667668const char *reduce_result() const;669// Return the name of the operand on the right hand side of the binary match670// Return NULL if there is no right hand side671const char *reduce_right(FormDict &globals) const;672const char *reduce_left(FormDict &globals) const;673674675// --------------------------- FILE *output_routines676//677// Output code for disp_is_oop, if true.678void disp_is_oop(FILE *fp, FormDict &globals);679// Generate code for internal and external format methods680void int_format(FILE *fp, FormDict &globals, uint index);681void ext_format(FILE *fp, FormDict &globals, uint index);682void format_constant(FILE *fp, uint con_index, uint con_type);683// Output code to access the value of the index'th constant684void access_constant(FILE *fp, FormDict &globals,685uint con_index);686// ---------------------------687688689virtual void dump(); // Debug printer690virtual void output(FILE *fp); // Write to output files691};692693//------------------------------Constraint-------------------------------------694class Constraint : public Form {695private:696697public:698const char *_func; // Constraint function699const char *_arg; // function's argument700701// Public Methods702Constraint(const char *func, const char *arg); // Constructor703~Constraint();704705bool stack_slots_only() const;706707void dump(); // Debug printer708void output(FILE *fp); // Write info to output files709};710711//------------------------------Predicate--------------------------------------712class Predicate : public Form {713private:714715public:716// Public Data717char *_pred; // C++ source string for predicate718719// Public Methods720Predicate(char *pr);721~Predicate();722723void dump();724void output(FILE *fp);725};726727//------------------------------Interface--------------------------------------728class Interface : public Form {729private:730731public:732// Public Data733const char *_name; // String representing the interface name734735// Public Methods736Interface(const char *name);737~Interface();738739virtual Form::InterfaceType interface_type(FormDict &globals) const;740741RegInterface *is_RegInterface();742MemInterface *is_MemInterface();743ConstInterface *is_ConstInterface();744CondInterface *is_CondInterface();745746747void dump();748void output(FILE *fp);749};750751//------------------------------RegInterface-----------------------------------752class RegInterface : public Interface {753private:754755public:756// Public Methods757RegInterface();758~RegInterface();759760void dump();761void output(FILE *fp);762};763764//------------------------------ConstInterface---------------------------------765class ConstInterface : public Interface {766private:767768public:769// Public Methods770ConstInterface();771~ConstInterface();772773void dump();774void output(FILE *fp);775};776777//------------------------------MemInterface-----------------------------------778class MemInterface : public Interface {779private:780781public:782// Public Data783char *_base; // Base address784char *_index; // index785char *_scale; // scaling factor786char *_disp; // displacement787788// Public Methods789MemInterface(char *base, char *index, char *scale, char *disp);790~MemInterface();791792void dump();793void output(FILE *fp);794};795796//------------------------------CondInterface----------------------------------797class CondInterface : public Interface {798private:799800public:801const char *_equal;802const char *_not_equal;803const char *_less;804const char *_greater_equal;805const char *_less_equal;806const char *_greater;807const char *_overflow;808const char *_no_overflow;809const char *_equal_format;810const char *_not_equal_format;811const char *_less_format;812const char *_greater_equal_format;813const char *_less_equal_format;814const char *_greater_format;815const char *_overflow_format;816const char *_no_overflow_format;817818// Public Methods819CondInterface(const char* equal, const char* equal_format,820const char* not_equal, const char* not_equal_format,821const char* less, const char* less_format,822const char* greater_equal, const char* greater_equal_format,823const char* less_equal, const char* less_equal_format,824const char* greater, const char* greater_format,825const char* overflow, const char* overflow_format,826const char* no_overflow, const char* no_overflow_format);827~CondInterface();828829void dump();830void output(FILE *fp);831};832833//------------------------------ConstructRule----------------------------------834class ConstructRule : public Form {835private:836837public:838// Public Data839char *_expr; // String representing the match expression840char *_construct; // String representing C++ constructor code841842// Public Methods843ConstructRule(char *cnstr);844~ConstructRule();845846void dump();847void output(FILE *fp);848};849850851//==============================Shared=========================================852//------------------------------AttributeForm----------------------------------853class AttributeForm : public Form {854private:855// counters for unique instruction or operand ID856static int _insId; // user-defined machine instruction types857static int _opId; // user-defined operand types858859int id; // hold type for this object860861public:862// Public Data863char *_attrname; // Name of attribute864int _atype; // Either INS_ATTR or OP_ATTR865char *_attrdef; // C++ source which evaluates to constant866867// Public Methods868AttributeForm(char *attr, int type, char *attrdef);869~AttributeForm();870871// Dynamic type check872virtual AttributeForm *is_attribute() const;873874int type() { return id;} // return this object's "id"875876static const char* _ins_cost; // "ins_cost"877static const char* _op_cost; // "op_cost"878879void dump(); // Debug printer880void output(FILE *fp); // Write output files881};882883//------------------------------Component--------------------------------------884class Component : public Form {885private:886887public:888// Public Data889const char *_name; // Name of this component890const char *_type; // Type of this component891int _usedef; // Value of component892893// Public Methods894Component(const char *name, const char *type, int usedef);895~Component();896897898// Return 'true' if this use def info equals the parameter899bool is(int use_def_kill_enum) const;900// Return 'true' if this use def info is a superset of parameter901bool isa(int use_def_kill_enum) const;902int promote_use_def_info(int new_use_def);903const char *base_type(FormDict &globals);904// Form::DataType is_base_constant(FormDict &globals);905906void dump(); // Debug printer907void output(FILE *fp); // Write to output files908const char* getUsedefName();909910public:911// Implementation depends upon working bit intersection and union.912enum use_def_enum {913INVALID = 0x0,914USE = 0x1,915DEF = 0x2, USE_DEF = 0x3,916KILL = 0x4, USE_KILL = 0x5,917SYNTHETIC = 0x8,918TEMP = USE | SYNTHETIC,919CALL = 0x10920};921};922923924//------------------------------MatchNode--------------------------------------925class MatchNode : public Form {926private:927928public:929// Public Data930const char *_result; // The name of the output of this node931const char *_name; // The name that appeared in the match rule932const char *_opType; // The Operation/Type matched933MatchNode *_lChild; // Left child in expression tree934MatchNode *_rChild; // Right child in expression tree935int _numleaves; // Sum of numleaves for all direct children936ArchDesc &_AD; // Reference to ArchDesc object937char *_internalop; // String representing internal operand938int _commutative_id; // id of commutative operation939940// Public Methods941MatchNode(ArchDesc &ad, const char *result = 0, const char *expr = 0,942const char *opType=0, MatchNode *lChild=NULL,943MatchNode *rChild=NULL);944MatchNode(ArchDesc &ad, MatchNode& mNode); // Shallow copy constructor;945MatchNode(ArchDesc &ad, MatchNode& mNode, int clone); // Construct clone946~MatchNode();947948// return 0 if not found:949// return 1 if found and position is incremented by operand offset in rule950bool find_name(const char *str, int &position) const;951bool find_type(const char *str, int &position) const;952virtual void append_components(FormDict& locals, ComponentList& components,953bool def_flag = false) const;954bool base_operand(uint &position, FormDict &globals,955const char * &result, const char * &name,956const char * &opType) const;957// recursive count on operands958uint num_consts(FormDict &globals) const;959uint num_const_ptrs(FormDict &globals) const;960// recursive count of constants with specified type961uint num_consts(FormDict &globals, Form::DataType type) const;962// uint num_consts() const; // Local inspection only963int needs_ideal_memory_edge(FormDict &globals) const;964int needs_base_oop_edge() const;965966// Help build instruction predicates. Search for operand names.967void count_instr_names( Dict &names );968int build_instr_pred( char *buf, const char *name, int cnt );969void build_internalop( );970971// Return the name of the operands associated with reducing to this operand:972// The result type, plus the left and right sides of the binary match973// Return NULL if there is no left or right hand side974bool sets_result() const; // rule "Set"s result of match975const char *reduce_right(FormDict &globals) const;976const char *reduce_left (FormDict &globals) const;977978// Recursive version of check in MatchRule979int cisc_spill_match(FormDict& globals, RegisterForm* registers,980MatchNode* mRule2, const char* &operand,981const char* ®_type);982int cisc_spill_merge(int left_result, int right_result);983984virtual bool equivalent(FormDict& globals, MatchNode* mNode2);985986void count_commutative_op(int& count);987void swap_commutative_op(bool atroot, int count);988989void dump();990void output(FILE *fp);991};992993//------------------------------MatchRule--------------------------------------994class MatchRule : public MatchNode {995private:996997public:998// Public Data999const char *_machType; // Machine type index1000int _depth; // Expression tree depth1001char *_construct; // String representing C++ constructor code1002int _numchilds; // Number of direct children1003MatchRule *_next; // Pointer to next match rule10041005// Public Methods1006MatchRule(ArchDesc &ad);1007MatchRule(ArchDesc &ad, MatchRule* mRule); // Shallow copy constructor;1008MatchRule(ArchDesc &ad, MatchNode* mroot, int depth, char* construct, int numleaves);1009~MatchRule();10101011virtual void append_components(FormDict& locals, ComponentList& components, bool def_flag = false) const;1012// Recursive call on all operands' match rules in my match rule.1013bool base_operand(uint &position, FormDict &globals,1014const char * &result, const char * &name,1015const char * &opType) const;101610171018bool is_base_register(FormDict &globals) const;1019Form::DataType is_base_constant(FormDict &globals) const;1020bool is_chain_rule(FormDict &globals) const;1021int is_ideal_copy() const;1022int is_expensive() const; // node matches ideal 'CosD'1023bool is_ideal_if() const; // node matches ideal 'If'1024bool is_ideal_fastlock() const; // node matches ideal 'FastLock'1025bool is_ideal_jump() const; // node matches ideal 'Jump'1026bool is_ideal_membar() const; // node matches ideal 'MemBarXXX'1027bool is_ideal_loadPC() const; // node matches ideal 'LoadPC'1028bool is_ideal_box() const; // node matches ideal 'Box'1029bool is_ideal_goto() const; // node matches ideal 'Goto'1030bool is_ideal_loopEnd() const; // node matches ideal 'LoopEnd'1031bool is_ideal_bool() const; // node matches ideal 'Bool'1032bool is_vector() const; // vector instruction1033Form::DataType is_ideal_load() const;// node matches ideal 'LoadXNode'1034// Should antidep checks be disabled for this rule1035// See definition of MatchRule::skip_antidep_check1036bool skip_antidep_check() const;1037Form::DataType is_ideal_store() const;// node matches ideal 'StoreXNode'10381039// Check if 'mRule2' is a cisc-spill variant of this MatchRule1040int matchrule_cisc_spill_match(FormDict &globals, RegisterForm* registers,1041MatchRule* mRule2, const char* &operand,1042const char* ®_type);10431044// Check if 'mRule2' is equivalent to this MatchRule1045virtual bool equivalent(FormDict& globals, MatchNode* mRule2);10461047void matchrule_swap_commutative_op(const char* instr_ident, int count, int& match_rules_cnt);10481049void dump();1050void output_short(FILE *fp);1051void output(FILE *fp);1052};10531054//------------------------------Attribute--------------------------------------1055class Attribute : public Form {1056private:10571058public:1059// Public Data1060char *_ident; // Name of predefined attribute1061char *_val; // C++ source which evaluates to constant1062int _atype; // Either INS_ATTR or OP_ATTR1063int int_val(ArchDesc &ad); // Return atoi(_val), ensuring syntax.10641065// Public Methods1066Attribute(char *id, char* val, int type);1067~Attribute();10681069void dump();1070void output(FILE *fp);1071};10721073//------------------------------FormatRule-------------------------------------1074class FormatRule : public Form {1075private:10761077public:1078// Public Data1079// There is an entry in _strings, perhaps NULL, that precedes each _rep_vars1080NameList _strings; // Strings passed through to tty->print1081NameList _rep_vars; // replacement variables1082char *_temp; // String representing the assembly code10831084// Public Methods1085FormatRule(char *temp);1086~FormatRule();10871088void dump();1089void output(FILE *fp);1090};10911092#endif // SHARE_VM_ADLC_FORMSSEL_HPP109310941095