0N/A/*
3845N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_ADLC_FORMS_HPP
1879N/A#define SHARE_VM_ADLC_FORMS_HPP
1879N/A
0N/A// FORMS.HPP - ADL Parser Generic and Utility Forms Classes
0N/A
0N/A#define TRUE 1
0N/A#define FALSE 0
0N/A
0N/A// DEFINITIONS OF LEGAL ATTRIBUTE TYPES
0N/A#define INS_ATTR 0
0N/A#define OP_ATTR 1
0N/A
0N/A// DEFINITIONS OF LEGAL CONSTRAINT TYPES
0N/A
0N/A// Class List
0N/Aclass Form;
0N/Aclass InstructForm;
0N/Aclass MachNodeForm;
0N/Aclass OperandForm;
0N/Aclass OpClassForm;
0N/Aclass AttributeForm;
0N/Aclass RegisterForm;
0N/Aclass PipelineForm;
0N/Aclass SourceForm;
0N/Aclass EncodeForm;
0N/Aclass Component;
0N/Aclass Constraint;
0N/Aclass Predicate;
0N/Aclass MatchRule;
0N/Aclass Attribute;
0N/Aclass Effect;
0N/Aclass ExpandRule;
0N/Aclass RewriteRule;
0N/Aclass ConstructRule;
0N/Aclass FormatRule;
0N/Aclass Peephole;
0N/Aclass EncClass;
0N/Aclass Interface;
0N/Aclass RegInterface;
0N/Aclass ConstInterface;
0N/Aclass MemInterface;
0N/Aclass CondInterface;
0N/Aclass Opcode;
0N/Aclass InsEncode;
0N/Aclass RegDef;
0N/Aclass RegClass;
0N/Aclass AllocClass;
0N/Aclass ResourceForm;
0N/Aclass PipeClassForm;
0N/Aclass PeepMatch;
0N/Aclass PeepConstraint;
0N/Aclass PeepReplace;
0N/Aclass MatchList;
0N/A
0N/Aclass ArchDesc;
0N/A
0N/A//------------------------------FormDict---------------------------------------
0N/A// Dictionary containing Forms, and objects derived from forms
0N/Aclass FormDict {
0N/Aprivate:
0N/A Dict _form; // map names, char*, to their Form* or NULL
0N/A
0N/A // Disable public use of constructor, copy-ctor, operator =, operator ==
0N/A FormDict( );
0N/A FormDict &operator =( const FormDict & );
0N/A // == compares two dictionaries; they must have the same keys (their keys
0N/A // must match using CmpKey) and they must have the same values (pointer
0N/A // comparison). If so 1 is returned, if not 0 is returned.
0N/A bool operator ==(const FormDict &d) const; // Compare dictionaries for equal
0N/A
0N/Apublic:
0N/A // cmp is a key comparision routine. hash is a routine to hash a key.
0N/A // FormDict( CmpKey cmp, Hash hash );
0N/A FormDict( CmpKey cmp, Hash hash, Arena *arena );
0N/A FormDict( const FormDict & fd ); // Deep-copy guts
0N/A ~FormDict();
0N/A
0N/A // Return # of key-value pairs in dict
0N/A int Size(void) const;
0N/A
0N/A // Insert inserts the given key-value pair into the dictionary. The prior
0N/A // value of the key is returned; NULL if the key was not previously defined.
0N/A const Form *Insert(const char *name, Form *form); // A new key-value
0N/A
0N/A // Find finds the value of a given key; or NULL if not found.
0N/A // The dictionary is NOT changed.
0N/A const Form *operator [](const char *name) const; // Do a lookup
0N/A
0N/A void dump();
0N/A};
0N/A
0N/A// ***** Master Class for ADL Parser Forms *****
0N/A//------------------------------Form-------------------------------------------
0N/Aclass Form {
0N/Apublic:
0N/A static Arena *arena; // arena used by forms
0N/Aprivate:
0N/A static Arena *generate_arena(); // allocate arena used by forms
0N/A
0N/Aprotected:
0N/A int _ftype; // Indicator for derived class type
0N/A
0N/Apublic:
0N/A // Public Data
0N/A Form *_next; // Next pointer for form lists
603N/A int _linenum; // Line number for debugging
0N/A
0N/A // Dynamic type check for common forms.
0N/A virtual OpClassForm *is_opclass() const;
0N/A virtual OperandForm *is_operand() const;
0N/A virtual InstructForm *is_instruction() const;
0N/A virtual MachNodeForm *is_machnode() const;
0N/A virtual AttributeForm *is_attribute() const;
0N/A virtual Effect *is_effect() const;
0N/A virtual ResourceForm *is_resource() const;
0N/A virtual PipeClassForm *is_pipeclass() const;
0N/A
0N/A // Check if this form is an operand usable for cisc-spilling
0N/A virtual bool is_cisc_reg(FormDict &globals) const { return false; }
0N/A virtual bool is_cisc_mem(FormDict &globals) const { return false; }
0N/A
0N/A // Public Methods
0N/A Form(int formType=0, int line=0)
0N/A : _next(NULL), _linenum(line), _ftype(formType) { };
0N/A ~Form() {};
0N/A
0N/A virtual bool ideal_only() const {
0N/A assert(0,"Check of ideal status on non-instruction/operand form.\n");
0N/A return FALSE;
0N/A }
0N/A
0N/A // Check constraints after parsing
0N/A virtual bool verify() { return true; }
0N/A
0N/A virtual void dump() { output(stderr); } // Debug printer
0N/A // Write info to output files
0N/A virtual void output(FILE *fp) { fprintf(fp,"Form Output"); }
0N/A
0N/Apublic:
0N/A // ADLC types, match the last character on ideal operands and instructions
0N/A enum DataType {
0N/A none = 0, // Not a simple type
0N/A idealI = 1, // Integer type
0N/A idealP = 2, // Pointer types, oop(s)
0N/A idealL = 3, // Long type
0N/A idealF = 4, // Float type
0N/A idealD = 5, // Double type
0N/A idealB = 6, // Byte type
0N/A idealC = 7, // Char type
113N/A idealS = 8, // String type
3845N/A idealN = 9, // Narrow oop types
3845N/A idealV = 10 // Vector type
0N/A };
0N/A // Convert ideal name to a DataType, return DataType::none if not a 'ConX'
0N/A Form::DataType ideal_to_const_type(const char *ideal_type_name) const;
0N/A // Convert ideal name to a DataType, return DataType::none if not a 'sRegX
0N/A Form::DataType ideal_to_sReg_type(const char *name) const;
0N/A // Convert ideal name to a DataType, return DataType::none if not a 'RegX
0N/A Form::DataType ideal_to_Reg_type(const char *name) const;
0N/A
0N/A // Convert ideal name to a DataType, return DataType::none if not a 'LoadX
0N/A Form::DataType is_load_from_memory(const char *opType) const;
0N/A // Convert ideal name to a DataType, return DataType::none if not a 'StoreX
0N/A Form::DataType is_store_to_memory(const char *opType) const;
0N/A
0N/A // ADLC call types, matched with ideal world
0N/A enum CallType {
0N/A invalid_type = 0, // invalid call type
0N/A JAVA_STATIC = 1, // monomorphic entry
0N/A JAVA_DYNAMIC = 2, // possibly megamorphic, inline cache call
0N/A JAVA_COMPILED = 3, // callee will be compiled java
0N/A JAVA_INTERP = 4, // callee will be executed by interpreter
0N/A JAVA_NATIVE = 5, // native entrypoint
0N/A JAVA_RUNTIME = 6, // runtime entrypoint
0N/A JAVA_LEAF = 7 // calling leaf
0N/A };
0N/A
0N/A // Interface types for operands and operand classes
0N/A enum InterfaceType {
0N/A no_interface = 0, // unknown or inconsistent interface type
0N/A constant_interface = 1, // interface to constants
0N/A register_interface = 2, // interface to registers
0N/A memory_interface = 3, // interface to memory
0N/A conditional_interface = 4 // interface for condition codes
0N/A };
0N/A virtual Form::InterfaceType interface_type(FormDict &globals) const;
0N/A
0N/A enum CiscSpillInfo {
0N/A Not_cisc_spillable = AdlcVMDeps::Not_cisc_spillable,
0N/A Maybe_cisc_spillable = 0,
0N/A Is_cisc_spillable = 1
0N/A // ...
0N/A };
0N/A
0N/A // LEGAL FORM TYPES
0N/A enum {
0N/A INS,
0N/A OPER,
0N/A OPCLASS,
0N/A SRC,
0N/A ADEF,
0N/A REG,
0N/A PIPE,
0N/A CNST,
0N/A PRED,
0N/A ATTR,
0N/A MAT,
0N/A ENC,
0N/A FOR,
0N/A EXP,
0N/A REW,
0N/A EFF,
0N/A RDEF,
0N/A RCL,
0N/A ACL,
0N/A RES,
0N/A PCL,
0N/A PDEF,
0N/A REGL,
0N/A RESL,
0N/A STAL,
0N/A COMP,
0N/A PEEP,
0N/A RESO
0N/A };
0N/A
0N/A};
0N/A
0N/A//------------------------------FormList---------------------------------------
0N/Aclass FormList {
0N/Aprivate:
0N/A Form *_root;
0N/A Form *_tail;
0N/A Form *_cur;
0N/A int _justReset; // Set immediately after reset
0N/A Form *_cur2; // Nested iterator
0N/A int _justReset2;
0N/A
0N/Apublic:
0N/A void addForm(Form * entry) {
0N/A if (_tail==NULL) { _root = _tail = _cur = entry;}
0N/A else { _tail->_next = entry; _tail = entry;}
0N/A };
0N/A Form * current() { return _cur; };
0N/A Form * iter() { if (_justReset) _justReset = 0;
0N/A else if (_cur) _cur = _cur->_next;
0N/A return _cur;};
0N/A void reset() { if (_root) {_cur = _root; _justReset = 1;} };
0N/A
0N/A // Second iterator, state is internal
0N/A Form * current2(){ return _cur2; };
0N/A Form * iter2() { if (_justReset2) _justReset2 = 0;
0N/A else if (_cur2) _cur2 = _cur2->_next;
0N/A return _cur2;};
0N/A void reset2() { if (_root) {_cur2 = _root; _justReset2 = 1;} };
0N/A
0N/A int count() {
0N/A int count = 0; reset();
0N/A for( Form *cur; (cur = iter()) != NULL; ) { ++count; };
0N/A return count;
0N/A }
0N/A
0N/A void dump() {
0N/A reset();
0N/A Form *cur;
0N/A for(; (cur = iter()) != NULL; ) {
0N/A cur->dump();
0N/A };
0N/A }
0N/A
0N/A bool verify() {
0N/A bool verified = true;
0N/A
0N/A reset();
0N/A Form *cur;
0N/A for(; (cur = iter()) != NULL; ) {
0N/A if ( ! cur->verify() ) verified = false;
0N/A };
0N/A
0N/A return verified;
0N/A }
0N/A
0N/A void output(FILE* fp) {
0N/A reset();
0N/A Form *cur;
0N/A for( ; (cur = iter()) != NULL; ) {
0N/A cur->output(fp);
0N/A };
0N/A }
0N/A
0N/A FormList() { _justReset = 1; _justReset2 = 1; _root = NULL; _tail = NULL; _cur = NULL; _cur2 = NULL;};
0N/A ~FormList();
0N/A};
0N/A
0N/A//------------------------------NameList---------------------------------------
0N/A// Extendable list of pointers, <char *>
0N/Aclass NameList {
0N/A friend class PreserveIter;
0N/A
0N/Aprivate:
0N/A int _cur; // Insert next entry here; count of entries
0N/A int _max; // Number of spaces allocated
0N/A const char **_names; // Array of names
0N/A
0N/Aprotected:
0N/A int _iter; // position during iteration
0N/A bool _justReset; // Set immediately after reset
0N/A
0N/A
0N/Apublic:
0N/A static const char *_signal; // reserved user-defined string
415N/A static const char *_signal2; // reserved user-defined string
415N/A static const char *_signal3; // reserved user-defined string
0N/A enum { Not_in_list = -1 };
0N/A
0N/A void addName(const char *name);
0N/A void add_signal();
0N/A void clear(); // Remove all entries
0N/A
0N/A int count() const;
0N/A
0N/A void reset(); // Reset iteration
0N/A const char *iter(); // after reset(), first element : else next
0N/A const char *current(); // return current element in iteration.
624N/A const char *peek(int skip = 1); // returns element + skip in iteration if there is one
0N/A
0N/A bool current_is_signal(); // Return 'true' if current entry is signal
0N/A bool is_signal(const char *entry); // Return true if entry is a signal
0N/A
0N/A bool search(const char *); // Search for a name in the list
0N/A int index(const char *); // Return index of name in list
0N/A const char *name (intptr_t index);// Return name at index in list
0N/A
0N/A void dump(); // output to stderr
0N/A void output(FILE *fp); // Output list of names to 'fp'
0N/A
0N/A NameList();
0N/A ~NameList();
0N/A};
0N/A
0N/A
0N/A// Convenience class to preserve iteration state since iterators are
0N/A// internal instead of being external.
0N/Aclass PreserveIter {
0N/A private:
0N/A NameList* _list;
0N/A int _iter;
0N/A bool _justReset;
0N/A
0N/A public:
0N/A PreserveIter(NameList* nl) {
0N/A _list = nl;
0N/A _iter = _list->_iter;
0N/A _justReset = _list->_justReset;
0N/A }
0N/A ~PreserveIter() {
0N/A _list->_iter = _iter;
0N/A _list->_justReset = _justReset;
0N/A }
0N/A
0N/A};
0N/A
0N/A
0N/A//------------------------------NameAndList------------------------------------
0N/A// Storage for a name and an associated list of names
0N/Aclass NameAndList {
0N/Aprivate:
0N/A const char *_name;
0N/A NameList _list;
0N/A
0N/Apublic:
0N/A NameAndList(char *name);
0N/A ~NameAndList();
0N/A
0N/A // Add to entries in list
0N/A void add_entry(const char *entry);
0N/A
0N/A // Access the name and its associated list.
0N/A const char *name() const;
0N/A void reset();
0N/A const char *iter();
0N/A
0N/A int count() { return _list.count(); }
0N/A
0N/A // Return the "index" entry in the list, zero-based
0N/A const char *operator[](int index);
0N/A
0N/A
0N/A void dump(); // output to stderr
0N/A void output(FILE *fp); // Output list of names to 'fp'
0N/A};
0N/A
0N/A//------------------------------ComponentList---------------------------------
0N/A// Component lists always have match rule operands first, followed by parameter
0N/A// operands which do not appear in the match list (in order of declaration).
0N/Aclass ComponentList : private NameList {
0N/Aprivate:
0N/A int _matchcnt; // Count of match rule operands
0N/A
0N/Apublic:
0N/A
0N/A // This is a batch program. (And I have a destructor bug!)
0N/A void operator delete( void *ptr ) {}
0N/A
0N/A void insert(Component *component, bool mflag);
0N/A void insert(const char *name, const char *opType, int usedef, bool mflag);
0N/A
0N/A int count();
0N/A int match_count() { return _matchcnt; } // Get count of match rule opers
0N/A
0N/A Component *iter(); // after reset(), first element : else next
0N/A Component *match_iter(); // after reset(), first element : else next
0N/A Component *post_match_iter(); // after reset(), first element : else next
0N/A void reset(); // Reset iteration
0N/A Component *current(); // return current element in iteration.
0N/A
0N/A // Return element at "position", else NULL
0N/A Component *operator[](int position);
0N/A Component *at(int position) { return (*this)[position]; }
0N/A
0N/A // Return first component having this name.
0N/A const Component *search(const char *name);
0N/A
0N/A // Return number of USEs + number of DEFs
0N/A int num_operands();
0N/A // Return zero-based position in list; -1 if not in list.
4033N/A int operand_position(const char *name, int usedef, Form *fm);
0N/A // Find position for this name, regardless of use/def information
0N/A int operand_position(const char *name);
0N/A // Find position for this name when looked up for output via "format"
4033N/A int operand_position_format(const char *name, Form *fm);
0N/A // Find position for the Label when looked up for output via "format"
0N/A int label_position();
0N/A // Find position for the Method when looked up for output via "format"
0N/A int method_position();
0N/A
0N/A void dump(); // output to stderr
0N/A void output(FILE *fp); // Output list of names to 'fp'
0N/A
0N/A ComponentList();
0N/A ~ComponentList();
0N/A};
0N/A
0N/A//------------------------------SourceForm-------------------------------------
0N/Aclass SourceForm : public Form {
0N/Aprivate:
0N/A
0N/Apublic:
0N/A // Public Data
0N/A char *_code; // Buffer for storing code text
0N/A
0N/A // Public Methods
0N/A SourceForm(char* code);
0N/A ~SourceForm();
0N/A
0N/A virtual const char* classname() { return "SourceForm"; }
0N/A
0N/A void dump(); // Debug printer
0N/A void output(FILE *fp); // Write output files
0N/A};
0N/A
0N/Aclass HeaderForm : public SourceForm {
0N/Apublic:
0N/A HeaderForm(char* code) : SourceForm(code) { }
0N/A
0N/A virtual const char* classname() { return "HeaderForm"; }
0N/A};
0N/A
0N/Aclass PreHeaderForm : public SourceForm {
0N/Apublic:
0N/A PreHeaderForm(char* code) : SourceForm(code) { }
0N/A
0N/A virtual const char* classname() { return "PreHeaderForm"; }
0N/A};
0N/A
0N/A
0N/A
0N/A
0N/A//------------------------------Expr------------------------------------------
0N/A#define STRING_BUFFER_LENGTH 2048
0N/A// class Expr represents integer expressions containing constants and addition
0N/A// Value must be in range zero through maximum positive integer. 32bits.
0N/A// Expected use: instruction and operand costs
0N/Aclass Expr {
0N/Apublic:
0N/A enum {
0N/A Zero = 0,
0N/A Max = 0x7fffffff
0N/A };
0N/A const char *_external_name; // if !NULL, then print this instead of _expr
0N/A const char *_expr;
0N/A int _min_value;
0N/A int _max_value;
0N/A
0N/A Expr();
0N/A Expr(const char *cost);
0N/A Expr(const char *name, const char *expression, int min_value, int max_value);
0N/A Expr *clone() const;
0N/A
0N/A bool is_unknown() const { return (this == Expr::get_unknown()); }
0N/A bool is_zero() const { return (_min_value == Expr::Zero && _max_value == Expr::Zero); }
0N/A bool less_than_or_equal(const Expr *c) const { return (_max_value <= c->_min_value); }
0N/A
0N/A void add(const Expr *c);
0N/A void add(const char *c);
0N/A void add(const char *c, ArchDesc &AD); // check if 'c' is defined in <arch>.ad
0N/A void set_external_name(const char *name) { _external_name = name; }
0N/A
0N/A const char *as_string() const { return (_external_name != NULL ? _external_name : _expr); }
0N/A void print() const;
0N/A void print_define(FILE *fp) const;
0N/A void print_assert(FILE *fp) const;
0N/A
0N/A static Expr *get_unknown(); // Returns pointer to shared unknown cost instance
0N/A
0N/A static char *buffer() { return &external_buffer[0]; }
0N/A static bool init_buffers(); // Fill buffers with 0
0N/A static bool check_buffers(); // if buffer use may have overflowed, assert
0N/A
0N/Aprivate:
0N/A static Expr *_unknown_expr;
0N/A static char string_buffer[STRING_BUFFER_LENGTH];
0N/A static char external_buffer[STRING_BUFFER_LENGTH];
0N/A static bool _init_buffers;
0N/A const char *compute_expr(const Expr *c1, const Expr *c2); // cost as string after adding 'c1' and 'c2'
0N/A int compute_min (const Expr *c1, const Expr *c2); // minimum after adding 'c1' and 'c2'
0N/A int compute_max (const Expr *c1, const Expr *c2); // maximum after adding 'c1' and 'c2'
0N/A const char *compute_external(const Expr *c1, const Expr *c2); // external name after adding 'c1' and 'c2'
0N/A};
0N/A
0N/A//------------------------------ExprDict---------------------------------------
0N/A// Dictionary containing Exprs
0N/Aclass ExprDict {
0N/Aprivate:
0N/A Dict _expr; // map names, char*, to their Expr* or NULL
0N/A NameList _defines; // record the order of definitions entered with define call
0N/A
0N/A // Disable public use of constructor, copy-ctor, operator =, operator ==
0N/A ExprDict( );
0N/A ExprDict( const ExprDict & ); // Deep-copy guts
0N/A ExprDict &operator =( const ExprDict & );
0N/A // == compares two dictionaries; they must have the same keys (their keys
0N/A // must match using CmpKey) and they must have the same values (pointer
0N/A // comparison). If so 1 is returned, if not 0 is returned.
0N/A bool operator ==(const ExprDict &d) const; // Compare dictionaries for equal
0N/A
0N/Apublic:
0N/A // cmp is a key comparision routine. hash is a routine to hash a key.
0N/A ExprDict( CmpKey cmp, Hash hash, Arena *arena );
0N/A ~ExprDict();
0N/A
0N/A // Return # of key-value pairs in dict
0N/A int Size(void) const;
0N/A
0N/A // define inserts the given key-value pair into the dictionary,
0N/A // and records the name in order for later output, ...
0N/A const Expr *define(const char *name, Expr *expr);
0N/A
0N/A // Insert inserts the given key-value pair into the dictionary. The prior
0N/A // value of the key is returned; NULL if the key was not previously defined.
0N/A const Expr *Insert(const char *name, Expr *expr); // A new key-value
0N/A
0N/A // Find finds the value of a given key; or NULL if not found.
0N/A // The dictionary is NOT changed.
0N/A const Expr *operator [](const char *name) const; // Do a lookup
0N/A
0N/A void print_defines(FILE *fp);
0N/A void print_asserts(FILE *fp);
0N/A void dump();
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_ADLC_FORMS_HPP