Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/forms.hpp
32285 views
/*1* Copyright (c) 1997, 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_FORMS_HPP25#define SHARE_VM_ADLC_FORMS_HPP2627// FORMS.HPP - ADL Parser Generic and Utility Forms Classes2829#define TRUE 130#define FALSE 03132// DEFINITIONS OF LEGAL ATTRIBUTE TYPES33#define INS_ATTR 034#define OP_ATTR 13536// DEFINITIONS OF LEGAL CONSTRAINT TYPES3738// Class List39class Form;40class InstructForm;41class MachNodeForm;42class OperandForm;43class OpClassForm;44class AttributeForm;45class RegisterForm;46class PipelineForm;47class SourceForm;48class EncodeForm;49class Component;50class Constraint;51class Predicate;52class MatchRule;53class Attribute;54class Effect;55class ExpandRule;56class RewriteRule;57class ConstructRule;58class FormatRule;59class Peephole;60class EncClass;61class Interface;62class RegInterface;63class ConstInterface;64class MemInterface;65class CondInterface;66class Opcode;67class InsEncode;68class RegDef;69class RegClass;70class CodeSnippetRegClass;71class ConditionalRegClass;72class AllocClass;73class ResourceForm;74class PipeClassForm;75class PeepMatch;76class PeepConstraint;77class PeepReplace;78class MatchList;7980class ArchDesc;8182//------------------------------FormDict---------------------------------------83// Dictionary containing Forms, and objects derived from forms84class FormDict {85private:86Dict _form; // map names, char*, to their Form* or NULL8788// Disable public use of constructor, copy-ctor, operator =, operator ==89FormDict( );90FormDict &operator =( const FormDict & );91// == compares two dictionaries; they must have the same keys (their keys92// must match using CmpKey) and they must have the same values (pointer93// comparison). If so 1 is returned, if not 0 is returned.94bool operator ==(const FormDict &d) const; // Compare dictionaries for equal9596public:97// cmp is a key comparision routine. hash is a routine to hash a key.98// FormDict( CmpKey cmp, Hash hash );99FormDict( CmpKey cmp, Hash hash, Arena *arena );100FormDict( const FormDict & fd ); // Deep-copy guts101~FormDict();102103// Return # of key-value pairs in dict104int Size(void) const;105106// Insert inserts the given key-value pair into the dictionary. The prior107// value of the key is returned; NULL if the key was not previously defined.108const Form *Insert(const char *name, Form *form); // A new key-value109110// Find finds the value of a given key; or NULL if not found.111// The dictionary is NOT changed.112const Form *operator [](const char *name) const; // Do a lookup113114void dump();115};116117// ***** Master Class for ADL Parser Forms *****118//------------------------------Form-------------------------------------------119class Form {120public:121static Arena *arena; // arena used by forms122private:123static Arena *generate_arena(); // allocate arena used by forms124125protected:126int _ftype; // Indicator for derived class type127128public:129// Public Data130Form *_next; // Next pointer for form lists131int _linenum; // Line number for debugging132133// Dynamic type check for common forms.134virtual OpClassForm *is_opclass() const;135virtual OperandForm *is_operand() const;136virtual InstructForm *is_instruction() const;137virtual MachNodeForm *is_machnode() const;138virtual AttributeForm *is_attribute() const;139virtual Effect *is_effect() const;140virtual ResourceForm *is_resource() const;141virtual PipeClassForm *is_pipeclass() const;142143// Check if this form is an operand usable for cisc-spilling144virtual bool is_cisc_reg(FormDict &globals) const { return false; }145virtual bool is_cisc_mem(FormDict &globals) const { return false; }146147// Public Methods148Form(int formType=0, int line=0)149: _next(NULL), _linenum(line), _ftype(formType) { };150virtual ~Form() {};151152virtual bool ideal_only() const {153assert(0,"Check of ideal status on non-instruction/operand form.\n");154return FALSE;155}156157// Check constraints after parsing158virtual bool verify() { return true; }159160virtual void dump() { output(stderr); } // Debug printer161// Write info to output files162virtual void output(FILE *fp) { fprintf(fp,"Form Output"); }163164public:165// ADLC types, match the last character on ideal operands and instructions166enum DataType {167none = 0, // Not a simple type168idealI = 1, // Integer type169idealP = 2, // Pointer types, oop(s)170idealL = 3, // Long type171idealF = 4, // Float type172idealD = 5, // Double type173idealB = 6, // Byte type174idealC = 7, // Char type175idealS = 8, // String type176idealN = 9, // Narrow oop types177idealNKlass = 10, // Narrow klass types178idealV = 11 // Vector type179};180// Convert ideal name to a DataType, return DataType::none if not a 'ConX'181Form::DataType ideal_to_const_type(const char *ideal_type_name) const;182// Convert ideal name to a DataType, return DataType::none if not a 'sRegX183Form::DataType ideal_to_sReg_type(const char *name) const;184// Convert ideal name to a DataType, return DataType::none if not a 'RegX185Form::DataType ideal_to_Reg_type(const char *name) const;186187// Convert ideal name to a DataType, return DataType::none if not a 'LoadX188Form::DataType is_load_from_memory(const char *opType) const;189// Convert ideal name to a DataType, return DataType::none if not a 'StoreX190Form::DataType is_store_to_memory(const char *opType) const;191192// ADLC call types, matched with ideal world193enum CallType {194invalid_type = 0, // invalid call type195JAVA_STATIC = 1, // monomorphic entry196JAVA_DYNAMIC = 2, // possibly megamorphic, inline cache call197JAVA_COMPILED = 3, // callee will be compiled java198JAVA_INTERP = 4, // callee will be executed by interpreter199JAVA_NATIVE = 5, // native entrypoint200JAVA_RUNTIME = 6, // runtime entrypoint201JAVA_LEAF = 7 // calling leaf202};203204// Interface types for operands and operand classes205enum InterfaceType {206no_interface = 0, // unknown or inconsistent interface type207constant_interface = 1, // interface to constants208register_interface = 2, // interface to registers209memory_interface = 3, // interface to memory210conditional_interface = 4 // interface for condition codes211};212virtual Form::InterfaceType interface_type(FormDict &globals) const;213214enum CiscSpillInfo {215Not_cisc_spillable = AdlcVMDeps::Not_cisc_spillable,216Maybe_cisc_spillable = 0,217Is_cisc_spillable = 1218// ...219};220221// LEGAL FORM TYPES222enum {223INS,224OPER,225OPCLASS,226SRC,227ADEF,228REG,229PIPE,230CNST,231PRED,232ATTR,233MAT,234ENC,235FOR,236EXP,237REW,238EFF,239RDEF,240RCL,241ACL,242RES,243PCL,244PDEF,245REGL,246RESL,247STAL,248COMP,249PEEP,250RESO251};252253};254255//------------------------------FormList---------------------------------------256class FormList {257private:258Form *_root;259Form *_tail;260Form *_cur;261int _justReset; // Set immediately after reset262Form *_cur2; // Nested iterator263int _justReset2;264265public:266void addForm(Form * entry) {267if (_tail==NULL) { _root = _tail = _cur = entry;}268else { _tail->_next = entry; _tail = entry;}269};270Form * current() { return _cur; };271Form * iter() { if (_justReset) _justReset = 0;272else if (_cur) _cur = _cur->_next;273return _cur;};274void reset() { if (_root) {_cur = _root; _justReset = 1;} };275276// Second iterator, state is internal277Form * current2(){ return _cur2; };278Form * iter2() { if (_justReset2) _justReset2 = 0;279else if (_cur2) _cur2 = _cur2->_next;280return _cur2;};281void reset2() { if (_root) {_cur2 = _root; _justReset2 = 1;} };282283int count() {284int count = 0; reset();285for( Form *cur; (cur = iter()) != NULL; ) { ++count; };286return count;287}288289void dump() {290reset();291Form *cur;292for(; (cur = iter()) != NULL; ) {293cur->dump();294};295}296297bool verify() {298bool verified = true;299300reset();301Form *cur;302for(; (cur = iter()) != NULL; ) {303if ( ! cur->verify() ) verified = false;304};305306return verified;307}308309void output(FILE* fp) {310reset();311Form *cur;312for( ; (cur = iter()) != NULL; ) {313cur->output(fp);314};315}316317FormList() { _justReset = 1; _justReset2 = 1; _root = NULL; _tail = NULL; _cur = NULL; _cur2 = NULL;};318~FormList();319};320321//------------------------------NameList---------------------------------------322// Extendable list of pointers, <char *>323class NameList {324friend class PreserveIter;325326private:327int _cur; // Insert next entry here; count of entries328int _max; // Number of spaces allocated329const char **_names; // Array of names330331protected:332int _iter; // position during iteration333bool _justReset; // Set immediately after reset334335336public:337static const char *_signal; // reserved user-defined string338static const char *_signal2; // reserved user-defined string339static const char *_signal3; // reserved user-defined string340enum { Not_in_list = -1 };341342void addName(const char *name);343void add_signal();344void clear(); // Remove all entries345346int count() const;347348void reset(); // Reset iteration349const char *iter(); // after reset(), first element : else next350const char *current(); // return current element in iteration.351const char *peek(int skip = 1); // returns element + skip in iteration if there is one352353bool current_is_signal(); // Return 'true' if current entry is signal354bool is_signal(const char *entry); // Return true if entry is a signal355356bool search(const char *); // Search for a name in the list357int index(const char *); // Return index of name in list358const char *name (intptr_t index);// Return name at index in list359360void dump(); // output to stderr361void output(FILE *fp); // Output list of names to 'fp'362363NameList();364~NameList();365};366367368// Convenience class to preserve iteration state since iterators are369// internal instead of being external.370class PreserveIter {371private:372NameList* _list;373int _iter;374bool _justReset;375376public:377PreserveIter(NameList* nl) {378_list = nl;379_iter = _list->_iter;380_justReset = _list->_justReset;381}382~PreserveIter() {383_list->_iter = _iter;384_list->_justReset = _justReset;385}386387};388389390//------------------------------NameAndList------------------------------------391// Storage for a name and an associated list of names392class NameAndList {393private:394const char *_name;395NameList _list;396397public:398NameAndList(char *name);399~NameAndList();400401// Add to entries in list402void add_entry(const char *entry);403404// Access the name and its associated list.405const char *name() const;406void reset();407const char *iter();408409int count() { return _list.count(); }410411// Return the "index" entry in the list, zero-based412const char *operator[](int index);413414415void dump(); // output to stderr416void output(FILE *fp); // Output list of names to 'fp'417};418419//------------------------------ComponentList---------------------------------420// Component lists always have match rule operands first, followed by parameter421// operands which do not appear in the match list (in order of declaration).422class ComponentList : private NameList {423private:424int _matchcnt; // Count of match rule operands425426public:427428// This is a batch program. (And I have a destructor bug!)429void operator delete( void *ptr ) {}430431void insert(Component *component, bool mflag);432void insert(const char *name, const char *opType, int usedef, bool mflag);433434int count();435int match_count() { return _matchcnt; } // Get count of match rule opers436437Component *iter(); // after reset(), first element : else next438Component *match_iter(); // after reset(), first element : else next439Component *post_match_iter(); // after reset(), first element : else next440void reset(); // Reset iteration441Component *current(); // return current element in iteration.442443// Return element at "position", else NULL444Component *operator[](int position);445Component *at(int position) { return (*this)[position]; }446447// Return first component having this name.448const Component *search(const char *name);449450// Return number of USEs + number of DEFs451int num_operands();452// Return zero-based position in list; -1 if not in list.453int operand_position(const char *name, int usedef, Form *fm);454// Find position for this name, regardless of use/def information455int operand_position(const char *name);456// Find position for this name when looked up for output via "format"457int operand_position_format(const char *name, Form *fm);458// Find position for the Label when looked up for output via "format"459int label_position();460// Find position for the Method when looked up for output via "format"461int method_position();462463void dump(); // output to stderr464void output(FILE *fp); // Output list of names to 'fp'465466ComponentList();467~ComponentList();468};469470//------------------------------SourceForm-------------------------------------471class SourceForm : public Form {472private:473474public:475// Public Data476char *_code; // Buffer for storing code text477478// Public Methods479SourceForm(char* code);480~SourceForm();481482virtual const char* classname() { return "SourceForm"; }483484void dump(); // Debug printer485void output(FILE *fp); // Write output files486};487488class HeaderForm : public SourceForm {489public:490HeaderForm(char* code) : SourceForm(code) { }491492virtual const char* classname() { return "HeaderForm"; }493};494495class PreHeaderForm : public SourceForm {496public:497PreHeaderForm(char* code) : SourceForm(code) { }498499virtual const char* classname() { return "PreHeaderForm"; }500};501502503504505//------------------------------Expr------------------------------------------506#define STRING_BUFFER_LENGTH 2048507// class Expr represents integer expressions containing constants and addition508// Value must be in range zero through maximum positive integer. 32bits.509// Expected use: instruction and operand costs510class Expr {511public:512enum {513Zero = 0,514Max = 0x7fffffff515};516const char *_external_name; // if !NULL, then print this instead of _expr517const char *_expr;518int _min_value;519int _max_value;520521Expr();522Expr(const char *cost);523Expr(const char *name, const char *expression, int min_value, int max_value);524Expr *clone() const;525526bool is_unknown() const { return (this == Expr::get_unknown()); }527bool is_zero() const { return (_min_value == Expr::Zero && _max_value == Expr::Zero); }528bool less_than_or_equal(const Expr *c) const { return (_max_value <= c->_min_value); }529530void add(const Expr *c);531void add(const char *c);532void add(const char *c, ArchDesc &AD); // check if 'c' is defined in <arch>.ad533void set_external_name(const char *name) { _external_name = name; }534535const char *as_string() const { return (_external_name != NULL ? _external_name : _expr); }536void print() const;537void print_define(FILE *fp) const;538void print_assert(FILE *fp) const;539540static Expr *get_unknown(); // Returns pointer to shared unknown cost instance541542static char *buffer() { return &external_buffer[0]; }543static bool init_buffers(); // Fill buffers with 0544static bool check_buffers(); // if buffer use may have overflowed, assert545546private:547static Expr *_unknown_expr;548static char string_buffer[STRING_BUFFER_LENGTH];549static char external_buffer[STRING_BUFFER_LENGTH];550static bool _init_buffers;551const char *compute_expr(const Expr *c1, const Expr *c2); // cost as string after adding 'c1' and 'c2'552int compute_min (const Expr *c1, const Expr *c2); // minimum after adding 'c1' and 'c2'553int compute_max (const Expr *c1, const Expr *c2); // maximum after adding 'c1' and 'c2'554const char *compute_external(const Expr *c1, const Expr *c2); // external name after adding 'c1' and 'c2'555};556557//------------------------------ExprDict---------------------------------------558// Dictionary containing Exprs559class ExprDict {560private:561Dict _expr; // map names, char*, to their Expr* or NULL562NameList _defines; // record the order of definitions entered with define call563564// Disable public use of constructor, copy-ctor, operator =, operator ==565ExprDict( );566ExprDict( const ExprDict & ); // Deep-copy guts567ExprDict &operator =( const ExprDict & );568// == compares two dictionaries; they must have the same keys (their keys569// must match using CmpKey) and they must have the same values (pointer570// comparison). If so 1 is returned, if not 0 is returned.571bool operator ==(const ExprDict &d) const; // Compare dictionaries for equal572573public:574// cmp is a key comparision routine. hash is a routine to hash a key.575ExprDict( CmpKey cmp, Hash hash, Arena *arena );576~ExprDict();577578// Return # of key-value pairs in dict579int Size(void) const;580581// define inserts the given key-value pair into the dictionary,582// and records the name in order for later output, ...583const Expr *define(const char *name, Expr *expr);584585// Insert inserts the given key-value pair into the dictionary. The prior586// value of the key is returned; NULL if the key was not previously defined.587const Expr *Insert(const char *name, Expr *expr); // A new key-value588589// Find finds the value of a given key; or NULL if not found.590// The dictionary is NOT changed.591const Expr *operator [](const char *name) const; // Do a lookup592593void print_defines(FILE *fp);594void print_asserts(FILE *fp);595void dump();596};597598#endif // SHARE_VM_ADLC_FORMS_HPP599600601