Path: blob/master/src/hotspot/share/adlc/forms.cpp
41145 views
/*1* Copyright (c) 1997, 2012, 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// FORMS.CPP - Definitions for ADL Parser Generic & Utility Forms Classes25#include "adlc.hpp"2627//------------------------------Static Initializers----------------------------28// allocate arena used by forms29Arena *Form::arena = Form::generate_arena(); // = Form::generate_arena();30Arena *Form::generate_arena() {31return (new Arena);32}3334//------------------------------NameList---------------------------------------35// reserved user-defined string36const char *NameList::_signal = "$$SIGNAL$$";37const char *NameList::_signal2 = "$$SIGNAL2$$";38const char *NameList::_signal3 = "$$SIGNAL3$$";3940// Constructor and Destructor41NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {42_names = (const char**) AllocateHeap(_max*sizeof(char*));43}44NameList::~NameList() {45// The following free is a double-free, and crashes the program:46//free(_names); // not owner of strings47}4849void NameList::addName(const char *name) {50if (_cur == _max) {51_names = (const char**) ReAllocateHeap(_names, (_max *=2)*sizeof(char*));52}53_names[_cur++] = name;54}5556void NameList::add_signal() {57addName( _signal );58}59void NameList::clear() {60_cur = 0;61_iter = 0;62_justReset = true;63// _max = 4; Already allocated64}6566int NameList::count() const { return _cur; }6768void NameList::reset() { _iter = 0; _justReset = true;}69const char *NameList::iter() {70if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}71else return (_iter <_cur-1 ? _names[++_iter] : NULL);72}73const char *NameList::current() { return (_iter < _cur ? _names[_iter] : NULL); }74const char *NameList::peek(int skip) { return (_iter + skip < _cur ? _names[_iter + skip] : NULL); }7576// Return 'true' if current entry is signal77bool NameList::current_is_signal() {78const char *entry = current();79return is_signal(entry);80}8182// Return true if entry is a signal83bool NameList::is_signal(const char *entry) {84return ( (strcmp(entry,NameList::_signal) == 0) ? true : false);85}8687// Search for a name in the list88bool NameList::search(const char *name) {89const char *entry;90for(reset(); (entry = iter()) != NULL; ) {91if(!strcmp(entry,name)) return true;92}93return false;94}9596// Return index of name in list97int NameList::index(const char *name) {98int cnt = 0;99const char *entry;100for(reset(); (entry = iter()) != NULL; ) {101if(!strcmp(entry,name)) return cnt;102cnt++;103}104return Not_in_list;105}106107// Return name at index in list108const char *NameList::name(intptr_t index) {109return ( index < _cur ? _names[index] : NULL);110}111112void NameList::dump() { output(stderr); }113114void NameList::output(FILE *fp) {115fprintf(fp, "\n");116117// Run iteration over all entries, independent of position of iterator.118const char *name = NULL;119int iter = 0;120bool justReset = true;121122while( ( name = (justReset ?123(justReset=false, (iter < _cur ? _names[iter] : NULL)) :124(iter < _cur-1 ? _names[++iter] : NULL)) )125!= NULL ) {126fprintf( fp, " %s,\n", name);127}128fprintf(fp, "\n");129}130131//------------------------------NameAndList------------------------------------132// Storage for a name and an associated list of names133NameAndList::NameAndList(char *name) : _name(name) {134}135NameAndList::~NameAndList() {136}137138// Add to entries in list139void NameAndList::add_entry(const char *entry) {140_list.addName(entry);141}142143// Access the name and its associated list.144const char *NameAndList::name() const { return _name; }145void NameAndList::reset() { _list.reset(); }146const char *NameAndList::iter() { return _list.iter(); }147148// Return the "index" entry in the list, zero-based149const char *NameAndList::operator[](int index) {150assert( index >= 0, "Internal Error(): index less than 0.");151152_list.reset();153const char *entry = _list.iter();154// Iterate further if it isn't at index 0.155for ( int position = 0; position != index; ++position ) {156entry = _list.iter();157}158159return entry;160}161162163void NameAndList::dump() { output(stderr); }164void NameAndList::output(FILE *fp) {165fprintf(fp, "\n");166167// Output the Name168fprintf(fp, "Name == %s", (_name ? _name : "") );169170// Output the associated list of names171const char *name;172fprintf(fp, " (");173for (reset(); (name = iter()) != NULL;) {174fprintf(fp, " %s,\n", name);175}176fprintf(fp, ")");177fprintf(fp, "\n");178}179180//------------------------------Form-------------------------------------------181OpClassForm *Form::is_opclass() const {182return NULL;183}184185OperandForm *Form::is_operand() const {186return NULL;187}188189InstructForm *Form::is_instruction() const {190return NULL;191}192193MachNodeForm *Form::is_machnode() const {194return NULL;195}196197AttributeForm *Form::is_attribute() const {198return NULL;199}200201Effect *Form::is_effect() const {202return NULL;203}204205ResourceForm *Form::is_resource() const {206return NULL;207}208209PipeClassForm *Form::is_pipeclass() const {210return NULL;211}212213Form::DataType Form::ideal_to_const_type(const char *name) const {214if( name == NULL ) { return Form::none; }215216if (strcmp(name,"ConI")==0) return Form::idealI;217if (strcmp(name,"ConP")==0) return Form::idealP;218if (strcmp(name,"ConN")==0) return Form::idealN;219if (strcmp(name,"ConNKlass")==0) return Form::idealNKlass;220if (strcmp(name,"ConL")==0) return Form::idealL;221if (strcmp(name,"ConF")==0) return Form::idealF;222if (strcmp(name,"ConD")==0) return Form::idealD;223if (strcmp(name,"Bool")==0) return Form::idealI;224225return Form::none;226}227228Form::DataType Form::ideal_to_sReg_type(const char *name) const {229if( name == NULL ) { return Form::none; }230231if (strcmp(name,"sRegI")==0) return Form::idealI;232if (strcmp(name,"sRegP")==0) return Form::idealP;233if (strcmp(name,"sRegF")==0) return Form::idealF;234if (strcmp(name,"sRegD")==0) return Form::idealD;235if (strcmp(name,"sRegL")==0) return Form::idealL;236return Form::none;237}238239Form::DataType Form::ideal_to_Reg_type(const char *name) const {240if( name == NULL ) { return Form::none; }241242if (strcmp(name,"RegI")==0) return Form::idealI;243if (strcmp(name,"RegP")==0) return Form::idealP;244if (strcmp(name,"RegF")==0) return Form::idealF;245if (strcmp(name,"RegD")==0) return Form::idealD;246if (strcmp(name,"RegL")==0) return Form::idealL;247248return Form::none;249}250251// True if 'opType', an ideal name, loads or stores.252Form::DataType Form::is_load_from_memory(const char *opType) const {253if( strcmp(opType,"LoadB")==0 ) return Form::idealB;254if( strcmp(opType,"LoadUB")==0 ) return Form::idealB;255if( strcmp(opType,"LoadUS")==0 ) return Form::idealC;256if( strcmp(opType,"LoadD")==0 ) return Form::idealD;257if( strcmp(opType,"LoadD_unaligned")==0 ) return Form::idealD;258if( strcmp(opType,"LoadF")==0 ) return Form::idealF;259if( strcmp(opType,"LoadI")==0 ) return Form::idealI;260if( strcmp(opType,"LoadKlass")==0 ) return Form::idealP;261if( strcmp(opType,"LoadNKlass")==0 ) return Form::idealNKlass;262if( strcmp(opType,"LoadL")==0 ) return Form::idealL;263if( strcmp(opType,"LoadL_unaligned")==0 ) return Form::idealL;264if( strcmp(opType,"LoadPLocked")==0 ) return Form::idealP;265if( strcmp(opType,"LoadP")==0 ) return Form::idealP;266if( strcmp(opType,"LoadN")==0 ) return Form::idealN;267if( strcmp(opType,"LoadRange")==0 ) return Form::idealI;268if( strcmp(opType,"LoadS")==0 ) return Form::idealS;269if( strcmp(opType,"LoadVector")==0 ) return Form::idealV;270if( strcmp(opType,"LoadVectorGather")==0 ) return Form::idealV;271if( strcmp(opType,"LoadVectorMasked")==0 ) return Form::idealV;272assert( strcmp(opType,"Load") != 0, "Must type Loads" );273return Form::none;274}275276Form::DataType Form::is_store_to_memory(const char *opType) const {277if( strcmp(opType,"StoreB")==0) return Form::idealB;278if( strcmp(opType,"StoreCM")==0) return Form::idealB;279if( strcmp(opType,"StoreC")==0) return Form::idealC;280if( strcmp(opType,"StoreD")==0) return Form::idealD;281if( strcmp(opType,"StoreF")==0) return Form::idealF;282if( strcmp(opType,"StoreI")==0) return Form::idealI;283if( strcmp(opType,"StoreL")==0) return Form::idealL;284if( strcmp(opType,"StoreP")==0) return Form::idealP;285if( strcmp(opType,"StoreN")==0) return Form::idealN;286if( strcmp(opType,"StoreNKlass")==0) return Form::idealNKlass;287if( strcmp(opType,"StoreVector")==0 ) return Form::idealV;288if( strcmp(opType,"StoreVectorScatter")==0 ) return Form::idealV;289if( strcmp(opType,"StoreVectorMasked")==0 ) return Form::idealV;290assert( strcmp(opType,"Store") != 0, "Must type Stores" );291return Form::none;292}293294Form::InterfaceType Form::interface_type(FormDict &globals) const {295return Form::no_interface;296}297298//------------------------------FormList---------------------------------------299// Destructor300FormList::~FormList() {301// // This list may not own its elements302// Form *cur = _root;303// Form *next = NULL;304// for( ; (cur = next) != NULL; ) {305// next = (Form *)cur->_next;306// delete cur;307// }308};309310//------------------------------FormDict---------------------------------------311// Constructor312FormDict::FormDict( CmpKey cmp, Hash hash, Arena *arena )313: _form(cmp, hash, arena) {314}315FormDict::~FormDict() {316}317318// Return # of name-Form pairs in dict319int FormDict::Size(void) const {320return _form.Size();321}322323// Insert inserts the given key-value pair into the dictionary. The prior324// value of the key is returned; NULL if the key was not previously defined.325const Form *FormDict::Insert(const char *name, Form *form) {326return (Form*)_form.Insert((void*)name, (void*)form);327}328329// Finds the value of a given key; or NULL if not found.330// The dictionary is NOT changed.331const Form *FormDict::operator [](const char *name) const {332return (Form*)_form[name];333}334335//------------------------------FormDict::private------------------------------336// Disable public use of constructor, copy-ctor, operator =, operator ==337FormDict::FormDict( ) : _form(cmpkey,hashkey) {338assert( false, "NotImplemented");339}340FormDict::FormDict( const FormDict & fd) : _form(fd._form) {341}342FormDict &FormDict::operator =( const FormDict &rhs) {343assert( false, "NotImplemented");344_form = rhs._form;345return *this;346}347// == compares two dictionaries; they must have the same keys (their keys348// must match using CmpKey) and they must have the same values (pointer349// comparison). If so 1 is returned, if not 0 is returned.350bool FormDict::operator ==(const FormDict &d) const {351assert( false, "NotImplemented");352return false;353}354355// Print out the dictionary contents as key-value pairs356static void dumpkey (const void* key) { fprintf(stdout, "%s", (char*) key); }357static void dumpform(const void* form) { fflush(stdout); ((Form*)form)->dump(); }358359void FormDict::dump() {360_form.print(dumpkey, dumpform);361}362363//------------------------------SourceForm-------------------------------------364SourceForm::SourceForm(char* code) : _code(code) { }; // Constructor365SourceForm::~SourceForm() {366}367368void SourceForm::dump() { // Debug printer369output(stderr);370}371372void SourceForm::output(FILE *fp) {373fprintf(fp,"\n//%s\n%s\n",classname(),(_code?_code:""));374}375376377