src/share/vm/adlc/forms.hpp

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 548
ba764ed4b6f2
child 850
4d9884b01ba6
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 1997-2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // FORMS.HPP - ADL Parser Generic and Utility Forms Classes
    27 #define TRUE 1
    28 #define FALSE 0
    30 // DEFINITIONS OF LEGAL ATTRIBUTE TYPES
    31 #define INS_ATTR 0
    32 #define OP_ATTR  1
    34 // DEFINITIONS OF LEGAL CONSTRAINT TYPES
    36 // Class List
    37 class Form;
    38 class InstructForm;
    39 class MachNodeForm;
    40 class OperandForm;
    41 class OpClassForm;
    42 class AttributeForm;
    43 class RegisterForm;
    44 class PipelineForm;
    45 class SourceForm;
    46 class EncodeForm;
    47 class Component;
    48 class Constraint;
    49 class Predicate;
    50 class MatchRule;
    51 class Attribute;
    52 class Effect;
    53 class ExpandRule;
    54 class RewriteRule;
    55 class ConstructRule;
    56 class FormatRule;
    57 class Peephole;
    58 class EncClass;
    59 class Interface;
    60 class RegInterface;
    61 class ConstInterface;
    62 class MemInterface;
    63 class CondInterface;
    64 class Opcode;
    65 class InsEncode;
    66 class RegDef;
    67 class RegClass;
    68 class AllocClass;
    69 class ResourceForm;
    70 class PipeClassForm;
    71 class PeepMatch;
    72 class PeepConstraint;
    73 class PeepReplace;
    74 class MatchList;
    76 class ArchDesc;
    78 //------------------------------FormDict---------------------------------------
    79 // Dictionary containing Forms, and objects derived from forms
    80 class FormDict {
    81 private:
    82   Dict         _form;              // map names, char*, to their Form* or NULL
    84   // Disable public use of constructor, copy-ctor, operator =, operator ==
    85   FormDict( );
    86   FormDict &operator =( const FormDict & );
    87   // == compares two dictionaries; they must have the same keys (their keys
    88   // must match using CmpKey) and they must have the same values (pointer
    89   // comparison).  If so 1 is returned, if not 0 is returned.
    90   bool operator ==(const FormDict &d) const; // Compare dictionaries for equal
    92 public:
    93   // cmp is a key comparision routine.  hash is a routine to hash a key.
    94   // FormDict( CmpKey cmp, Hash hash );
    95   FormDict( CmpKey cmp, Hash hash, Arena *arena );
    96   FormDict( const FormDict & fd );    // Deep-copy guts
    97   ~FormDict();
    99   // Return # of key-value pairs in dict
   100   int Size(void) const;
   102   // Insert inserts the given key-value pair into the dictionary.  The prior
   103   // value of the key is returned; NULL if the key was not previously defined.
   104   const Form  *Insert(const char *name, Form *form); // A new key-value
   106   // Find finds the value of a given key; or NULL if not found.
   107   // The dictionary is NOT changed.
   108   const Form  *operator [](const char *name) const;  // Do a lookup
   110   void dump();
   111 };
   113 // ***** Master Class for ADL Parser Forms *****
   114 //------------------------------Form-------------------------------------------
   115 class Form {
   116 public:
   117   static Arena  *arena;            // arena used by forms
   118 private:
   119   static Arena  *generate_arena(); // allocate arena used by forms
   121 protected:
   122   int   _ftype;                    // Indicator for derived class type
   124 public:
   125   // Public Data
   126   Form *_next;                     // Next pointer for form lists
   127   long  _linenum;                  // Line number for debugging
   129   // Dynamic type check for common forms.
   130   virtual OpClassForm   *is_opclass()     const;
   131   virtual OperandForm   *is_operand()     const;
   132   virtual InstructForm  *is_instruction() const;
   133   virtual MachNodeForm  *is_machnode()    const;
   134   virtual AttributeForm *is_attribute()   const;
   135   virtual Effect        *is_effect()      const;
   136   virtual ResourceForm  *is_resource()    const;
   137   virtual PipeClassForm *is_pipeclass()   const;
   139   // Check if this form is an operand usable for cisc-spilling
   140   virtual bool           is_cisc_reg(FormDict &globals) const { return false; }
   141   virtual bool           is_cisc_mem(FormDict &globals) const { return false; }
   143   // Public Methods
   144   Form(int formType=0, int line=0)
   145     : _next(NULL), _linenum(line), _ftype(formType) { };
   146   ~Form() {};
   148   virtual bool ideal_only() const {
   149     assert(0,"Check of ideal status on non-instruction/operand form.\n");
   150     return FALSE;
   151   }
   153   // Check constraints after parsing
   154   virtual bool verify()    { return true; }
   156   virtual void dump()      { output(stderr); }    // Debug printer
   157   // Write info to output files
   158   virtual void output(FILE *fp)    { fprintf(fp,"Form Output"); }
   160 public:
   161   // ADLC types, match the last character on ideal operands and instructions
   162   enum DataType {
   163     none        =  0,  // Not a simple type
   164     idealI      =  1,  // Integer type
   165     idealP      =  2,  // Pointer types, oop(s)
   166     idealL      =  3,  // Long    type
   167     idealF      =  4,  // Float   type
   168     idealD      =  5,  // Double  type
   169     idealB      =  6,  // Byte    type
   170     idealC      =  7,  // Char    type
   171     idealS      =  8,  // String  type
   172     idealN      =  9   // Narrow oop types
   173   };
   174   // Convert ideal name to a DataType, return DataType::none if not a 'ConX'
   175   Form::DataType  ideal_to_const_type(const char *ideal_type_name) const;
   176   // Convert ideal name to a DataType, return DataType::none if not a 'sRegX
   177   Form::DataType  ideal_to_sReg_type(const char *name) const;
   178   // Convert ideal name to a DataType, return DataType::none if not a 'RegX
   179   Form::DataType  ideal_to_Reg_type(const char *name) const;
   181   // Convert ideal name to a DataType, return DataType::none if not a 'LoadX
   182   Form::DataType is_load_from_memory(const char *opType) const;
   183   // Convert ideal name to a DataType, return DataType::none if not a 'StoreX
   184   Form::DataType is_store_to_memory(const char *opType)  const;
   186   // ADLC call types, matched with ideal world
   187   enum CallType {
   188     invalid_type  =  0,  // invalid call type
   189     JAVA_STATIC   =  1,  // monomorphic entry
   190     JAVA_DYNAMIC  =  2,  // possibly megamorphic, inline cache call
   191     JAVA_COMPILED =  3,  // callee will be compiled java
   192     JAVA_INTERP   =  4,  // callee will be executed by interpreter
   193     JAVA_NATIVE   =  5,  // native entrypoint
   194     JAVA_RUNTIME  =  6,  // runtime entrypoint
   195     JAVA_LEAF     =  7   // calling leaf
   196   };
   198   // Interface types for operands and operand classes
   199   enum InterfaceType {
   200     no_interface          =  0,  // unknown or inconsistent interface type
   201     constant_interface    =  1,  // interface to constants
   202     register_interface    =  2,  // interface to registers
   203     memory_interface      =  3,  // interface to memory
   204     conditional_interface =  4   // interface for condition codes
   205   };
   206   virtual Form::InterfaceType interface_type(FormDict &globals) const;
   208   enum CiscSpillInfo {
   209     Not_cisc_spillable   =  AdlcVMDeps::Not_cisc_spillable,
   210     Maybe_cisc_spillable =   0,
   211     Is_cisc_spillable    =   1
   212     // ...
   213   };
   215   // LEGAL FORM TYPES
   216   enum {
   217     INS,
   218     OPER,
   219     OPCLASS,
   220     SRC,
   221     ADEF,
   222     REG,
   223     PIPE,
   224     CNST,
   225     PRED,
   226     ATTR,
   227     MAT,
   228     ENC,
   229     FOR,
   230     EXP,
   231     REW,
   232     EFF,
   233     RDEF,
   234     RCL,
   235     ACL,
   236     RES,
   237     PCL,
   238     PDEF,
   239     REGL,
   240     RESL,
   241     STAL,
   242     COMP,
   243     PEEP,
   244     RESO
   245   };
   247 };
   249 //------------------------------FormList---------------------------------------
   250 class FormList {
   251 private:
   252   Form *_root;
   253   Form *_tail;
   254   Form *_cur;
   255   int   _justReset;                // Set immediately after reset
   256   Form *_cur2;                     // Nested iterator
   257   int   _justReset2;
   259 public:
   260   void addForm(Form * entry) {
   261     if (_tail==NULL) { _root = _tail = _cur = entry;}
   262     else { _tail->_next = entry; _tail = entry;}
   263   };
   264   Form * current() { return _cur; };
   265   Form * iter()    { if (_justReset) _justReset = 0;
   266                      else if (_cur)  _cur = _cur->_next;
   267                      return _cur;};
   268   void   reset()   { if (_root) {_cur = _root; _justReset = 1;} };
   270   // Second iterator, state is internal
   271   Form * current2(){ return _cur2; };
   272   Form * iter2()   { if (_justReset2) _justReset2 = 0;
   273                     else if (_cur2)  _cur2 = _cur2->_next;
   274                     return _cur2;};
   275   void   reset2()  { if (_root) {_cur2 = _root; _justReset2 = 1;} };
   277   int  count() {
   278     int  count = 0; reset();
   279     for( Form *cur; (cur =  iter()) != NULL; ) { ++count; };
   280     return count;
   281   }
   283   void dump() {
   284     reset();
   285     Form *cur;
   286     for(; (cur =  iter()) != NULL; ) {
   287       cur->dump();
   288     };
   289   }
   291   bool verify() {
   292     bool verified = true;
   294     reset();
   295     Form *cur;
   296     for(; (cur =  iter()) != NULL; ) {
   297       if ( ! cur->verify() ) verified = false;
   298     };
   300     return verified;
   301   }
   303   void output(FILE* fp) {
   304     reset();
   305     Form *cur;
   306     for( ; (cur =  iter()) != NULL; ) {
   307       cur->output(fp);
   308     };
   309   }
   311   FormList() { _justReset = 1; _justReset2 = 1; _root = NULL; _tail = NULL; _cur = NULL; _cur2 = NULL;};
   312   ~FormList();
   313 };
   315 //------------------------------NameList---------------------------------------
   316 // Extendable list of pointers, <char *>
   317 class NameList {
   318   friend class PreserveIter;
   320 private:
   321   int                _cur;         // Insert next entry here; count of entries
   322   int                _max;         // Number of spaces allocated
   323   const char       **_names;       // Array of names
   325 protected:
   326   int                _iter;        // position during iteration
   327   bool               _justReset;   // Set immediately after reset
   330 public:
   331   static const char *_signal;      // reserved user-defined string
   332   enum               { Not_in_list = -1 };
   334   void  addName(const char *name);
   335   void  add_signal();
   336   void  clear();                   // Remove all entries
   338   int   count() const;
   340   void  reset();                   // Reset iteration
   341   const char *iter();              // after reset(), first element : else next
   342   const char *current();           // return current element in iteration.
   344   bool  current_is_signal();       // Return 'true' if current entry is signal
   345   bool  is_signal(const char *entry); // Return true if entry is a signal
   347   bool  search(const char *);      // Search for a name in the list
   348   int   index(const char *);       // Return index of name in list
   349   const char *name (intptr_t index);// Return name at index in list
   351   void  dump();                    // output to stderr
   352   void  output(FILE *fp);          // Output list of names to 'fp'
   354   NameList();
   355   ~NameList();
   356 };
   359 // Convenience class to preserve iteration state since iterators are
   360 // internal instead of being external.
   361 class PreserveIter {
   362  private:
   363   NameList* _list;
   364   int _iter;
   365   bool _justReset;
   367  public:
   368   PreserveIter(NameList* nl) {
   369     _list = nl;
   370     _iter = _list->_iter;
   371     _justReset = _list->_justReset;
   372   }
   373   ~PreserveIter() {
   374     _list->_iter = _iter;
   375     _list->_justReset = _justReset;
   376   }
   378 };
   381 //------------------------------NameAndList------------------------------------
   382 // Storage for a name and an associated list of names
   383 class NameAndList {
   384 private:
   385   const char *_name;
   386   NameList    _list;
   388 public:
   389   NameAndList(char *name);
   390   ~NameAndList();
   392   // Add to entries in list
   393   void        add_entry(const char *entry);
   395   // Access the name and its associated list.
   396   const char *name() const;
   397   void        reset();
   398   const char *iter();
   400   int count() { return _list.count(); }
   402   // Return the "index" entry in the list, zero-based
   403   const char *operator[](int index);
   406   void  dump();                    // output to stderr
   407   void  output(FILE *fp);          // Output list of names to 'fp'
   408 };
   410 //------------------------------ComponentList---------------------------------
   411 // Component lists always have match rule operands first, followed by parameter
   412 // operands which do not appear in the match list (in order of declaration).
   413 class ComponentList : private NameList {
   414 private:
   415   int   _matchcnt;                 // Count of match rule operands
   417 public:
   419   // This is a batch program.  (And I have a destructor bug!)
   420   void operator delete( void *ptr ) {}
   422   void insert(Component *component, bool mflag);
   423   void insert(const char *name, const char *opType, int usedef, bool mflag);
   425   int  count();
   426   int  match_count() { return _matchcnt; } // Get count of match rule opers
   428   Component *iter();               // after reset(), first element : else next
   429   Component *match_iter();         // after reset(), first element : else next
   430   Component *post_match_iter();    // after reset(), first element : else next
   431   void       reset();              // Reset iteration
   432   Component *current();            // return current element in iteration.
   434   // Return element at "position", else NULL
   435   Component *operator[](int position);
   436   Component *at(int position) { return (*this)[position]; }
   438   // Return first component having this name.
   439   const Component *search(const char *name);
   441   // Return number of USEs + number of DEFs
   442   int        num_operands();
   443   // Return zero-based position in list;  -1 if not in list.
   444   int        operand_position(const char *name, int usedef);
   445   // Find position for this name, regardless of use/def information
   446   int        operand_position(const char *name);
   447   // Find position for this name when looked up for output via "format"
   448   int        operand_position_format(const char *name);
   449   // Find position for the Label when looked up for output via "format"
   450   int        label_position();
   451   // Find position for the Method when looked up for output via "format"
   452   int        method_position();
   454   void       dump();               // output to stderr
   455   void       output(FILE *fp);     // Output list of names to 'fp'
   457   ComponentList();
   458   ~ComponentList();
   459 };
   461 //------------------------------SourceForm-------------------------------------
   462 class SourceForm : public Form {
   463 private:
   465 public:
   466   // Public Data
   467   char *_code;                     // Buffer for storing code text
   469   // Public Methods
   470   SourceForm(char* code);
   471   ~SourceForm();
   473   virtual const char* classname() { return "SourceForm"; }
   475   void dump();                    // Debug printer
   476   void output(FILE *fp);          // Write output files
   477 };
   479 class HeaderForm : public SourceForm {
   480 public:
   481   HeaderForm(char* code) : SourceForm(code) { }
   483   virtual const char* classname() { return "HeaderForm"; }
   484 };
   486 class PreHeaderForm : public SourceForm {
   487 public:
   488   PreHeaderForm(char* code) : SourceForm(code) { }
   490   virtual const char* classname() { return "PreHeaderForm"; }
   491 };
   496 //------------------------------Expr------------------------------------------
   497 #define STRING_BUFFER_LENGTH  2048
   498 // class Expr represents integer expressions containing constants and addition
   499 // Value must be in range zero through maximum positive integer. 32bits.
   500 // Expected use: instruction and operand costs
   501 class Expr {
   502 public:
   503   enum {
   504     Zero     = 0,
   505     Max      = 0x7fffffff
   506   };
   507   const char *_external_name;  // if !NULL, then print this instead of _expr
   508   const char *_expr;
   509   int         _min_value;
   510   int         _max_value;
   512   Expr();
   513   Expr(const char *cost);
   514   Expr(const char *name, const char *expression, int min_value, int max_value);
   515   Expr *clone() const;
   517   bool  is_unknown() const { return (this == Expr::get_unknown()); }
   518   bool  is_zero()    const { return (_min_value == Expr::Zero && _max_value == Expr::Zero); }
   519   bool  less_than_or_equal(const Expr *c) const { return (_max_value <= c->_min_value); }
   521   void  add(const Expr *c);
   522   void  add(const char *c);
   523   void  add(const char *c, ArchDesc &AD);   // check if 'c' is defined in <arch>.ad
   524   void  set_external_name(const char *name) { _external_name = name; }
   526   const char *as_string()  const { return (_external_name != NULL ? _external_name : _expr); }
   527   void  print()            const;
   528   void  print_define(FILE *fp) const;
   529   void  print_assert(FILE *fp) const;
   531   static Expr *get_unknown();   // Returns pointer to shared unknown cost instance
   533   static char *buffer()         { return &external_buffer[0]; }
   534   static bool  init_buffers();  // Fill buffers with 0
   535   static bool  check_buffers(); // if buffer use may have overflowed, assert
   537 private:
   538   static Expr *_unknown_expr;
   539   static char string_buffer[STRING_BUFFER_LENGTH];
   540   static char external_buffer[STRING_BUFFER_LENGTH];
   541   static bool _init_buffers;
   542   const char *compute_expr(const Expr *c1, const Expr *c2);  // cost as string after adding 'c1' and 'c2'
   543   int         compute_min (const Expr *c1, const Expr *c2);  // minimum after adding 'c1' and 'c2'
   544   int         compute_max (const Expr *c1, const Expr *c2);  // maximum after adding 'c1' and 'c2'
   545   const char *compute_external(const Expr *c1, const Expr *c2);  // external name after adding 'c1' and 'c2'
   546 };
   548 //------------------------------ExprDict---------------------------------------
   549 // Dictionary containing Exprs
   550 class ExprDict {
   551 private:
   552   Dict         _expr;              // map names, char*, to their Expr* or NULL
   553   NameList     _defines;           // record the order of definitions entered with define call
   555   // Disable public use of constructor, copy-ctor, operator =, operator ==
   556   ExprDict( );
   557   ExprDict( const ExprDict & );    // Deep-copy guts
   558   ExprDict &operator =( const ExprDict & );
   559   // == compares two dictionaries; they must have the same keys (their keys
   560   // must match using CmpKey) and they must have the same values (pointer
   561   // comparison).  If so 1 is returned, if not 0 is returned.
   562   bool operator ==(const ExprDict &d) const; // Compare dictionaries for equal
   564 public:
   565   // cmp is a key comparision routine.  hash is a routine to hash a key.
   566   ExprDict( CmpKey cmp, Hash hash, Arena *arena );
   567   ~ExprDict();
   569   // Return # of key-value pairs in dict
   570   int Size(void) const;
   572   // define inserts the given key-value pair into the dictionary,
   573   // and records the name in order for later output, ...
   574   const Expr  *define(const char *name, Expr *expr);
   576   // Insert inserts the given key-value pair into the dictionary.  The prior
   577   // value of the key is returned; NULL if the key was not previously defined.
   578   const Expr  *Insert(const char *name, Expr *expr); // A new key-value
   580   // Find finds the value of a given key; or NULL if not found.
   581   // The dictionary is NOT changed.
   582   const Expr  *operator [](const char *name) const;  // Do a lookup
   584   void print_defines(FILE *fp);
   585   void print_asserts(FILE *fp);
   586   void dump();
   587 };

mercurial