src/share/vm/adlc/forms.cpp

Mon, 09 Mar 2009 03:17:11 -0700

author
twisti
date
Mon, 09 Mar 2009 03:17:11 -0700
changeset 1059
337400e7a5dd
parent 1038
dbbe28fc66b5
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6797305: Add LoadUB and LoadUI opcode class
Summary: Add a LoadUB (unsigned byte) and LoadUI (unsigned int) opcode class so we have these load optimizations in the first place and do not need to handle them in the matcher.
Reviewed-by: never, kvn

     1 /*
     2  * Copyright 1997-2009 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.CPP - Definitions for ADL Parser Generic & Utility Forms Classes
    26 #include "adlc.hpp"
    28 //------------------------------Static Initializers----------------------------
    29 // allocate arena used by forms
    30 Arena  *Form::arena = Form::generate_arena(); //  = Form::generate_arena();
    31 Arena *Form::generate_arena() {
    32   return (new Arena);
    33 }
    35 //------------------------------NameList---------------------------------------
    36 // reserved user-defined string
    37 const char  *NameList::_signal   = "$$SIGNAL$$";
    38 const char  *NameList::_signal2  = "$$SIGNAL2$$";
    39 const char  *NameList::_signal3  = "$$SIGNAL3$$";
    41 // Constructor and Destructor
    42 NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {
    43   _names = (const char**)malloc(_max*sizeof(char*));
    44 }
    45 NameList::~NameList() {
    46   // The following free is a double-free, and crashes the program:
    47   //free(_names);                   // not owner of strings
    48 }
    50 void   NameList::addName(const char *name) {
    51   if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));
    52   _names[_cur++] = name;
    53 }
    55 void   NameList::add_signal() {
    56   addName( _signal );
    57 }
    58 void   NameList::clear() {
    59   _cur   = 0;
    60   _iter  = 0;
    61   _justReset = true;
    62   // _max   = 4; Already allocated
    63 }
    65 int    NameList::count()  const { return _cur; }
    67 void   NameList::reset()   { _iter = 0; _justReset = true;}
    68 const char  *NameList::iter()    {
    69   if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}
    70   else return (_iter <_cur-1 ? _names[++_iter] : NULL);
    71 }
    72 const char  *NameList::current() { return (_iter < _cur ? _names[_iter] : NULL); }
    73 const char  *NameList::peek(int skip) { return (_iter + skip < _cur ? _names[_iter + skip] : NULL); }
    75 // Return 'true' if current entry is signal
    76 bool  NameList::current_is_signal() {
    77   const char *entry = current();
    78   return is_signal(entry);
    79 }
    81 // Return true if entry is a signal
    82 bool  NameList::is_signal(const char *entry) {
    83   return ( (strcmp(entry,NameList::_signal) == 0) ? true : false);
    84 }
    86 // Search for a name in the list
    87 bool   NameList::search(const char *name) {
    88   const char *entry;
    89   for(reset(); (entry = iter()) != NULL; ) {
    90     if(!strcmp(entry,name)) return true;
    91   }
    92   return false;
    93 }
    95 // Return index of name in list
    96 int    NameList::index(const char *name) {
    97   int         cnt = 0;
    98   const char *entry;
    99   for(reset(); (entry = iter()) != NULL; ) {
   100     if(!strcmp(entry,name)) return cnt;
   101     cnt++;
   102   }
   103   return Not_in_list;
   104 }
   106 // Return name at index in list
   107 const char  *NameList::name(intptr_t  index) {
   108   return ( index < _cur ? _names[index] : NULL);
   109 }
   111 void   NameList::dump() { output(stderr); }
   113 void   NameList::output(FILE *fp) {
   114   fprintf(fp, "\n");
   116   // Run iteration over all entries, independent of position of iterator.
   117   const char *name       = NULL;
   118   int         iter       = 0;
   119   bool        justReset  = true;
   121   while( ( name  = (justReset ?
   122                     (justReset=false, (iter < _cur ? _names[iter] : NULL)) :
   123                     (iter < _cur-1 ? _names[++iter] : NULL)) )
   124          != NULL ) {
   125     fprintf( fp, "  %s,\n", name);
   126   }
   127   fprintf(fp, "\n");
   128 }
   130 //------------------------------NameAndList------------------------------------
   131 // Storage for a name and an associated list of names
   132 NameAndList::NameAndList(char *name) : _name(name) {
   133 }
   134 NameAndList::~NameAndList() {
   135 }
   137 // Add to entries in list
   138 void NameAndList::add_entry(const char *entry) {
   139   _list.addName(entry);
   140 }
   142 // Access the name and its associated list.
   143 const char *NameAndList::name()  const {  return _name;  }
   144 void        NameAndList::reset()       { _list.reset();  }
   145 const char *NameAndList::iter()        { return _list.iter(); }
   147 // Return the "index" entry in the list, zero-based
   148 const char *NameAndList::operator[](int index) {
   149   assert( index >= 0, "Internal Error(): index less than 0.");
   151   _list.reset();
   152   const char *entry = _list.iter();
   153   // Iterate further if it isn't at index 0.
   154   for ( int position = 0; position != index; ++position ) {
   155     entry = _list.iter();
   156   }
   158   return entry;
   159 }
   162 void   NameAndList::dump() { output(stderr); }
   163 void   NameAndList::output(FILE *fp) {
   164   fprintf(fp, "\n");
   166   // Output the Name
   167   fprintf(fp, "Name == %s", (_name ? _name : "") );
   169   // Output the associated list of names
   170   const char *name;
   171   fprintf(fp, " (");
   172   for (reset(); (name = iter()) != NULL;) {
   173     fprintf(fp, "  %s,\n", name);
   174   }
   175   fprintf(fp, ")");
   176   fprintf(fp, "\n");
   177 }
   179 //------------------------------Form-------------------------------------------
   180 OpClassForm   *Form::is_opclass()     const {
   181   return NULL;
   182 }
   184 OperandForm   *Form::is_operand()     const {
   185   return NULL;
   186 }
   188 InstructForm  *Form::is_instruction() const {
   189   return NULL;
   190 }
   192 MachNodeForm  *Form::is_machnode() const {
   193   return NULL;
   194 }
   196 AttributeForm *Form::is_attribute() const {
   197   return NULL;
   198 }
   200 Effect        *Form::is_effect() const {
   201   return NULL;
   202 }
   204 ResourceForm  *Form::is_resource() const {
   205   return NULL;
   206 }
   208 PipeClassForm *Form::is_pipeclass() const {
   209   return NULL;
   210 }
   212 Form::DataType Form::ideal_to_const_type(const char *name) const {
   213   if( name == NULL ) { return Form::none; }
   215   if (strcmp(name,"ConI")==0) return Form::idealI;
   216   if (strcmp(name,"ConP")==0) return Form::idealP;
   217   if (strcmp(name,"ConN")==0) return Form::idealN;
   218   if (strcmp(name,"ConL")==0) return Form::idealL;
   219   if (strcmp(name,"ConF")==0) return Form::idealF;
   220   if (strcmp(name,"ConD")==0) return Form::idealD;
   221   if (strcmp(name,"Bool")==0) return Form::idealI;
   223   return Form::none;
   224 }
   226 Form::DataType Form::ideal_to_sReg_type(const char *name) const {
   227   if( name == NULL ) { return Form::none; }
   229   if (strcmp(name,"sRegI")==0) return Form::idealI;
   230   if (strcmp(name,"sRegP")==0) return Form::idealP;
   231   if (strcmp(name,"sRegF")==0) return Form::idealF;
   232   if (strcmp(name,"sRegD")==0) return Form::idealD;
   233   if (strcmp(name,"sRegL")==0) return Form::idealL;
   234   return Form::none;
   235 }
   237 Form::DataType Form::ideal_to_Reg_type(const char *name) const {
   238   if( name == NULL ) { return Form::none; }
   240   if (strcmp(name,"RegI")==0) return Form::idealI;
   241   if (strcmp(name,"RegP")==0) return Form::idealP;
   242   if (strcmp(name,"RegF")==0) return Form::idealF;
   243   if (strcmp(name,"RegD")==0) return Form::idealD;
   244   if (strcmp(name,"RegL")==0) return Form::idealL;
   246   return Form::none;
   247 }
   249 // True if 'opType', an ideal name, loads or stores.
   250 Form::DataType Form::is_load_from_memory(const char *opType) const {
   251   if( strcmp(opType,"LoadB")==0 )  return Form::idealB;
   252   if( strcmp(opType,"LoadUB")==0 )  return Form::idealB;
   253   if( strcmp(opType,"LoadUS")==0 )  return Form::idealC;
   254   if( strcmp(opType,"LoadD")==0 )  return Form::idealD;
   255   if( strcmp(opType,"LoadD_unaligned")==0 )  return Form::idealD;
   256   if( strcmp(opType,"LoadF")==0 )  return Form::idealF;
   257   if( strcmp(opType,"LoadI")==0 )  return Form::idealI;
   258   if( strcmp(opType,"LoadUI2L")==0 )  return Form::idealI;
   259   if( strcmp(opType,"LoadKlass")==0 )  return Form::idealP;
   260   if( strcmp(opType,"LoadNKlass")==0 ) return Form::idealN;
   261   if( strcmp(opType,"LoadL")==0 )  return Form::idealL;
   262   if( strcmp(opType,"LoadL_unaligned")==0 )  return Form::idealL;
   263   if( strcmp(opType,"LoadPLocked")==0 )  return Form::idealP;
   264   if( strcmp(opType,"LoadLLocked")==0 )  return Form::idealL;
   265   if( strcmp(opType,"LoadP")==0 )  return Form::idealP;
   266   if( strcmp(opType,"LoadN")==0 )  return Form::idealN;
   267   if( strcmp(opType,"LoadRange")==0 )  return Form::idealI;
   268   if( strcmp(opType,"LoadS")==0 )  return Form::idealS;
   269   if( strcmp(opType,"Load16B")==0 )  return Form::idealB;
   270   if( strcmp(opType,"Load8B")==0 )  return Form::idealB;
   271   if( strcmp(opType,"Load4B")==0 )  return Form::idealB;
   272   if( strcmp(opType,"Load8C")==0 )  return Form::idealC;
   273   if( strcmp(opType,"Load4C")==0 )  return Form::idealC;
   274   if( strcmp(opType,"Load2C")==0 )  return Form::idealC;
   275   if( strcmp(opType,"Load8S")==0 )  return Form::idealS;
   276   if( strcmp(opType,"Load4S")==0 )  return Form::idealS;
   277   if( strcmp(opType,"Load2S")==0 )  return Form::idealS;
   278   if( strcmp(opType,"Load2D")==0 )  return Form::idealD;
   279   if( strcmp(opType,"Load4F")==0 )  return Form::idealF;
   280   if( strcmp(opType,"Load2F")==0 )  return Form::idealF;
   281   if( strcmp(opType,"Load4I")==0 )  return Form::idealI;
   282   if( strcmp(opType,"Load2I")==0 )  return Form::idealI;
   283   if( strcmp(opType,"Load2L")==0 )  return Form::idealL;
   284   assert( strcmp(opType,"Load") != 0, "Must type Loads" );
   285   return Form::none;
   286 }
   288 Form::DataType Form::is_store_to_memory(const char *opType) const {
   289   if( strcmp(opType,"StoreB")==0)  return Form::idealB;
   290   if( strcmp(opType,"StoreCM")==0)  return Form::idealB;
   291   if( strcmp(opType,"StoreC")==0)  return Form::idealC;
   292   if( strcmp(opType,"StoreD")==0)  return Form::idealD;
   293   if( strcmp(opType,"StoreF")==0)  return Form::idealF;
   294   if( strcmp(opType,"StoreI")==0)  return Form::idealI;
   295   if( strcmp(opType,"StoreL")==0)  return Form::idealL;
   296   if( strcmp(opType,"StoreP")==0)  return Form::idealP;
   297   if( strcmp(opType,"StoreN")==0) return Form::idealN;
   298   if( strcmp(opType,"Store16B")==0)  return Form::idealB;
   299   if( strcmp(opType,"Store8B")==0)  return Form::idealB;
   300   if( strcmp(opType,"Store4B")==0)  return Form::idealB;
   301   if( strcmp(opType,"Store8C")==0)  return Form::idealC;
   302   if( strcmp(opType,"Store4C")==0)  return Form::idealC;
   303   if( strcmp(opType,"Store2C")==0)  return Form::idealC;
   304   if( strcmp(opType,"Store2D")==0)  return Form::idealD;
   305   if( strcmp(opType,"Store4F")==0)  return Form::idealF;
   306   if( strcmp(opType,"Store2F")==0)  return Form::idealF;
   307   if( strcmp(opType,"Store4I")==0)  return Form::idealI;
   308   if( strcmp(opType,"Store2I")==0)  return Form::idealI;
   309   if( strcmp(opType,"Store2L")==0)  return Form::idealL;
   310   assert( strcmp(opType,"Store") != 0, "Must type Stores" );
   311   return Form::none;
   312 }
   314 Form::InterfaceType Form::interface_type(FormDict &globals) const {
   315   return Form::no_interface;
   316 }
   318 //------------------------------FormList---------------------------------------
   319 // Destructor
   320 FormList::~FormList()  {
   321   // // This list may not own its elements
   322   // Form *cur  = _root;
   323   // Form *next = NULL;
   324   // for( ; (cur = next) != NULL; ) {
   325   //   next = (Form *)cur->_next;
   326   //   delete cur;
   327   // }
   328 };
   330 //------------------------------FormDict---------------------------------------
   331 // Constructor
   332 FormDict::FormDict( CmpKey cmp, Hash hash, Arena *arena )
   333   : _form(cmp, hash, arena) {
   334 }
   335 FormDict::~FormDict() {
   336 }
   338 // Return # of name-Form pairs in dict
   339 int FormDict::Size(void) const {
   340   return _form.Size();
   341 }
   343 // Insert inserts the given key-value pair into the dictionary.  The prior
   344 // value of the key is returned; NULL if the key was not previously defined.
   345 const Form  *FormDict::Insert(const char *name, Form *form) {
   346   return (Form*)_form.Insert((void*)name, (void*)form);
   347 }
   349 // Finds the value of a given key; or NULL if not found.
   350 // The dictionary is NOT changed.
   351 const Form  *FormDict::operator [](const char *name) const {
   352   return (Form*)_form[name];
   353 }
   355 //------------------------------FormDict::private------------------------------
   356 // Disable public use of constructor, copy-ctor, operator =, operator ==
   357 FormDict::FormDict( ) : _form(cmpkey,hashkey) {
   358   assert( false, "NotImplemented");
   359 }
   360 FormDict::FormDict( const FormDict & fd) : _form(fd._form) {
   361 }
   362 FormDict &FormDict::operator =( const FormDict &rhs) {
   363   assert( false, "NotImplemented");
   364   _form = rhs._form;
   365   return *this;
   366 }
   367 // == compares two dictionaries; they must have the same keys (their keys
   368 // must match using CmpKey) and they must have the same values (pointer
   369 // comparison).  If so 1 is returned, if not 0 is returned.
   370 bool FormDict::operator ==(const FormDict &d) const {
   371   assert( false, "NotImplemented");
   372   return false;
   373 }
   375 // Print out the dictionary contents as key-value pairs
   376 static void dumpkey (const void* key)  { fprintf(stdout, "%s", (char*) key); }
   377 static void dumpform(const void* form) { fflush(stdout); ((Form*)form)->dump(); }
   379 void FormDict::dump() {
   380   _form.print(dumpkey, dumpform);
   381 }
   383 //------------------------------SourceForm-------------------------------------
   384 SourceForm::SourceForm(char* code) : _code(code) { }; // Constructor
   385 SourceForm::~SourceForm() {
   386 }
   388 void SourceForm::dump() {                    // Debug printer
   389   output(stderr);
   390 }
   392 void SourceForm::output(FILE *fp) {
   393   fprintf(fp,"\n//%s\n%s\n",classname(),(_code?_code:""));
   394 }

mercurial