Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/forms.cpp
32285 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**)malloc(_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) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));51_names[_cur++] = name;52}5354void NameList::add_signal() {55addName( _signal );56}57void NameList::clear() {58_cur = 0;59_iter = 0;60_justReset = true;61// _max = 4; Already allocated62}6364int NameList::count() const { return _cur; }6566void NameList::reset() { _iter = 0; _justReset = true;}67const char *NameList::iter() {68if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}69else return (_iter <_cur-1 ? _names[++_iter] : NULL);70}71const char *NameList::current() { return (_iter < _cur ? _names[_iter] : NULL); }72const char *NameList::peek(int skip) { return (_iter + skip < _cur ? _names[_iter + skip] : NULL); }7374// Return 'true' if current entry is signal75bool NameList::current_is_signal() {76const char *entry = current();77return is_signal(entry);78}7980// Return true if entry is a signal81bool NameList::is_signal(const char *entry) {82return ( (strcmp(entry,NameList::_signal) == 0) ? true : false);83}8485// Search for a name in the list86bool NameList::search(const char *name) {87const char *entry;88for(reset(); (entry = iter()) != NULL; ) {89if(!strcmp(entry,name)) return true;90}91return false;92}9394// Return index of name in list95int NameList::index(const char *name) {96int cnt = 0;97const char *entry;98for(reset(); (entry = iter()) != NULL; ) {99if(!strcmp(entry,name)) return cnt;100cnt++;101}102return Not_in_list;103}104105// Return name at index in list106const char *NameList::name(intptr_t index) {107return ( index < _cur ? _names[index] : NULL);108}109110void NameList::dump() { output(stderr); }111112void NameList::output(FILE *fp) {113fprintf(fp, "\n");114115// Run iteration over all entries, independent of position of iterator.116const char *name = NULL;117int iter = 0;118bool justReset = true;119120while( ( name = (justReset ?121(justReset=false, (iter < _cur ? _names[iter] : NULL)) :122(iter < _cur-1 ? _names[++iter] : NULL)) )123!= NULL ) {124fprintf( fp, " %s,\n", name);125}126fprintf(fp, "\n");127}128129//------------------------------NameAndList------------------------------------130// Storage for a name and an associated list of names131NameAndList::NameAndList(char *name) : _name(name) {132}133NameAndList::~NameAndList() {134}135136// Add to entries in list137void NameAndList::add_entry(const char *entry) {138_list.addName(entry);139}140141// Access the name and its associated list.142const char *NameAndList::name() const { return _name; }143void NameAndList::reset() { _list.reset(); }144const char *NameAndList::iter() { return _list.iter(); }145146// Return the "index" entry in the list, zero-based147const char *NameAndList::operator[](int index) {148assert( index >= 0, "Internal Error(): index less than 0.");149150_list.reset();151const char *entry = _list.iter();152// Iterate further if it isn't at index 0.153for ( int position = 0; position != index; ++position ) {154entry = _list.iter();155}156157return entry;158}159160161void NameAndList::dump() { output(stderr); }162void NameAndList::output(FILE *fp) {163fprintf(fp, "\n");164165// Output the Name166fprintf(fp, "Name == %s", (_name ? _name : "") );167168// Output the associated list of names169const char *name;170fprintf(fp, " (");171for (reset(); (name = iter()) != NULL;) {172fprintf(fp, " %s,\n", name);173}174fprintf(fp, ")");175fprintf(fp, "\n");176}177178//------------------------------Form-------------------------------------------179OpClassForm *Form::is_opclass() const {180return NULL;181}182183OperandForm *Form::is_operand() const {184return NULL;185}186187InstructForm *Form::is_instruction() const {188return NULL;189}190191MachNodeForm *Form::is_machnode() const {192return NULL;193}194195AttributeForm *Form::is_attribute() const {196return NULL;197}198199Effect *Form::is_effect() const {200return NULL;201}202203ResourceForm *Form::is_resource() const {204return NULL;205}206207PipeClassForm *Form::is_pipeclass() const {208return NULL;209}210211Form::DataType Form::ideal_to_const_type(const char *name) const {212if( name == NULL ) { return Form::none; }213214if (strcmp(name,"ConI")==0) return Form::idealI;215if (strcmp(name,"ConP")==0) return Form::idealP;216if (strcmp(name,"ConN")==0) return Form::idealN;217if (strcmp(name,"ConNKlass")==0) return Form::idealNKlass;218if (strcmp(name,"ConL")==0) return Form::idealL;219if (strcmp(name,"ConF")==0) return Form::idealF;220if (strcmp(name,"ConD")==0) return Form::idealD;221if (strcmp(name,"Bool")==0) return Form::idealI;222223return Form::none;224}225226Form::DataType Form::ideal_to_sReg_type(const char *name) const {227if( name == NULL ) { return Form::none; }228229if (strcmp(name,"sRegI")==0) return Form::idealI;230if (strcmp(name,"sRegP")==0) return Form::idealP;231if (strcmp(name,"sRegF")==0) return Form::idealF;232if (strcmp(name,"sRegD")==0) return Form::idealD;233if (strcmp(name,"sRegL")==0) return Form::idealL;234return Form::none;235}236237Form::DataType Form::ideal_to_Reg_type(const char *name) const {238if( name == NULL ) { return Form::none; }239240if (strcmp(name,"RegI")==0) return Form::idealI;241if (strcmp(name,"RegP")==0) return Form::idealP;242if (strcmp(name,"RegF")==0) return Form::idealF;243if (strcmp(name,"RegD")==0) return Form::idealD;244if (strcmp(name,"RegL")==0) return Form::idealL;245246return Form::none;247}248249// True if 'opType', an ideal name, loads or stores.250Form::DataType Form::is_load_from_memory(const char *opType) const {251if( strcmp(opType,"LoadB")==0 ) return Form::idealB;252if( strcmp(opType,"LoadUB")==0 ) return Form::idealB;253if( strcmp(opType,"LoadUS")==0 ) return Form::idealC;254if( strcmp(opType,"LoadD")==0 ) return Form::idealD;255if( strcmp(opType,"LoadD_unaligned")==0 ) return Form::idealD;256if( strcmp(opType,"LoadF")==0 ) return Form::idealF;257if( strcmp(opType,"LoadI")==0 ) return Form::idealI;258if( strcmp(opType,"LoadKlass")==0 ) return Form::idealP;259if( strcmp(opType,"LoadNKlass")==0 ) return Form::idealNKlass;260if( strcmp(opType,"LoadL")==0 ) return Form::idealL;261if( strcmp(opType,"LoadL_unaligned")==0 ) return Form::idealL;262if( strcmp(opType,"LoadPLocked")==0 ) return Form::idealP;263if( strcmp(opType,"LoadP")==0 ) return Form::idealP;264if( strcmp(opType,"LoadN")==0 ) return Form::idealN;265if( strcmp(opType,"LoadRange")==0 ) return Form::idealI;266if( strcmp(opType,"LoadS")==0 ) return Form::idealS;267if( strcmp(opType,"LoadVector")==0 ) return Form::idealV;268assert( strcmp(opType,"Load") != 0, "Must type Loads" );269return Form::none;270}271272Form::DataType Form::is_store_to_memory(const char *opType) const {273if( strcmp(opType,"StoreB")==0) return Form::idealB;274if( strcmp(opType,"StoreCM")==0) return Form::idealB;275if( strcmp(opType,"StoreC")==0) return Form::idealC;276if( strcmp(opType,"StoreD")==0) return Form::idealD;277if( strcmp(opType,"StoreF")==0) return Form::idealF;278if( strcmp(opType,"StoreI")==0) return Form::idealI;279if( strcmp(opType,"StoreL")==0) return Form::idealL;280if( strcmp(opType,"StoreP")==0) return Form::idealP;281if( strcmp(opType,"StoreN")==0) return Form::idealN;282if( strcmp(opType,"StoreNKlass")==0) return Form::idealNKlass;283if( strcmp(opType,"StoreVector")==0 ) return Form::idealV;284assert( strcmp(opType,"Store") != 0, "Must type Stores" );285return Form::none;286}287288Form::InterfaceType Form::interface_type(FormDict &globals) const {289return Form::no_interface;290}291292//------------------------------FormList---------------------------------------293// Destructor294FormList::~FormList() {295// // This list may not own its elements296// Form *cur = _root;297// Form *next = NULL;298// for( ; (cur = next) != NULL; ) {299// next = (Form *)cur->_next;300// delete cur;301// }302};303304//------------------------------FormDict---------------------------------------305// Constructor306FormDict::FormDict( CmpKey cmp, Hash hash, Arena *arena )307: _form(cmp, hash, arena) {308}309FormDict::~FormDict() {310}311312// Return # of name-Form pairs in dict313int FormDict::Size(void) const {314return _form.Size();315}316317// Insert inserts the given key-value pair into the dictionary. The prior318// value of the key is returned; NULL if the key was not previously defined.319const Form *FormDict::Insert(const char *name, Form *form) {320return (Form*)_form.Insert((void*)name, (void*)form);321}322323// Finds the value of a given key; or NULL if not found.324// The dictionary is NOT changed.325const Form *FormDict::operator [](const char *name) const {326return (Form*)_form[name];327}328329//------------------------------FormDict::private------------------------------330// Disable public use of constructor, copy-ctor, operator =, operator ==331FormDict::FormDict( ) : _form(cmpkey,hashkey) {332assert( false, "NotImplemented");333}334FormDict::FormDict( const FormDict & fd) : _form(fd._form) {335}336FormDict &FormDict::operator =( const FormDict &rhs) {337assert( false, "NotImplemented");338_form = rhs._form;339return *this;340}341// == compares two dictionaries; they must have the same keys (their keys342// must match using CmpKey) and they must have the same values (pointer343// comparison). If so 1 is returned, if not 0 is returned.344bool FormDict::operator ==(const FormDict &d) const {345assert( false, "NotImplemented");346return false;347}348349// Print out the dictionary contents as key-value pairs350static void dumpkey (const void* key) { fprintf(stdout, "%s", (char*) key); }351static void dumpform(const void* form) { fflush(stdout); ((Form*)form)->dump(); }352353void FormDict::dump() {354_form.print(dumpkey, dumpform);355}356357//------------------------------SourceForm-------------------------------------358SourceForm::SourceForm(char* code) : _code(code) { }; // Constructor359SourceForm::~SourceForm() {360}361362void SourceForm::dump() { // Debug printer363output(stderr);364}365366void SourceForm::output(FILE *fp) {367fprintf(fp,"\n//%s\n%s\n",classname(),(_code?_code:""));368}369370371