Path: blob/master/src/hotspot/share/adlc/output_h.cpp
41144 views
/*1* Copyright (c) 1998, 2020, 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// output_h.cpp - Class HPP file output routines for architecture definition25#include "adlc.hpp"2627// The comment delimiter used in format statements after assembler instructions.28#if defined(PPC64)29#define commentSeperator "\t//"30#else31#define commentSeperator "!"32#endif3334// Generate the #define that describes the number of registers.35static void defineRegCount(FILE *fp, RegisterForm *registers) {36if (registers) {37int regCount = AdlcVMDeps::Physical + registers->_rdefs.count();38fprintf(fp,"\n");39fprintf(fp,"// the number of reserved registers + machine registers.\n");40fprintf(fp,"#define REG_COUNT %d\n", regCount);41}42}4344// Output enumeration of machine register numbers45// (1)46// // Enumerate machine registers starting after reserved regs.47// // in the order of occurrence in the register block.48// enum MachRegisterNumbers {49// EAX_num = 0,50// ...51// _last_Mach_Reg52// }53void ArchDesc::buildMachRegisterNumbers(FILE *fp_hpp) {54if (_register) {55RegDef *reg_def = NULL;5657// Output a #define for the number of machine registers58defineRegCount(fp_hpp, _register);5960// Count all the Save_On_Entry and Always_Save registers61int saved_on_entry = 0;62int c_saved_on_entry = 0;63_register->reset_RegDefs();64while( (reg_def = _register->iter_RegDefs()) != NULL ) {65if( strcmp(reg_def->_callconv,"SOE") == 0 ||66strcmp(reg_def->_callconv,"AS") == 0 ) ++saved_on_entry;67if( strcmp(reg_def->_c_conv,"SOE") == 0 ||68strcmp(reg_def->_c_conv,"AS") == 0 ) ++c_saved_on_entry;69}70fprintf(fp_hpp, "\n");71fprintf(fp_hpp, "// the number of save_on_entry + always_saved registers.\n");72fprintf(fp_hpp, "#define MAX_SAVED_ON_ENTRY_REG_COUNT %d\n", max(saved_on_entry,c_saved_on_entry));73fprintf(fp_hpp, "#define SAVED_ON_ENTRY_REG_COUNT %d\n", saved_on_entry);74fprintf(fp_hpp, "#define C_SAVED_ON_ENTRY_REG_COUNT %d\n", c_saved_on_entry);7576// (1)77// Build definition for enumeration of register numbers78fprintf(fp_hpp, "\n");79fprintf(fp_hpp, "// Enumerate machine register numbers starting after reserved regs.\n");80fprintf(fp_hpp, "// in the order of occurrence in the register block.\n");81fprintf(fp_hpp, "enum MachRegisterNumbers {\n");8283// Output the register number for each register in the allocation classes84_register->reset_RegDefs();85int i = 0;86while( (reg_def = _register->iter_RegDefs()) != NULL ) {87fprintf(fp_hpp," %s_num,", reg_def->_regname);88for (int j = 0; j < 20-(int)strlen(reg_def->_regname); j++) fprintf(fp_hpp, " ");89fprintf(fp_hpp," // enum %3d, regnum %3d, reg encode %3s\n",90i++,91reg_def->register_num(),92reg_def->register_encode());93}94// Finish defining enumeration95fprintf(fp_hpp, " _last_Mach_Reg // %d\n", i);96fprintf(fp_hpp, "};\n");97}9899fprintf(fp_hpp, "\n// Size of register-mask in ints\n");100fprintf(fp_hpp, "#define RM_SIZE %d\n", RegisterForm::RegMask_Size());101fprintf(fp_hpp, "// Unroll factor for loops over the data in a RegMask\n");102fprintf(fp_hpp, "#define FORALL_BODY ");103int len = RegisterForm::RegMask_Size();104for( int i = 0; i < len; i++ )105fprintf(fp_hpp, "BODY(%d) ",i);106fprintf(fp_hpp, "\n\n");107108fprintf(fp_hpp,"class RegMask;\n");109// All RegMasks are declared "extern const ..." in ad_<arch>.hpp110// fprintf(fp_hpp,"extern RegMask STACK_OR_STACK_SLOTS_mask;\n\n");111}112113114// Output enumeration of machine register encodings115// (2)116// // Enumerate machine registers starting after reserved regs.117// // in the order of occurrence in the alloc_class(es).118// enum MachRegisterEncodes {119// EAX_enc = 0x00,120// ...121// }122void ArchDesc::buildMachRegisterEncodes(FILE *fp_hpp) {123if (_register) {124RegDef *reg_def = NULL;125RegDef *reg_def_next = NULL;126127// (2)128// Build definition for enumeration of encode values129fprintf(fp_hpp, "\n");130fprintf(fp_hpp, "// Enumerate machine registers starting after reserved regs.\n");131fprintf(fp_hpp, "// in the order of occurrence in the alloc_class(es).\n");132fprintf(fp_hpp, "enum MachRegisterEncodes {\n");133134// Find max enum string length.135size_t maxlen = 0;136_register->reset_RegDefs();137reg_def = _register->iter_RegDefs();138while (reg_def != NULL) {139size_t len = strlen(reg_def->_regname);140if (len > maxlen) maxlen = len;141reg_def = _register->iter_RegDefs();142}143144// Output the register encoding for each register in the allocation classes145_register->reset_RegDefs();146reg_def_next = _register->iter_RegDefs();147while( (reg_def = reg_def_next) != NULL ) {148reg_def_next = _register->iter_RegDefs();149fprintf(fp_hpp," %s_enc", reg_def->_regname);150for (size_t i = strlen(reg_def->_regname); i < maxlen; i++) fprintf(fp_hpp, " ");151fprintf(fp_hpp," = %3s%s\n", reg_def->register_encode(), reg_def_next == NULL? "" : "," );152}153// Finish defining enumeration154fprintf(fp_hpp, "};\n");155156} // Done with register form157}158159160// Declare an array containing the machine register names, strings.161static void declareRegNames(FILE *fp, RegisterForm *registers) {162if (registers) {163// fprintf(fp,"\n");164// fprintf(fp,"// An array of character pointers to machine register names.\n");165// fprintf(fp,"extern const char *regName[];\n");166}167}168169// Declare an array containing the machine register sizes in 32-bit words.170void ArchDesc::declareRegSizes(FILE *fp) {171// regSize[] is not used172}173174// Declare an array containing the machine register encoding values175static void declareRegEncodes(FILE *fp, RegisterForm *registers) {176if (registers) {177// // //178// fprintf(fp,"\n");179// fprintf(fp,"// An array containing the machine register encode values\n");180// fprintf(fp,"extern const char regEncode[];\n");181}182}183184185// ---------------------------------------------------------------------------186//------------------------------Utilities to build Instruction Classes--------187// ---------------------------------------------------------------------------188static void out_RegMask(FILE *fp) {189fprintf(fp," virtual const RegMask &out_RegMask() const;\n");190}191192// ---------------------------------------------------------------------------193//--------Utilities to build MachOper and MachNode derived Classes------------194// ---------------------------------------------------------------------------195196//------------------------------Utilities to build Operand Classes------------197static void in_RegMask(FILE *fp) {198fprintf(fp," virtual const RegMask *in_RegMask(int index) const;\n");199}200201static void declareConstStorage(FILE *fp, FormDict &globals, OperandForm *oper) {202int i = 0;203Component *comp;204205if (oper->num_consts(globals) == 0) return;206// Iterate over the component list looking for constants207oper->_components.reset();208if ((comp = oper->_components.iter()) == NULL) {209assert(oper->num_consts(globals) == 1, "Bad component list detected.\n");210const char *type = oper->ideal_type(globals);211if (!strcmp(type, "ConI")) {212if (i > 0) fprintf(fp,", ");213fprintf(fp," int32_t _c%d;\n", i);214}215else if (!strcmp(type, "ConP")) {216if (i > 0) fprintf(fp,", ");217fprintf(fp," const TypePtr *_c%d;\n", i);218}219else if (!strcmp(type, "ConN")) {220if (i > 0) fprintf(fp,", ");221fprintf(fp," const TypeNarrowOop *_c%d;\n", i);222}223else if (!strcmp(type, "ConNKlass")) {224if (i > 0) fprintf(fp,", ");225fprintf(fp," const TypeNarrowKlass *_c%d;\n", i);226}227else if (!strcmp(type, "ConL")) {228if (i > 0) fprintf(fp,", ");229fprintf(fp," jlong _c%d;\n", i);230}231else if (!strcmp(type, "ConF")) {232if (i > 0) fprintf(fp,", ");233fprintf(fp," jfloat _c%d;\n", i);234}235else if (!strcmp(type, "ConD")) {236if (i > 0) fprintf(fp,", ");237fprintf(fp," jdouble _c%d;\n", i);238}239else if (!strcmp(type, "Bool")) {240fprintf(fp,"private:\n");241fprintf(fp," BoolTest::mask _c%d;\n", i);242fprintf(fp,"public:\n");243}244else {245assert(0, "Non-constant operand lacks component list.");246}247} // end if NULL248else {249oper->_components.reset();250while ((comp = oper->_components.iter()) != NULL) {251if (!strcmp(comp->base_type(globals), "ConI")) {252fprintf(fp," jint _c%d;\n", i);253i++;254}255else if (!strcmp(comp->base_type(globals), "ConP")) {256fprintf(fp," const TypePtr *_c%d;\n", i);257i++;258}259else if (!strcmp(comp->base_type(globals), "ConN")) {260fprintf(fp," const TypePtr *_c%d;\n", i);261i++;262}263else if (!strcmp(comp->base_type(globals), "ConNKlass")) {264fprintf(fp," const TypePtr *_c%d;\n", i);265i++;266}267else if (!strcmp(comp->base_type(globals), "ConL")) {268fprintf(fp," jlong _c%d;\n", i);269i++;270}271else if (!strcmp(comp->base_type(globals), "ConF")) {272fprintf(fp," jfloat _c%d;\n", i);273i++;274}275else if (!strcmp(comp->base_type(globals), "ConD")) {276fprintf(fp," jdouble _c%d;\n", i);277i++;278}279}280}281}282283// Declare constructor.284// Parameters start with condition code, then all other constants285//286// (0) public:287// (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)288// (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }289//290static void defineConstructor(FILE *fp, const char *name, uint num_consts,291ComponentList &lst, bool is_ideal_bool,292Form::DataType constant_type, FormDict &globals) {293fprintf(fp,"public:\n");294// generate line (1)295fprintf(fp," %sOper(", name);296if( num_consts == 0 ) {297fprintf(fp,") {}\n");298return;299}300301// generate parameters for constants302uint i = 0;303Component *comp;304lst.reset();305if ((comp = lst.iter()) == NULL) {306assert(num_consts == 1, "Bad component list detected.\n");307switch( constant_type ) {308case Form::idealI : {309fprintf(fp,is_ideal_bool ? "BoolTest::mask c%d" : "int32_t c%d", i);310break;311}312case Form::idealN : { fprintf(fp,"const TypeNarrowOop *c%d", i); break; }313case Form::idealNKlass : { fprintf(fp,"const TypeNarrowKlass *c%d", i); break; }314case Form::idealP : { fprintf(fp,"const TypePtr *c%d", i); break; }315case Form::idealL : { fprintf(fp,"jlong c%d", i); break; }316case Form::idealF : { fprintf(fp,"jfloat c%d", i); break; }317case Form::idealD : { fprintf(fp,"jdouble c%d", i); break; }318default:319assert(!is_ideal_bool, "Non-constant operand lacks component list.");320break;321}322} // end if NULL323else {324lst.reset();325while((comp = lst.iter()) != NULL) {326if (!strcmp(comp->base_type(globals), "ConI")) {327if (i > 0) fprintf(fp,", ");328fprintf(fp,"int32_t c%d", i);329i++;330}331else if (!strcmp(comp->base_type(globals), "ConP")) {332if (i > 0) fprintf(fp,", ");333fprintf(fp,"const TypePtr *c%d", i);334i++;335}336else if (!strcmp(comp->base_type(globals), "ConN")) {337if (i > 0) fprintf(fp,", ");338fprintf(fp,"const TypePtr *c%d", i);339i++;340}341else if (!strcmp(comp->base_type(globals), "ConNKlass")) {342if (i > 0) fprintf(fp,", ");343fprintf(fp,"const TypePtr *c%d", i);344i++;345}346else if (!strcmp(comp->base_type(globals), "ConL")) {347if (i > 0) fprintf(fp,", ");348fprintf(fp,"jlong c%d", i);349i++;350}351else if (!strcmp(comp->base_type(globals), "ConF")) {352if (i > 0) fprintf(fp,", ");353fprintf(fp,"jfloat c%d", i);354i++;355}356else if (!strcmp(comp->base_type(globals), "ConD")) {357if (i > 0) fprintf(fp,", ");358fprintf(fp,"jdouble c%d", i);359i++;360}361else if (!strcmp(comp->base_type(globals), "Bool")) {362if (i > 0) fprintf(fp,", ");363fprintf(fp,"BoolTest::mask c%d", i);364i++;365}366}367}368// finish line (1) and start line (2)369fprintf(fp,") : ");370// generate initializers for constants371i = 0;372fprintf(fp,"_c%d(c%d)", i, i);373for( i = 1; i < num_consts; ++i) {374fprintf(fp,", _c%d(c%d)", i, i);375}376// The body for the constructor is empty377fprintf(fp," {}\n");378}379380// ---------------------------------------------------------------------------381// Utilities to generate format rules for machine operands and instructions382// ---------------------------------------------------------------------------383384// Generate the format rule for condition codes385static void defineCCodeDump(OperandForm* oper, FILE *fp, int i) {386assert(oper != NULL, "what");387CondInterface* cond = oper->_interface->is_CondInterface();388fprintf(fp, " if( _c%d == BoolTest::eq ) st->print_raw(\"%s\");\n",i,cond->_equal_format);389fprintf(fp, " else if( _c%d == BoolTest::ne ) st->print_raw(\"%s\");\n",i,cond->_not_equal_format);390fprintf(fp, " else if( _c%d == BoolTest::le ) st->print_raw(\"%s\");\n",i,cond->_less_equal_format);391fprintf(fp, " else if( _c%d == BoolTest::ge ) st->print_raw(\"%s\");\n",i,cond->_greater_equal_format);392fprintf(fp, " else if( _c%d == BoolTest::lt ) st->print_raw(\"%s\");\n",i,cond->_less_format);393fprintf(fp, " else if( _c%d == BoolTest::gt ) st->print_raw(\"%s\");\n",i,cond->_greater_format);394fprintf(fp, " else if( _c%d == BoolTest::overflow ) st->print_raw(\"%s\");\n",i,cond->_overflow_format);395fprintf(fp, " else if( _c%d == BoolTest::no_overflow ) st->print_raw(\"%s\");\n",i,cond->_no_overflow_format);396}397398// Output code that dumps constant values, increment "i" if type is constant399static uint dump_spec_constant(FILE *fp, const char *ideal_type, uint i, OperandForm* oper) {400if (!strcmp(ideal_type, "ConI")) {401fprintf(fp," st->print(\"#%%d\", _c%d);\n", i);402fprintf(fp," st->print(\"/0x%%08x\", _c%d);\n", i);403++i;404}405else if (!strcmp(ideal_type, "ConP")) {406fprintf(fp," _c%d->dump_on(st);\n", i);407++i;408}409else if (!strcmp(ideal_type, "ConN")) {410fprintf(fp," _c%d->dump_on(st);\n", i);411++i;412}413else if (!strcmp(ideal_type, "ConNKlass")) {414fprintf(fp," _c%d->dump_on(st);\n", i);415++i;416}417else if (!strcmp(ideal_type, "ConL")) {418fprintf(fp," st->print(\"#\" INT64_FORMAT, (int64_t)_c%d);\n", i);419fprintf(fp," st->print(\"/\" PTR64_FORMAT, (uint64_t)_c%d);\n", i);420++i;421}422else if (!strcmp(ideal_type, "ConF")) {423fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);424fprintf(fp," jint _c%di = JavaValue(_c%d).get_jint();\n", i, i);425fprintf(fp," st->print(\"/0x%%x/\", _c%di);\n", i);426++i;427}428else if (!strcmp(ideal_type, "ConD")) {429fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);430fprintf(fp," jlong _c%dl = JavaValue(_c%d).get_jlong();\n", i, i);431fprintf(fp," st->print(\"/\" PTR64_FORMAT, (uint64_t)_c%dl);\n", i);432++i;433}434else if (!strcmp(ideal_type, "Bool")) {435defineCCodeDump(oper, fp,i);436++i;437}438439return i;440}441442// Generate the format rule for an operand443void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) {444if (!for_c_file) {445// invoked after output #ifndef PRODUCT to ad_<arch>.hpp446// compile the bodies separately, to cut down on recompilations447fprintf(fp," virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n");448fprintf(fp," virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n");449return;450}451452// Local pointer indicates remaining part of format rule453int idx = 0; // position of operand in match rule454455// Generate internal format function, used when stored locally456fprintf(fp, "\n#ifndef PRODUCT\n");457fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident);458// Generate the user-defined portion of the format459if (oper._format) {460if ( oper._format->_strings.count() != 0 ) {461// No initialization code for int_format462463// Build the format from the entries in strings and rep_vars464const char *string = NULL;465oper._format->_rep_vars.reset();466oper._format->_strings.reset();467while ( (string = oper._format->_strings.iter()) != NULL ) {468469// Check if this is a standard string or a replacement variable470if ( string != NameList::_signal ) {471// Normal string472// Pass through to st->print473fprintf(fp," st->print_raw(\"%s\");\n", string);474} else {475// Replacement variable476const char *rep_var = oper._format->_rep_vars.iter();477// Check that it is a local name, and an operand478const Form* form = oper._localNames[rep_var];479if (form == NULL) {480globalAD->syntax_err(oper._linenum,481"\'%s\' not found in format for %s\n", rep_var, oper._ident);482assert(form, "replacement variable was not found in local names");483}484OperandForm *op = form->is_operand();485// Get index if register or constant486if ( op->_matrule && op->_matrule->is_base_register(globals) ) {487idx = oper.register_position( globals, rep_var);488}489else if (op->_matrule && op->_matrule->is_base_constant(globals)) {490idx = oper.constant_position( globals, rep_var);491} else {492idx = 0;493}494495// output invocation of "$..."s format function496if ( op != NULL ) op->int_format(fp, globals, idx);497498if ( idx == -1 ) {499fprintf(stderr,500"Using a name, %s, that isn't in match rule\n", rep_var);501assert( strcmp(op->_ident,"label")==0, "Unimplemented");502}503} // Done with a replacement variable504} // Done with all format strings505} else {506// Default formats for base operands (RegI, RegP, ConI, ConP, ...)507oper.int_format(fp, globals, 0);508}509510} else { // oper._format == NULL511// Provide a few special case formats where the AD writer cannot.512if ( strcmp(oper._ident,"Universe")==0 ) {513fprintf(fp, " st->print(\"$$univ\");\n");514}515// labelOper::int_format is defined in ad_<...>.cpp516}517// ALWAYS! Provide a special case output for condition codes.518if( oper.is_ideal_bool() ) {519defineCCodeDump(&oper, fp,0);520}521fprintf(fp,"}\n");522523// Generate external format function, when data is stored externally524fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident);525// Generate the user-defined portion of the format526if (oper._format) {527if ( oper._format->_strings.count() != 0 ) {528529// Check for a replacement string "$..."530if ( oper._format->_rep_vars.count() != 0 ) {531// Initialization code for ext_format532}533534// Build the format from the entries in strings and rep_vars535const char *string = NULL;536oper._format->_rep_vars.reset();537oper._format->_strings.reset();538while ( (string = oper._format->_strings.iter()) != NULL ) {539540// Check if this is a standard string or a replacement variable541if ( string != NameList::_signal ) {542// Normal string543// Pass through to st->print544fprintf(fp," st->print_raw(\"%s\");\n", string);545} else {546// Replacement variable547const char *rep_var = oper._format->_rep_vars.iter();548// Check that it is a local name, and an operand549const Form* form = oper._localNames[rep_var];550if (form == NULL) {551globalAD->syntax_err(oper._linenum,552"\'%s\' not found in format for %s\n", rep_var, oper._ident);553assert(form, "replacement variable was not found in local names");554}555OperandForm *op = form->is_operand();556// Get index if register or constant557if ( op->_matrule && op->_matrule->is_base_register(globals) ) {558idx = oper.register_position( globals, rep_var);559}560else if (op->_matrule && op->_matrule->is_base_constant(globals)) {561idx = oper.constant_position( globals, rep_var);562} else {563idx = 0;564}565// output invocation of "$..."s format function566if ( op != NULL ) op->ext_format(fp, globals, idx);567568// Lookup the index position of the replacement variable569idx = oper._components.operand_position_format(rep_var, &oper);570if ( idx == -1 ) {571fprintf(stderr,572"Using a name, %s, that isn't in match rule\n", rep_var);573assert( strcmp(op->_ident,"label")==0, "Unimplemented");574}575} // Done with a replacement variable576} // Done with all format strings577578} else {579// Default formats for base operands (RegI, RegP, ConI, ConP, ...)580oper.ext_format(fp, globals, 0);581}582} else { // oper._format == NULL583// Provide a few special case formats where the AD writer cannot.584if ( strcmp(oper._ident,"Universe")==0 ) {585fprintf(fp, " st->print(\"$$univ\");\n");586}587// labelOper::ext_format is defined in ad_<...>.cpp588}589// ALWAYS! Provide a special case output for condition codes.590if( oper.is_ideal_bool() ) {591defineCCodeDump(&oper, fp,0);592}593fprintf(fp, "}\n");594fprintf(fp, "#endif\n");595}596597598// Generate the format rule for an instruction599void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &inst, bool for_c_file = false) {600if (!for_c_file) {601// compile the bodies separately, to cut down on recompilations602// #ifndef PRODUCT region generated by caller603fprintf(fp," virtual void format(PhaseRegAlloc *ra, outputStream *st) const;\n");604return;605}606607// Define the format function608fprintf(fp, "#ifndef PRODUCT\n");609fprintf(fp, "void %sNode::format(PhaseRegAlloc *ra, outputStream *st) const {\n", inst._ident);610611// Generate the user-defined portion of the format612if( inst._format ) {613// If there are replacement variables,614// Generate index values needed for determining the operand position615if( inst._format->_rep_vars.count() )616inst.index_temps(fp, globals);617618// Build the format from the entries in strings and rep_vars619const char *string = NULL;620inst._format->_rep_vars.reset();621inst._format->_strings.reset();622while( (string = inst._format->_strings.iter()) != NULL ) {623fprintf(fp," ");624// Check if this is a standard string or a replacement variable625if( string == NameList::_signal ) { // Replacement variable626const char* rep_var = inst._format->_rep_vars.iter();627inst.rep_var_format( fp, rep_var);628} else if( string == NameList::_signal3 ) { // Replacement variable in raw text629const char* rep_var = inst._format->_rep_vars.iter();630const Form *form = inst._localNames[rep_var];631if (form == NULL) {632fprintf(stderr, "unknown replacement variable in format statement: '%s'\n", rep_var);633assert(false, "ShouldNotReachHere()");634}635OpClassForm *opc = form->is_opclass();636assert( opc, "replacement variable was not found in local names");637// Lookup the index position of the replacement variable638int idx = inst.operand_position_format(rep_var);639if ( idx == -1 ) {640assert( strcmp(opc->_ident,"label")==0, "Unimplemented");641assert( false, "ShouldNotReachHere()");642}643644if (inst.is_noninput_operand(idx)) {645assert( false, "ShouldNotReachHere()");646} else {647// Output the format call for this operand648fprintf(fp,"opnd_array(%d)",idx);649}650rep_var = inst._format->_rep_vars.iter();651inst._format->_strings.iter();652if ( strcmp(rep_var,"$constant") == 0 && opc->is_operand()) {653Form::DataType constant_type = form->is_operand()->is_base_constant(globals);654if ( constant_type == Form::idealD ) {655fprintf(fp,"->constantD()");656} else if ( constant_type == Form::idealF ) {657fprintf(fp,"->constantF()");658} else if ( constant_type == Form::idealL ) {659fprintf(fp,"->constantL()");660} else {661fprintf(fp,"->constant()");662}663} else if ( strcmp(rep_var,"$cmpcode") == 0) {664fprintf(fp,"->ccode()");665} else {666assert( false, "ShouldNotReachHere()");667}668} else if( string == NameList::_signal2 ) // Raw program text669fputs(inst._format->_strings.iter(), fp);670else671fprintf(fp,"st->print_raw(\"%s\");\n", string);672} // Done with all format strings673} // Done generating the user-defined portion of the format674675// Add call debug info automatically676Form::CallType call_type = inst.is_ideal_call();677if( call_type != Form::invalid_type ) {678switch( call_type ) {679case Form::JAVA_DYNAMIC:680fprintf(fp," _method->print_short_name(st);\n");681break;682case Form::JAVA_STATIC:683fprintf(fp," if( _method ) _method->print_short_name(st);\n");684fprintf(fp," else st->print(\" wrapper for: %%s\", _name);\n");685fprintf(fp," if( !_method ) dump_trap_args(st);\n");686break;687case Form::JAVA_COMPILED:688case Form::JAVA_INTERP:689break;690case Form::JAVA_RUNTIME:691case Form::JAVA_LEAF:692case Form::JAVA_NATIVE:693fprintf(fp," st->print(\" %%s\", _name);");694break;695default:696assert(0,"ShouldNotReachHere");697}698fprintf(fp, " st->cr();\n" );699fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );700fprintf(fp, " st->print(\" # \");\n" );701fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");702}703else if(inst.is_ideal_safepoint()) {704fprintf(fp, " st->print_raw(\"\");\n" );705fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );706fprintf(fp, " st->print(\" # \");\n" );707fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");708}709else if( inst.is_ideal_if() ) {710fprintf(fp, " st->print(\" P=%%f C=%%f\",_prob,_fcnt);\n" );711}712else if( inst.is_ideal_mem() ) {713// Print out the field name if available to improve readability714fprintf(fp, " if (ra->C->alias_type(adr_type())->field() != NULL) {\n");715fprintf(fp, " ciField* f = ra->C->alias_type(adr_type())->field();\n");716fprintf(fp, " st->print(\" %s Field: \");\n", commentSeperator);717fprintf(fp, " if (f->is_volatile())\n");718fprintf(fp, " st->print(\"volatile \");\n");719fprintf(fp, " f->holder()->name()->print_symbol_on(st);\n");720fprintf(fp, " st->print(\".\");\n");721fprintf(fp, " f->name()->print_symbol_on(st);\n");722fprintf(fp, " if (f->is_constant())\n");723fprintf(fp, " st->print(\" (constant)\");\n");724fprintf(fp, " } else {\n");725// Make sure 'Volatile' gets printed out726fprintf(fp, " if (ra->C->alias_type(adr_type())->is_volatile())\n");727fprintf(fp, " st->print(\" volatile!\");\n");728fprintf(fp, " }\n");729}730731// Complete the definition of the format function732fprintf(fp, "}\n#endif\n");733}734735void ArchDesc::declare_pipe_classes(FILE *fp_hpp) {736if (!_pipeline)737return;738739fprintf(fp_hpp, "\n");740fprintf(fp_hpp, "// Pipeline_Use_Cycle_Mask Class\n");741fprintf(fp_hpp, "class Pipeline_Use_Cycle_Mask {\n");742743if (_pipeline->_maxcycleused <= 32) {744fprintf(fp_hpp, "protected:\n");745fprintf(fp_hpp, " %s _mask;\n\n", _pipeline->_maxcycleused <= 32 ? "uint" : "uint64_t" );746fprintf(fp_hpp, "public:\n");747fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : _mask(0) {}\n\n");748if (_pipeline->_maxcycleused <= 32)749fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask) : _mask(mask) {}\n\n");750else {751fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n");752fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n");753}754fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");755fprintf(fp_hpp, " return ((_mask & in2._mask) != 0);\n");756fprintf(fp_hpp, " }\n\n");757fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");758fprintf(fp_hpp, " _mask <<= n;\n");759fprintf(fp_hpp, " return *this;\n");760fprintf(fp_hpp, " }\n\n");761fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &in2) {\n");762fprintf(fp_hpp, " _mask |= in2._mask;\n");763fprintf(fp_hpp, " }\n\n");764fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");765fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");766}767else {768fprintf(fp_hpp, "protected:\n");769uint masklen = (_pipeline->_maxcycleused + 31) >> 5;770uint l;771fprintf(fp_hpp, " uint ");772for (l = 1; l <= masklen; l++)773fprintf(fp_hpp, "_mask%d%s", l, l < masklen ? ", " : ";\n\n");774fprintf(fp_hpp, "public:\n");775fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : ");776for (l = 1; l <= masklen; l++)777fprintf(fp_hpp, "_mask%d(0)%s", l, l < masklen ? ", " : " {}\n\n");778fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(");779for (l = 1; l <= masklen; l++)780fprintf(fp_hpp, "uint mask%d%s", l, l < masklen ? ", " : ") : ");781for (l = 1; l <= masklen; l++)782fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n");783784fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n");785fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask out;\n");786for (l = 1; l <= masklen; l++)787fprintf(fp_hpp, " out._mask%d = _mask%d & in2._mask%d;\n", l, l, l);788fprintf(fp_hpp, " return out;\n");789fprintf(fp_hpp, " }\n\n");790fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");791fprintf(fp_hpp, " return (");792for (l = 1; l <= masklen; l++)793fprintf(fp_hpp, "((_mask%d & in2._mask%d) != 0)%s", l, l, l < masklen ? " || " : "");794fprintf(fp_hpp, ") ? true : false;\n");795fprintf(fp_hpp, " }\n\n");796fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");797fprintf(fp_hpp, " if (n >= 32)\n");798fprintf(fp_hpp, " do {\n ");799for (l = masklen; l > 1; l--)800fprintf(fp_hpp, " _mask%d = _mask%d;", l, l-1);801fprintf(fp_hpp, " _mask%d = 0;\n", 1);802fprintf(fp_hpp, " } while ((n -= 32) >= 32);\n\n");803fprintf(fp_hpp, " if (n > 0) {\n");804fprintf(fp_hpp, " uint m = 32 - n;\n");805fprintf(fp_hpp, " uint mask = (1 << n) - 1;\n");806fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n;\n", 2, 1, 1);807for (l = 2; l < masklen; l++) {808fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n; _mask%d |= temp%d;\n", l+1, l, l, l, l);809}810fprintf(fp_hpp, " _mask%d <<= n; _mask%d |= temp%d;\n", masklen, masklen, masklen);811fprintf(fp_hpp, " }\n");812813fprintf(fp_hpp, " return *this;\n");814fprintf(fp_hpp, " }\n\n");815fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &);\n\n");816fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");817fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");818}819820fprintf(fp_hpp, " friend class Pipeline_Use;\n\n");821fprintf(fp_hpp, " friend class Pipeline_Use_Element;\n\n");822fprintf(fp_hpp, "};\n\n");823824uint rescount = 0;825const char *resource;826827for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {828int mask = _pipeline->_resdict[resource]->is_resource()->mask();829if ((mask & (mask-1)) == 0)830rescount++;831}832833fprintf(fp_hpp, "// Pipeline_Use_Element Class\n");834fprintf(fp_hpp, "class Pipeline_Use_Element {\n");835fprintf(fp_hpp, "protected:\n");836fprintf(fp_hpp, " // Mask of used functional units\n");837fprintf(fp_hpp, " uint _used;\n\n");838fprintf(fp_hpp, " // Lower and upper bound of functional unit number range\n");839fprintf(fp_hpp, " uint _lb, _ub;\n\n");840fprintf(fp_hpp, " // Indicates multiple functionals units available\n");841fprintf(fp_hpp, " bool _multiple;\n\n");842fprintf(fp_hpp, " // Mask of specific used cycles\n");843fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask _mask;\n\n");844fprintf(fp_hpp, "public:\n");845fprintf(fp_hpp, " Pipeline_Use_Element() {}\n\n");846fprintf(fp_hpp, " Pipeline_Use_Element(uint used, uint lb, uint ub, bool multiple, Pipeline_Use_Cycle_Mask mask)\n");847fprintf(fp_hpp, " : _used(used), _lb(lb), _ub(ub), _multiple(multiple), _mask(mask) {}\n\n");848fprintf(fp_hpp, " uint used() const { return _used; }\n\n");849fprintf(fp_hpp, " uint lowerBound() const { return _lb; }\n\n");850fprintf(fp_hpp, " uint upperBound() const { return _ub; }\n\n");851fprintf(fp_hpp, " bool multiple() const { return _multiple; }\n\n");852fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask mask() const { return _mask; }\n\n");853fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Element &in2) const {\n");854fprintf(fp_hpp, " return ((_used & in2._used) != 0 && _mask.overlaps(in2._mask));\n");855fprintf(fp_hpp, " }\n\n");856fprintf(fp_hpp, " void step(uint cycles) {\n");857fprintf(fp_hpp, " _used = 0;\n");858fprintf(fp_hpp, " _mask <<= cycles;\n");859fprintf(fp_hpp, " }\n\n");860fprintf(fp_hpp, " friend class Pipeline_Use;\n");861fprintf(fp_hpp, "};\n\n");862863fprintf(fp_hpp, "// Pipeline_Use Class\n");864fprintf(fp_hpp, "class Pipeline_Use {\n");865fprintf(fp_hpp, "protected:\n");866fprintf(fp_hpp, " // These resources can be used\n");867fprintf(fp_hpp, " uint _resources_used;\n\n");868fprintf(fp_hpp, " // These resources are used; excludes multiple choice functional units\n");869fprintf(fp_hpp, " uint _resources_used_exclusively;\n\n");870fprintf(fp_hpp, " // Number of elements\n");871fprintf(fp_hpp, " uint _count;\n\n");872fprintf(fp_hpp, " // This is the array of Pipeline_Use_Elements\n");873fprintf(fp_hpp, " Pipeline_Use_Element * _elements;\n\n");874fprintf(fp_hpp, "public:\n");875fprintf(fp_hpp, " Pipeline_Use(uint resources_used, uint resources_used_exclusively, uint count, Pipeline_Use_Element *elements)\n");876fprintf(fp_hpp, " : _resources_used(resources_used)\n");877fprintf(fp_hpp, " , _resources_used_exclusively(resources_used_exclusively)\n");878fprintf(fp_hpp, " , _count(count)\n");879fprintf(fp_hpp, " , _elements(elements)\n");880fprintf(fp_hpp, " {}\n\n");881fprintf(fp_hpp, " uint resourcesUsed() const { return _resources_used; }\n\n");882fprintf(fp_hpp, " uint resourcesUsedExclusively() const { return _resources_used_exclusively; }\n\n");883fprintf(fp_hpp, " uint count() const { return _count; }\n\n");884fprintf(fp_hpp, " Pipeline_Use_Element * element(uint i) const { return &_elements[i]; }\n\n");885fprintf(fp_hpp, " uint full_latency(uint delay, const Pipeline_Use &pred) const;\n\n");886fprintf(fp_hpp, " void add_usage(const Pipeline_Use &pred);\n\n");887fprintf(fp_hpp, " void reset() {\n");888fprintf(fp_hpp, " _resources_used = _resources_used_exclusively = 0;\n");889fprintf(fp_hpp, " };\n\n");890fprintf(fp_hpp, " void step(uint cycles) {\n");891fprintf(fp_hpp, " reset();\n");892fprintf(fp_hpp, " for (uint i = 0; i < %d; i++)\n",893rescount);894fprintf(fp_hpp, " (&_elements[i])->step(cycles);\n");895fprintf(fp_hpp, " };\n\n");896fprintf(fp_hpp, " static const Pipeline_Use elaborated_use;\n");897fprintf(fp_hpp, " static const Pipeline_Use_Element elaborated_elements[%d];\n\n",898rescount);899fprintf(fp_hpp, " friend class Pipeline;\n");900fprintf(fp_hpp, "};\n\n");901902fprintf(fp_hpp, "// Pipeline Class\n");903fprintf(fp_hpp, "class Pipeline {\n");904fprintf(fp_hpp, "public:\n");905906fprintf(fp_hpp, " static bool enabled() { return %s; }\n\n",907_pipeline ? "true" : "false" );908909assert( _pipeline->_maxInstrsPerBundle &&910( _pipeline->_instrUnitSize || _pipeline->_bundleUnitSize) &&911_pipeline->_instrFetchUnitSize &&912_pipeline->_instrFetchUnits,913"unspecified pipeline architecture units");914915uint unitSize = _pipeline->_instrUnitSize ? _pipeline->_instrUnitSize : _pipeline->_bundleUnitSize;916917fprintf(fp_hpp, " enum {\n");918fprintf(fp_hpp, " _variable_size_instructions = %d,\n",919_pipeline->_variableSizeInstrs ? 1 : 0);920fprintf(fp_hpp, " _fixed_size_instructions = %d,\n",921_pipeline->_variableSizeInstrs ? 0 : 1);922fprintf(fp_hpp, " _branch_has_delay_slot = %d,\n",923_pipeline->_branchHasDelaySlot ? 1 : 0);924fprintf(fp_hpp, " _max_instrs_per_bundle = %d,\n",925_pipeline->_maxInstrsPerBundle);926fprintf(fp_hpp, " _max_bundles_per_cycle = %d,\n",927_pipeline->_maxBundlesPerCycle);928fprintf(fp_hpp, " _max_instrs_per_cycle = %d\n",929_pipeline->_maxBundlesPerCycle * _pipeline->_maxInstrsPerBundle);930fprintf(fp_hpp, " };\n\n");931932fprintf(fp_hpp, " static bool instr_has_unit_size() { return %s; }\n\n",933_pipeline->_instrUnitSize != 0 ? "true" : "false" );934if( _pipeline->_bundleUnitSize != 0 )935if( _pipeline->_instrUnitSize != 0 )936fprintf(fp_hpp, "// Individual Instructions may be bundled together by the hardware\n\n");937else938fprintf(fp_hpp, "// Instructions exist only in bundles\n\n");939else940fprintf(fp_hpp, "// Bundling is not supported\n\n");941if( _pipeline->_instrUnitSize != 0 )942fprintf(fp_hpp, " // Size of an instruction\n");943else944fprintf(fp_hpp, " // Size of an individual instruction does not exist - unsupported\n");945fprintf(fp_hpp, " static uint instr_unit_size() {");946if( _pipeline->_instrUnitSize == 0 )947fprintf(fp_hpp, " assert( false, \"Instructions are only in bundles\" );");948fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_instrUnitSize);949950if( _pipeline->_bundleUnitSize != 0 )951fprintf(fp_hpp, " // Size of a bundle\n");952else953fprintf(fp_hpp, " // Bundles do not exist - unsupported\n");954fprintf(fp_hpp, " static uint bundle_unit_size() {");955if( _pipeline->_bundleUnitSize == 0 )956fprintf(fp_hpp, " assert( false, \"Bundles are not supported\" );");957fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_bundleUnitSize);958959fprintf(fp_hpp, " static bool requires_bundling() { return %s; }\n\n",960_pipeline->_bundleUnitSize != 0 && _pipeline->_instrUnitSize == 0 ? "true" : "false" );961962fprintf(fp_hpp, "private:\n");963fprintf(fp_hpp, " Pipeline(); // Not a legal constructor\n");964fprintf(fp_hpp, "\n");965fprintf(fp_hpp, " const unsigned char _read_stage_count;\n");966fprintf(fp_hpp, " const unsigned char _write_stage;\n");967fprintf(fp_hpp, " const unsigned char _fixed_latency;\n");968fprintf(fp_hpp, " const unsigned char _instruction_count;\n");969fprintf(fp_hpp, " const bool _has_fixed_latency;\n");970fprintf(fp_hpp, " const bool _has_branch_delay;\n");971fprintf(fp_hpp, " const bool _has_multiple_bundles;\n");972fprintf(fp_hpp, " const bool _force_serialization;\n");973fprintf(fp_hpp, " const bool _may_have_no_code;\n");974fprintf(fp_hpp, " const enum machPipelineStages * const _read_stages;\n");975fprintf(fp_hpp, " const enum machPipelineStages * const _resource_stage;\n");976fprintf(fp_hpp, " const uint * const _resource_cycles;\n");977fprintf(fp_hpp, " const Pipeline_Use _resource_use;\n");978fprintf(fp_hpp, "\n");979fprintf(fp_hpp, "public:\n");980fprintf(fp_hpp, " Pipeline(uint write_stage,\n");981fprintf(fp_hpp, " uint count,\n");982fprintf(fp_hpp, " bool has_fixed_latency,\n");983fprintf(fp_hpp, " uint fixed_latency,\n");984fprintf(fp_hpp, " uint instruction_count,\n");985fprintf(fp_hpp, " bool has_branch_delay,\n");986fprintf(fp_hpp, " bool has_multiple_bundles,\n");987fprintf(fp_hpp, " bool force_serialization,\n");988fprintf(fp_hpp, " bool may_have_no_code,\n");989fprintf(fp_hpp, " enum machPipelineStages * const dst,\n");990fprintf(fp_hpp, " enum machPipelineStages * const stage,\n");991fprintf(fp_hpp, " uint * const cycles,\n");992fprintf(fp_hpp, " Pipeline_Use resource_use)\n");993fprintf(fp_hpp, " : _read_stage_count(count)\n");994fprintf(fp_hpp, " , _write_stage(write_stage)\n");995fprintf(fp_hpp, " , _fixed_latency(fixed_latency)\n");996fprintf(fp_hpp, " , _instruction_count(instruction_count)\n");997fprintf(fp_hpp, " , _has_fixed_latency(has_fixed_latency)\n");998fprintf(fp_hpp, " , _has_branch_delay(has_branch_delay)\n");999fprintf(fp_hpp, " , _has_multiple_bundles(has_multiple_bundles)\n");1000fprintf(fp_hpp, " , _force_serialization(force_serialization)\n");1001fprintf(fp_hpp, " , _may_have_no_code(may_have_no_code)\n");1002fprintf(fp_hpp, " , _read_stages(dst)\n");1003fprintf(fp_hpp, " , _resource_stage(stage)\n");1004fprintf(fp_hpp, " , _resource_cycles(cycles)\n");1005fprintf(fp_hpp, " , _resource_use(resource_use)\n");1006fprintf(fp_hpp, " {};\n");1007fprintf(fp_hpp, "\n");1008fprintf(fp_hpp, " uint writeStage() const {\n");1009fprintf(fp_hpp, " return (_write_stage);\n");1010fprintf(fp_hpp, " }\n");1011fprintf(fp_hpp, "\n");1012fprintf(fp_hpp, " enum machPipelineStages readStage(int ndx) const {\n");1013fprintf(fp_hpp, " return (ndx < _read_stage_count ? _read_stages[ndx] : stage_undefined);");1014fprintf(fp_hpp, " }\n\n");1015fprintf(fp_hpp, " uint resourcesUsed() const {\n");1016fprintf(fp_hpp, " return _resource_use.resourcesUsed();\n }\n\n");1017fprintf(fp_hpp, " uint resourcesUsedExclusively() const {\n");1018fprintf(fp_hpp, " return _resource_use.resourcesUsedExclusively();\n }\n\n");1019fprintf(fp_hpp, " bool hasFixedLatency() const {\n");1020fprintf(fp_hpp, " return (_has_fixed_latency);\n }\n\n");1021fprintf(fp_hpp, " uint fixedLatency() const {\n");1022fprintf(fp_hpp, " return (_fixed_latency);\n }\n\n");1023fprintf(fp_hpp, " uint functional_unit_latency(uint start, const Pipeline *pred) const;\n\n");1024fprintf(fp_hpp, " uint operand_latency(uint opnd, const Pipeline *pred) const;\n\n");1025fprintf(fp_hpp, " const Pipeline_Use& resourceUse() const {\n");1026fprintf(fp_hpp, " return (_resource_use); }\n\n");1027fprintf(fp_hpp, " const Pipeline_Use_Element * resourceUseElement(uint i) const {\n");1028fprintf(fp_hpp, " return (&_resource_use._elements[i]); }\n\n");1029fprintf(fp_hpp, " uint resourceUseCount() const {\n");1030fprintf(fp_hpp, " return (_resource_use._count); }\n\n");1031fprintf(fp_hpp, " uint instructionCount() const {\n");1032fprintf(fp_hpp, " return (_instruction_count); }\n\n");1033fprintf(fp_hpp, " bool hasBranchDelay() const {\n");1034fprintf(fp_hpp, " return (_has_branch_delay); }\n\n");1035fprintf(fp_hpp, " bool hasMultipleBundles() const {\n");1036fprintf(fp_hpp, " return (_has_multiple_bundles); }\n\n");1037fprintf(fp_hpp, " bool forceSerialization() const {\n");1038fprintf(fp_hpp, " return (_force_serialization); }\n\n");1039fprintf(fp_hpp, " bool mayHaveNoCode() const {\n");1040fprintf(fp_hpp, " return (_may_have_no_code); }\n\n");1041fprintf(fp_hpp, "//const Pipeline_Use_Cycle_Mask& resourceUseMask(int resource) const {\n");1042fprintf(fp_hpp, "// return (_resource_use_masks[resource]); }\n\n");1043fprintf(fp_hpp, "\n#ifndef PRODUCT\n");1044fprintf(fp_hpp, " static const char * stageName(uint i);\n");1045fprintf(fp_hpp, "#endif\n");1046fprintf(fp_hpp, "};\n\n");10471048fprintf(fp_hpp, "// Bundle class\n");1049fprintf(fp_hpp, "class Bundle {\n");10501051uint mshift = 0;1052for (uint msize = _pipeline->_maxInstrsPerBundle * _pipeline->_maxBundlesPerCycle; msize != 0; msize >>= 1)1053mshift++;10541055uint rshift = rescount;10561057fprintf(fp_hpp, "protected:\n");1058fprintf(fp_hpp, " enum {\n");1059fprintf(fp_hpp, " _unused_delay = 0x%x,\n", 0);1060fprintf(fp_hpp, " _use_nop_delay = 0x%x,\n", 1);1061fprintf(fp_hpp, " _use_unconditional_delay = 0x%x,\n", 2);1062fprintf(fp_hpp, " _use_conditional_delay = 0x%x,\n", 3);1063fprintf(fp_hpp, " _used_in_conditional_delay = 0x%x,\n", 4);1064fprintf(fp_hpp, " _used_in_unconditional_delay = 0x%x,\n", 5);1065fprintf(fp_hpp, " _used_in_all_conditional_delays = 0x%x,\n", 6);1066fprintf(fp_hpp, "\n");1067fprintf(fp_hpp, " _use_delay = 0x%x,\n", 3);1068fprintf(fp_hpp, " _used_in_delay = 0x%x\n", 4);1069fprintf(fp_hpp, " };\n\n");1070fprintf(fp_hpp, " uint _flags : 3,\n");1071fprintf(fp_hpp, " _starts_bundle : 1,\n");1072fprintf(fp_hpp, " _instr_count : %d,\n", mshift);1073fprintf(fp_hpp, " _resources_used : %d;\n", rshift);1074fprintf(fp_hpp, "public:\n");1075fprintf(fp_hpp, " Bundle() : _flags(_unused_delay), _starts_bundle(0), _instr_count(0), _resources_used(0) {}\n\n");1076fprintf(fp_hpp, " void set_instr_count(uint i) { _instr_count = i; }\n");1077fprintf(fp_hpp, " void set_resources_used(uint i) { _resources_used = i; }\n");1078fprintf(fp_hpp, " void clear_usage() { _flags = _unused_delay; }\n");1079fprintf(fp_hpp, " void set_starts_bundle() { _starts_bundle = true; }\n");10801081fprintf(fp_hpp, " uint flags() const { return (_flags); }\n");1082fprintf(fp_hpp, " uint instr_count() const { return (_instr_count); }\n");1083fprintf(fp_hpp, " uint resources_used() const { return (_resources_used); }\n");1084fprintf(fp_hpp, " bool starts_bundle() const { return (_starts_bundle != 0); }\n");10851086fprintf(fp_hpp, " void set_use_nop_delay() { _flags = _use_nop_delay; }\n");1087fprintf(fp_hpp, " void set_use_unconditional_delay() { _flags = _use_unconditional_delay; }\n");1088fprintf(fp_hpp, " void set_use_conditional_delay() { _flags = _use_conditional_delay; }\n");1089fprintf(fp_hpp, " void set_used_in_unconditional_delay() { _flags = _used_in_unconditional_delay; }\n");1090fprintf(fp_hpp, " void set_used_in_conditional_delay() { _flags = _used_in_conditional_delay; }\n");1091fprintf(fp_hpp, " void set_used_in_all_conditional_delays() { _flags = _used_in_all_conditional_delays; }\n");10921093fprintf(fp_hpp, " bool use_nop_delay() { return (_flags == _use_nop_delay); }\n");1094fprintf(fp_hpp, " bool use_unconditional_delay() { return (_flags == _use_unconditional_delay); }\n");1095fprintf(fp_hpp, " bool use_conditional_delay() { return (_flags == _use_conditional_delay); }\n");1096fprintf(fp_hpp, " bool used_in_unconditional_delay() { return (_flags == _used_in_unconditional_delay); }\n");1097fprintf(fp_hpp, " bool used_in_conditional_delay() { return (_flags == _used_in_conditional_delay); }\n");1098fprintf(fp_hpp, " bool used_in_all_conditional_delays() { return (_flags == _used_in_all_conditional_delays); }\n");1099fprintf(fp_hpp, " bool use_delay() { return ((_flags & _use_delay) != 0); }\n");1100fprintf(fp_hpp, " bool used_in_delay() { return ((_flags & _used_in_delay) != 0); }\n\n");11011102fprintf(fp_hpp, " enum {\n");1103fprintf(fp_hpp, " _nop_count = %d\n",1104_pipeline->_nopcnt);1105fprintf(fp_hpp, " };\n\n");1106fprintf(fp_hpp, " static void initialize_nops(MachNode *nop_list[%d]);\n\n",1107_pipeline->_nopcnt);1108fprintf(fp_hpp, "#ifndef PRODUCT\n");1109fprintf(fp_hpp, " void dump(outputStream *st = tty) const;\n");1110fprintf(fp_hpp, "#endif\n");1111fprintf(fp_hpp, "};\n\n");11121113// const char *classname;1114// for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) {1115// PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass();1116// fprintf(fp_hpp, "// Pipeline Class Instance for \"%s\"\n", classname);1117// }1118}11191120//------------------------------declareClasses---------------------------------1121// Construct the class hierarchy of MachNode classes from the instruction &1122// operand lists1123void ArchDesc::declareClasses(FILE *fp) {11241125// Declare an array containing the machine register names, strings.1126declareRegNames(fp, _register);11271128// Declare an array containing the machine register encoding values1129declareRegEncodes(fp, _register);11301131// Generate declarations for the total number of operands1132fprintf(fp,"\n");1133fprintf(fp,"// Total number of operands defined in architecture definition\n");1134int num_operands = 0;1135OperandForm *op;1136for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != NULL; ) {1137// Ensure this is a machine-world instruction1138if (op->ideal_only()) continue;11391140++num_operands;1141}1142int first_operand_class = num_operands;1143OpClassForm *opc;1144for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != NULL; ) {1145// Ensure this is a machine-world instruction1146if (opc->ideal_only()) continue;11471148++num_operands;1149}1150fprintf(fp,"#define FIRST_OPERAND_CLASS %d\n", first_operand_class);1151fprintf(fp,"#define NUM_OPERANDS %d\n", num_operands);1152fprintf(fp,"\n");1153// Generate declarations for the total number of instructions1154fprintf(fp,"// Total number of instructions defined in architecture definition\n");1155fprintf(fp,"#define NUM_INSTRUCTIONS %d\n",instructFormCount());115611571158// Generate Machine Classes for each operand defined in AD file1159fprintf(fp,"\n");1160fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n");1161// Iterate through all operands1162_operands.reset();1163OperandForm *oper;1164for( ; (oper = (OperandForm*)_operands.iter()) != NULL;) {1165// Ensure this is a machine-world instruction1166if (oper->ideal_only() ) continue;1167// The declaration of labelOper is in machine-independent file: machnode1168if ( strcmp(oper->_ident,"label") == 0 ) continue;1169// The declaration of methodOper is in machine-independent file: machnode1170if ( strcmp(oper->_ident,"method") == 0 ) continue;11711172// Build class definition for this operand1173fprintf(fp,"\n");1174fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident);1175fprintf(fp,"private:\n");1176// Operand definitions that depend upon number of input edges1177{1178uint num_edges = oper->num_edges(_globalNames);1179if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;}1180fprintf(fp," virtual uint num_edges() const { return %d; }\n",1181num_edges );1182}1183if( num_edges > 0 ) {1184in_RegMask(fp);1185}1186}11871188// Support storing constants inside the MachOper1189declareConstStorage(fp,_globalNames,oper);11901191// Support storage of the condition codes1192if( oper->is_ideal_bool() ) {1193fprintf(fp," virtual int ccode() const { \n");1194fprintf(fp," switch (_c0) {\n");1195fprintf(fp," case BoolTest::eq : return equal();\n");1196fprintf(fp," case BoolTest::gt : return greater();\n");1197fprintf(fp," case BoolTest::lt : return less();\n");1198fprintf(fp," case BoolTest::ne : return not_equal();\n");1199fprintf(fp," case BoolTest::le : return less_equal();\n");1200fprintf(fp," case BoolTest::ge : return greater_equal();\n");1201fprintf(fp," case BoolTest::overflow : return overflow();\n");1202fprintf(fp," case BoolTest::no_overflow: return no_overflow();\n");1203fprintf(fp," default : ShouldNotReachHere(); return 0;\n");1204fprintf(fp," }\n");1205fprintf(fp," };\n");1206}12071208// Support storage of the condition codes1209if( oper->is_ideal_bool() ) {1210fprintf(fp," virtual void negate() { \n");1211fprintf(fp," _c0 = (BoolTest::mask)((int)_c0^0x4); \n");1212fprintf(fp," };\n");1213}12141215// Declare constructor.1216// Parameters start with condition code, then all other constants1217//1218// (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)1219// (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }1220//1221Form::DataType constant_type = oper->simple_type(_globalNames);1222defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames),1223oper->_components, oper->is_ideal_bool(),1224constant_type, _globalNames);12251226// Clone function1227fprintf(fp," virtual MachOper *clone() const;\n");12281229// Support setting a spill offset into a constant operand.1230// We only support setting an 'int' offset, while in the1231// LP64 build spill offsets are added with an AddP which1232// requires a long constant. Thus we don't support spilling1233// in frames larger than 4Gig.1234if( oper->has_conI(_globalNames) ||1235oper->has_conL(_globalNames) )1236fprintf(fp, " virtual void set_con( jint c0 ) { _c0 = c0; }\n");12371238// virtual functions for encoding and format1239// fprintf(fp," virtual void encode() const {\n %s }\n",1240// (oper->_encrule)?(oper->_encrule->_encrule):"");1241// Check the interface type, and generate the correct query functions1242// encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER.12431244fprintf(fp," virtual uint opcode() const { return %s; }\n",1245machOperEnum(oper->_ident));12461247// virtual function to look up ideal return type of machine instruction1248//1249// (1) virtual const Type *type() const { return .....; }1250//1251if ((oper->_matrule) && (oper->_matrule->_lChild == NULL) &&1252(oper->_matrule->_rChild == NULL)) {1253unsigned int position = 0;1254const char *opret, *opname, *optype;1255oper->_matrule->base_operand(position,_globalNames,opret,opname,optype);1256fprintf(fp," virtual const Type *type() const {");1257const char *type = getIdealType(optype);1258if( type != NULL ) {1259Form::DataType data_type = oper->is_base_constant(_globalNames);1260// Check if we are an ideal pointer type1261if( data_type == Form::idealP || data_type == Form::idealN || data_type == Form::idealNKlass ) {1262// Return the ideal type we already have: <TypePtr *>1263fprintf(fp," return _c0;");1264} else {1265// Return the appropriate bottom type1266fprintf(fp," return %s;", getIdealType(optype));1267}1268} else {1269fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;");1270}1271fprintf(fp," }\n");1272} else {1273// Check for user-defined stack slots, based upon sRegX1274Form::DataType data_type = oper->is_user_name_for_sReg();1275if( data_type != Form::none ){1276const char *type = NULL;1277switch( data_type ) {1278case Form::idealI: type = "TypeInt::INT"; break;1279case Form::idealP: type = "TypePtr::BOTTOM";break;1280case Form::idealF: type = "Type::FLOAT"; break;1281case Form::idealD: type = "Type::DOUBLE"; break;1282case Form::idealL: type = "TypeLong::LONG"; break;1283case Form::none: // fall through1284default:1285assert( false, "No support for this type of stackSlot");1286}1287fprintf(fp," virtual const Type *type() const { return %s; } // stackSlotX\n", type);1288}1289}129012911292//1293// virtual functions for defining the encoding interface.1294//1295// Access the linearized ideal register mask,1296// map to physical register encoding1297if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) {1298// Just use the default virtual 'reg' call1299} else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) {1300// Special handling for operand 'sReg', a Stack Slot Register.1301// Map linearized ideal register mask to stack slot number1302fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node) const {\n");1303fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n");1304fprintf(fp," }\n");1305fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n");1306fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n");1307fprintf(fp," }\n");1308}13091310// Output the operand specific access functions used by an enc_class1311// These are only defined when we want to override the default virtual func1312if (oper->_interface != NULL) {1313fprintf(fp,"\n");1314// Check if it is a Memory Interface1315if ( oper->_interface->is_MemInterface() != NULL ) {1316MemInterface *mem_interface = oper->_interface->is_MemInterface();1317const char *base = mem_interface->_base;1318if( base != NULL ) {1319define_oper_interface(fp, *oper, _globalNames, "base", base);1320}1321char *index = mem_interface->_index;1322if( index != NULL ) {1323define_oper_interface(fp, *oper, _globalNames, "index", index);1324}1325const char *scale = mem_interface->_scale;1326if( scale != NULL ) {1327define_oper_interface(fp, *oper, _globalNames, "scale", scale);1328}1329const char *disp = mem_interface->_disp;1330if( disp != NULL ) {1331define_oper_interface(fp, *oper, _globalNames, "disp", disp);1332oper->disp_is_oop(fp, _globalNames);1333}1334if( oper->stack_slots_only(_globalNames) ) {1335// should not call this:1336fprintf(fp," virtual int constant_disp() const { return Type::OffsetBot; }");1337} else if ( disp != NULL ) {1338define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp);1339}1340} // end Memory Interface1341// Check if it is a Conditional Interface1342else if (oper->_interface->is_CondInterface() != NULL) {1343CondInterface *cInterface = oper->_interface->is_CondInterface();1344const char *equal = cInterface->_equal;1345if( equal != NULL ) {1346define_oper_interface(fp, *oper, _globalNames, "equal", equal);1347}1348const char *not_equal = cInterface->_not_equal;1349if( not_equal != NULL ) {1350define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal);1351}1352const char *less = cInterface->_less;1353if( less != NULL ) {1354define_oper_interface(fp, *oper, _globalNames, "less", less);1355}1356const char *greater_equal = cInterface->_greater_equal;1357if( greater_equal != NULL ) {1358define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal);1359}1360const char *less_equal = cInterface->_less_equal;1361if( less_equal != NULL ) {1362define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal);1363}1364const char *greater = cInterface->_greater;1365if( greater != NULL ) {1366define_oper_interface(fp, *oper, _globalNames, "greater", greater);1367}1368const char *overflow = cInterface->_overflow;1369if( overflow != NULL ) {1370define_oper_interface(fp, *oper, _globalNames, "overflow", overflow);1371}1372const char *no_overflow = cInterface->_no_overflow;1373if( no_overflow != NULL ) {1374define_oper_interface(fp, *oper, _globalNames, "no_overflow", no_overflow);1375}1376} // end Conditional Interface1377// Check if it is a Constant Interface1378else if (oper->_interface->is_ConstInterface() != NULL ) {1379assert( oper->num_consts(_globalNames) == 1,1380"Must have one constant when using CONST_INTER encoding");1381if (!strcmp(oper->ideal_type(_globalNames), "ConI")) {1382// Access the locally stored constant1383fprintf(fp," virtual intptr_t constant() const {");1384fprintf(fp, " return (intptr_t)_c0;");1385fprintf(fp," }\n");1386}1387else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) {1388// Access the locally stored constant1389fprintf(fp," virtual intptr_t constant() const {");1390fprintf(fp, " return _c0->get_con();");1391fprintf(fp, " }\n");1392// Generate query to determine if this pointer is an oop1393fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");1394fprintf(fp, " return _c0->reloc();");1395fprintf(fp, " }\n");1396}1397else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) {1398// Access the locally stored constant1399fprintf(fp," virtual intptr_t constant() const {");1400fprintf(fp, " return _c0->get_ptrtype()->get_con();");1401fprintf(fp, " }\n");1402// Generate query to determine if this pointer is an oop1403fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");1404fprintf(fp, " return _c0->get_ptrtype()->reloc();");1405fprintf(fp, " }\n");1406}1407else if (!strcmp(oper->ideal_type(_globalNames), "ConNKlass")) {1408// Access the locally stored constant1409fprintf(fp," virtual intptr_t constant() const {");1410fprintf(fp, " return _c0->get_ptrtype()->get_con();");1411fprintf(fp, " }\n");1412// Generate query to determine if this pointer is an oop1413fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");1414fprintf(fp, " return _c0->get_ptrtype()->reloc();");1415fprintf(fp, " }\n");1416}1417else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) {1418fprintf(fp," virtual intptr_t constant() const {");1419// We don't support addressing modes with > 4Gig offsets.1420// Truncate to int.1421fprintf(fp, " return (intptr_t)_c0;");1422fprintf(fp, " }\n");1423fprintf(fp," virtual jlong constantL() const {");1424fprintf(fp, " return _c0;");1425fprintf(fp, " }\n");1426}1427else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) {1428fprintf(fp," virtual intptr_t constant() const {");1429fprintf(fp, " ShouldNotReachHere(); return 0; ");1430fprintf(fp, " }\n");1431fprintf(fp," virtual jfloat constantF() const {");1432fprintf(fp, " return (jfloat)_c0;");1433fprintf(fp, " }\n");1434}1435else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) {1436fprintf(fp," virtual intptr_t constant() const {");1437fprintf(fp, " ShouldNotReachHere(); return 0; ");1438fprintf(fp, " }\n");1439fprintf(fp," virtual jdouble constantD() const {");1440fprintf(fp, " return _c0;");1441fprintf(fp, " }\n");1442}1443}1444else if (oper->_interface->is_RegInterface() != NULL) {1445// make sure that a fixed format string isn't used for an1446// operand which might be assiged to multiple registers.1447// Otherwise the opto assembly output could be misleading.1448if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) {1449syntax_err(oper->_linenum,1450"Only bound registers can have fixed formats: %s\n",1451oper->_ident);1452}1453}1454else {1455assert( false, "ShouldNotReachHere();");1456}1457}14581459fprintf(fp,"\n");1460// // Currently all XXXOper::hash() methods are identical (990820)1461// declare_hash(fp);1462// // Currently all XXXOper::Cmp() methods are identical (990820)1463// declare_cmp(fp);14641465// Do not place dump_spec() and Name() into PRODUCT code1466// int_format and ext_format are not needed in PRODUCT code either1467fprintf(fp, "#ifndef PRODUCT\n");14681469// Declare int_format() and ext_format()1470gen_oper_format(fp, _globalNames, *oper);14711472// Machine independent print functionality for debugging1473// IF we have constants, create a dump_spec function for the derived class1474//1475// (1) virtual void dump_spec() const {1476// (2) st->print("#%d", _c#); // Constant != ConP1477// OR _c#->dump_on(st); // Type ConP1478// ...1479// (3) }1480uint num_consts = oper->num_consts(_globalNames);1481if( num_consts > 0 ) {1482// line (1)1483fprintf(fp, " virtual void dump_spec(outputStream *st) const {\n");1484// generate format string for st->print1485// Iterate over the component list & spit out the right thing1486uint i = 0;1487const char *type = oper->ideal_type(_globalNames);1488Component *comp;1489oper->_components.reset();1490if ((comp = oper->_components.iter()) == NULL) {1491assert(num_consts == 1, "Bad component list detected.\n");1492i = dump_spec_constant( fp, type, i, oper );1493// Check that type actually matched1494assert( i != 0, "Non-constant operand lacks component list.");1495} // end if NULL1496else {1497// line (2)1498// dump all components1499oper->_components.reset();1500while((comp = oper->_components.iter()) != NULL) {1501type = comp->base_type(_globalNames);1502i = dump_spec_constant( fp, type, i, NULL );1503}1504}1505// finish line (3)1506fprintf(fp," }\n");1507}15081509fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",1510oper->_ident);15111512fprintf(fp,"#endif\n");15131514// Close definition of this XxxMachOper1515fprintf(fp,"};\n");1516}151715181519// Generate Machine Classes for each instruction defined in AD file1520fprintf(fp,"\n");1521fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");1522declare_pipe_classes(fp);15231524// Generate Machine Classes for each instruction defined in AD file1525fprintf(fp,"\n");1526fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");1527_instructions.reset();1528InstructForm *instr;1529for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {1530// Ensure this is a machine-world instruction1531if ( instr->ideal_only() ) continue;15321533// Build class definition for this instruction1534fprintf(fp,"\n");1535fprintf(fp,"class %sNode : public %s { \n",1536instr->_ident, instr->mach_base_class(_globalNames) );1537fprintf(fp,"private:\n");1538fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() );1539if ( instr->is_ideal_jump() ) {1540fprintf(fp, " GrowableArray<Label*> _index2label;\n");1541}15421543fprintf(fp, "public:\n");15441545Attribute *att = instr->_attribs;1546// Fields of the node specified in the ad file.1547while (att != NULL) {1548if (strncmp(att->_ident, "ins_field_", 10) == 0) {1549const char *field_name = att->_ident+10;1550const char *field_type = att->_val;1551fprintf(fp, " %s _%s;\n", field_type, field_name);1552}1553att = (Attribute *)att->_next;1554}15551556fprintf(fp," MachOper *opnd_array(uint operand_index) const {\n");1557fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");1558fprintf(fp," return _opnd_array[operand_index];\n");1559fprintf(fp," }\n");1560fprintf(fp," void set_opnd_array(uint operand_index, MachOper *operand) {\n");1561fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");1562fprintf(fp," _opnd_array[operand_index] = operand;\n");1563fprintf(fp," }\n");1564fprintf(fp," virtual uint rule() const { return %s_rule; }\n",1565instr->_ident);1566fprintf(fp,"private:\n");1567if ( instr->is_ideal_jump() ) {1568fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n");1569fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);\n");1570fprintf(fp," }\n");1571}1572if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {1573fprintf(fp," const RegMask *_cisc_RegMask;\n");1574}15751576out_RegMask(fp); // output register mask15771578// If this instruction contains a labelOper1579// Declare Node::methods that set operand Label's contents1580int label_position = instr->label_position();1581if( label_position != -1 ) {1582// Set/Save the label, stored in labelOper::_branch_label1583fprintf(fp," virtual void label_set( Label* label, uint block_num );\n");1584fprintf(fp," virtual void save_label( Label** label, uint* block_num );\n");1585}15861587// If this instruction contains a methodOper1588// Declare Node::methods that set operand method's contents1589int method_position = instr->method_position();1590if( method_position != -1 ) {1591// Set the address method, stored in methodOper::_method1592fprintf(fp," virtual void method_set( intptr_t method );\n");1593}15941595// virtual functions for attributes1596//1597// Each instruction attribute results in a virtual call of same name.1598// The ins_cost is not handled here.1599Attribute *attr = instr->_attribs;1600Attribute *avoid_back_to_back_attr = NULL;1601while (attr != NULL) {1602if (strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") == 0) {1603fprintf(fp, " virtual bool is_TrapBasedCheckNode() const { return %s; }\n", attr->_val);1604} else if (strcmp (attr->_ident, "ins_cost") != 0 &&1605strncmp(attr->_ident, "ins_field_", 10) != 0 &&1606// Must match function in node.hpp: return type bool, no prefix "ins_".1607strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") != 0 &&1608strcmp (attr->_ident, "ins_short_branch") != 0) {1609fprintf(fp, " virtual int %s() const { return %s; }\n", attr->_ident, attr->_val);1610}1611if (strcmp(attr->_ident, "ins_avoid_back_to_back") == 0) {1612avoid_back_to_back_attr = attr;1613}1614attr = (Attribute *)attr->_next;1615}16161617// virtual functions for encode and format16181619// Virtual function for evaluating the constant.1620if (instr->is_mach_constant()) {1621fprintf(fp," virtual void eval_constant(Compile* C);\n");1622}16231624// Output the opcode function and the encode function here using the1625// encoding class information in the _insencode slot.1626if ( instr->_insencode ) {1627if (instr->postalloc_expands()) {1628fprintf(fp," virtual bool requires_postalloc_expand() const { return true; }\n");1629fprintf(fp," virtual void postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_);\n");1630} else {1631fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n");1632}1633}16341635// virtual function for getting the size of an instruction1636if ( instr->_size ) {1637fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n");1638}16391640// Return the top-level ideal opcode.1641// Use MachNode::ideal_Opcode() for nodes based on MachNode class1642// if the ideal_Opcode == Op_Node.1643if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||1644strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {1645fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n",1646instr->ideal_Opcode(_globalNames) );1647}16481649if (instr->needs_constant_base() &&1650!instr->is_mach_constant()) { // These inherit the funcion from MachConstantNode.1651fprintf(fp," virtual uint mach_constant_base_node_input() const { ");1652if (instr->is_ideal_call() != Form::invalid_type &&1653instr->is_ideal_call() != Form::JAVA_LEAF) {1654// MachConstantBase goes behind arguments, but before jvms.1655fprintf(fp,"assert(tf() && tf()->domain(), \"\"); return tf()->domain()->cnt();");1656} else {1657fprintf(fp,"return req()-1;");1658}1659fprintf(fp," }\n");1660}16611662// Allow machine-independent optimization, invert the sense of the IF test1663if( instr->is_ideal_if() ) {1664fprintf(fp," virtual void negate() { \n");1665// Identify which operand contains the negate(able) ideal condition code1666int idx = 0;1667instr->_components.reset();1668for( Component *comp; (comp = instr->_components.iter()) != NULL; ) {1669// Check that component is an operand1670Form *form = (Form*)_globalNames[comp->_type];1671OperandForm *opForm = form ? form->is_operand() : NULL;1672if( opForm == NULL ) continue;16731674// Lookup the position of the operand in the instruction.1675if( opForm->is_ideal_bool() ) {1676idx = instr->operand_position(comp->_name, comp->_usedef);1677assert( idx != NameList::Not_in_list, "Did not find component in list that contained it.");1678break;1679}1680}1681fprintf(fp," opnd_array(%d)->negate();\n", idx);1682fprintf(fp," _prob = 1.0f - _prob;\n");1683fprintf(fp," };\n");1684}168516861687// Identify which input register matches the input register.1688uint matching_input = instr->two_address(_globalNames);16891690// Generate the method if it returns != 0 otherwise use MachNode::two_adr()1691if( matching_input != 0 ) {1692fprintf(fp," virtual uint two_adr() const ");1693fprintf(fp,"{ return oper_input_base()");1694for( uint i = 2; i <= matching_input; i++ )1695fprintf(fp," + opnd_array(%d)->num_edges()",i-1);1696fprintf(fp,"; }\n");1697}16981699// Declare cisc_version, if applicable1700// MachNode *cisc_version( int offset /* ,... */ );1701instr->declare_cisc_version(*this, fp);17021703// If there is an explicit peephole rule, build it1704if ( instr->peepholes() != NULL ) {1705fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted);\n");1706}17071708// Output the declaration for number of relocation entries1709if ( instr->reloc(_globalNames) != 0 ) {1710fprintf(fp," virtual int reloc() const;\n");1711}17121713if (instr->alignment() != 1) {1714fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment());1715fprintf(fp," virtual int compute_padding(int current_offset) const;\n");1716}17171718// Starting point for inputs matcher wants.1719// Use MachNode::oper_input_base() for nodes based on MachNode class1720// if the base == 1.1721if ( instr->oper_input_base(_globalNames) != 1 ||1722strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {1723fprintf(fp," virtual uint oper_input_base() const { return %d; }\n",1724instr->oper_input_base(_globalNames));1725}17261727// Make the constructor and following methods 'public:'1728fprintf(fp,"public:\n");17291730// Constructor1731if ( instr->is_ideal_jump() ) {1732fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);1733} else {1734fprintf(fp," %sNode() { ", instr->_ident);1735if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {1736fprintf(fp,"_cisc_RegMask = NULL; ");1737}1738}17391740fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());17411742bool node_flags_set = false;1743// flag: if this instruction matches an ideal 'Copy*' node1744if ( instr->is_ideal_copy() != 0 ) {1745fprintf(fp,"init_flags(Flag_is_Copy");1746node_flags_set = true;1747}17481749// Is an instruction is a constant? If so, get its type1750Form::DataType data_type;1751const char *opType = NULL;1752const char *result = NULL;1753data_type = instr->is_chain_of_constant(_globalNames, opType, result);1754// Check if this instruction is a constant1755if ( data_type != Form::none ) {1756if ( node_flags_set ) {1757fprintf(fp," | Flag_is_Con");1758} else {1759fprintf(fp,"init_flags(Flag_is_Con");1760node_flags_set = true;1761}1762}17631764// flag: if this instruction is cisc alternate1765if ( can_cisc_spill() && instr->is_cisc_alternate() ) {1766if ( node_flags_set ) {1767fprintf(fp," | Flag_is_cisc_alternate");1768} else {1769fprintf(fp,"init_flags(Flag_is_cisc_alternate");1770node_flags_set = true;1771}1772}17731774// flag: if this instruction has short branch form1775if ( instr->has_short_branch_form() ) {1776if ( node_flags_set ) {1777fprintf(fp," | Flag_may_be_short_branch");1778} else {1779fprintf(fp,"init_flags(Flag_may_be_short_branch");1780node_flags_set = true;1781}1782}17831784// flag: if this instruction should not be generated back to back.1785if (avoid_back_to_back_attr != NULL) {1786if (node_flags_set) {1787fprintf(fp," | (%s)", avoid_back_to_back_attr->_val);1788} else {1789fprintf(fp,"init_flags((%s)", avoid_back_to_back_attr->_val);1790node_flags_set = true;1791}1792}17931794// Check if machine instructions that USE memory, but do not DEF memory,1795// depend upon a node that defines memory in machine-independent graph.1796if ( instr->needs_anti_dependence_check(_globalNames) ) {1797if ( node_flags_set ) {1798fprintf(fp," | Flag_needs_anti_dependence_check");1799} else {1800fprintf(fp,"init_flags(Flag_needs_anti_dependence_check");1801node_flags_set = true;1802}1803}18041805// flag: if this instruction is implemented with a call1806if ( instr->_has_call ) {1807if ( node_flags_set ) {1808fprintf(fp," | Flag_has_call");1809} else {1810fprintf(fp,"init_flags(Flag_has_call");1811node_flags_set = true;1812}1813}18141815if ( node_flags_set ) {1816fprintf(fp,"); ");1817}18181819fprintf(fp,"}\n");18201821// size_of, used by base class's clone to obtain the correct size.1822fprintf(fp," virtual uint size_of() const {");1823fprintf(fp, " return sizeof(%sNode);", instr->_ident);1824fprintf(fp, " }\n");18251826// Virtual methods which are only generated to override base class1827if( instr->expands() || instr->needs_projections() ||1828instr->has_temps() ||1829instr->is_mach_constant() ||1830instr->needs_constant_base() ||1831(instr->_matrule != NULL &&1832instr->num_opnds() != instr->num_unique_opnds()) ) {1833fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list, Node* mem);\n");1834}18351836if (instr->is_pinned(_globalNames)) {1837fprintf(fp," virtual bool pinned() const { return ");1838if (instr->is_parm(_globalNames)) {1839fprintf(fp,"_in[0]->pinned();");1840} else {1841fprintf(fp,"true;");1842}1843fprintf(fp," }\n");1844}1845if (instr->is_projection(_globalNames)) {1846fprintf(fp," virtual const Node *is_block_proj() const { return this; }\n");1847}1848if ( instr->num_post_match_opnds() != 01849|| instr->is_chain_of_constant(_globalNames) ) {1850fprintf(fp," friend MachNode *State::MachNodeGenerator(int opcode);\n");1851}1852if ( instr->rematerialize(_globalNames, get_registers()) ) {1853fprintf(fp," // Rematerialize %s\n", instr->_ident);1854}18551856// Declare short branch methods, if applicable1857instr->declare_short_branch_methods(fp);18581859// See if there is an "ins_pipe" declaration for this instruction1860if (instr->_ins_pipe) {1861fprintf(fp," static const Pipeline *pipeline_class();\n");1862fprintf(fp," virtual const Pipeline *pipeline() const;\n");1863}18641865// Generate virtual function for MachNodeX::bottom_type when necessary1866//1867// Note on accuracy: Pointer-types of machine nodes need to be accurate,1868// or else alias analysis on the matched graph may produce bad code.1869// Moreover, the aliasing decisions made on machine-node graph must be1870// no less accurate than those made on the ideal graph, or else the graph1871// may fail to schedule. (Reason: Memory ops which are reordered in1872// the ideal graph might look interdependent in the machine graph,1873// thereby removing degrees of scheduling freedom that the optimizer1874// assumed would be available.)1875//1876// %%% We should handle many of these cases with an explicit ADL clause:1877// instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %}1878if( data_type != Form::none ) {1879// A constant's bottom_type returns a Type containing its constant value18801881// !!!!!1882// Convert all ints, floats, ... to machine-independent TypeXs1883// as is done for pointers1884//1885// Construct appropriate constant type containing the constant value.1886fprintf(fp," virtual const class Type *bottom_type() const {\n");1887switch( data_type ) {1888case Form::idealI:1889fprintf(fp," return TypeInt::make(opnd_array(1)->constant());\n");1890break;1891case Form::idealP:1892case Form::idealN:1893case Form::idealNKlass:1894fprintf(fp," return opnd_array(1)->type();\n");1895break;1896case Form::idealD:1897fprintf(fp," return TypeD::make(opnd_array(1)->constantD());\n");1898break;1899case Form::idealF:1900fprintf(fp," return TypeF::make(opnd_array(1)->constantF());\n");1901break;1902case Form::idealL:1903fprintf(fp," return TypeLong::make(opnd_array(1)->constantL());\n");1904break;1905default:1906assert( false, "Unimplemented()" );1907break;1908}1909fprintf(fp," };\n");1910}1911/* else if ( instr->_matrule && instr->_matrule->_rChild &&1912( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==01913|| strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {1914// !!!!! !!!!!1915// Provide explicit bottom type for conversions to int1916// On Intel the result operand is a stackSlot, untyped.1917fprintf(fp," virtual const class Type *bottom_type() const {");1918fprintf(fp, " return TypeInt::INT;");1919fprintf(fp, " };\n");1920}*/1921else if( instr->is_ideal_copy() &&1922!strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) {1923// !!!!!1924// Special hack for ideal Copy of pointer. Bottom type is oop or not depending on input.1925fprintf(fp," const Type *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n");1926}1927else if( instr->is_ideal_loadPC() ) {1928// LoadPCNode provides the return address of a call to native code.1929// Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM1930// since it is a pointer to an internal VM location and must have a zero offset.1931// Allocation detects derived pointers, in part, by their non-zero offsets.1932fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n");1933}1934else if( instr->is_ideal_box() ) {1935// BoxNode provides the address of a stack slot.1936// Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM1937// This prevent s insert_anti_dependencies from complaining. It will1938// complain if it sees that the pointer base is TypePtr::BOTTOM since1939// it doesn't understand what that might alias.1940fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n");1941}1942else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveP") ) {1943int offset = 1;1944// Special special hack to see if the Cmp? has been incorporated in the conditional move1945MatchNode *rl = instr->_matrule->_rChild->_lChild;1946if( rl && !strcmp(rl->_opType, "Binary") ) {1947MatchNode *rlr = rl->_rChild;1948if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)1949offset = 2;1950}1951// Special hack for ideal CMoveP; ideal type depends on inputs1952fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveP\n",1953offset, offset+1, offset+1);1954}1955else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) {1956int offset = 1;1957// Special special hack to see if the Cmp? has been incorporated in the conditional move1958MatchNode *rl = instr->_matrule->_rChild->_lChild;1959if( rl && !strcmp(rl->_opType, "Binary") ) {1960MatchNode *rlr = rl->_rChild;1961if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)1962offset = 2;1963}1964// Special hack for ideal CMoveN; ideal type depends on inputs1965fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveN\n",1966offset, offset+1, offset+1);1967}1968else if (instr->is_tls_instruction()) {1969// Special hack for tlsLoadP1970fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");1971}1972else if ( instr->is_ideal_if() ) {1973fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");1974}1975else if ( instr->is_ideal_membar() ) {1976fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");1977}19781979// Check where 'ideal_type' must be customized1980/*1981if ( instr->_matrule && instr->_matrule->_rChild &&1982( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==01983|| strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {1984fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");1985}*/19861987// Analyze machine instructions that either USE or DEF memory.1988int memory_operand = instr->memory_operand(_globalNames);1989if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {1990if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {1991fprintf(fp," virtual const TypePtr *adr_type() const;\n");1992}1993fprintf(fp," virtual const MachOper *memory_operand() const;\n");1994}19951996fprintf(fp, "#ifndef PRODUCT\n");19971998// virtual function for generating the user's assembler output1999gen_inst_format(fp, _globalNames,*instr);20002001// Machine independent print functionality for debugging2002fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",2003instr->_ident);20042005fprintf(fp, "#endif\n");20062007// Close definition of this XxxMachNode2008fprintf(fp,"};\n");2009};20102011}20122013void ArchDesc::defineStateClass(FILE *fp) {2014static const char *state__valid = "_rule[index] & 0x1";20152016fprintf(fp,"\n");2017fprintf(fp,"// MACROS to inline and constant fold State::valid(index)...\n");2018fprintf(fp,"// when given a constant 'index' in dfa_<arch>.cpp\n");2019fprintf(fp,"#define STATE__NOT_YET_VALID(index) ");2020fprintf(fp," ( (%s) == 0 )\n", state__valid);2021fprintf(fp,"\n");2022fprintf(fp,"#define STATE__VALID_CHILD(state,index) ");2023fprintf(fp," ( state && (state->%s) )\n", state__valid);2024fprintf(fp,"\n");2025fprintf(fp,2026"//---------------------------State-------------------------------------------\n");2027fprintf(fp,"// State contains an integral cost vector, indexed by machine operand opcodes,\n");2028fprintf(fp,"// a rule vector consisting of machine operand/instruction opcodes, and also\n");2029fprintf(fp,"// indexed by machine operand opcodes, pointers to the children in the label\n");2030fprintf(fp,"// tree generated by the Label routines in ideal nodes (currently limited to\n");2031fprintf(fp,"// two for convenience, but this could change).\n");2032fprintf(fp,"class State : public ResourceObj {\n");2033fprintf(fp,"private:\n");2034fprintf(fp," unsigned int _cost[_LAST_MACH_OPER]; // Costs, indexed by operand opcodes\n");2035fprintf(fp," uint16_t _rule[_LAST_MACH_OPER]; // Rule and validity, indexed by operand opcodes\n");2036fprintf(fp," // Lowest bit encodes validity\n");20372038fprintf(fp,"public:\n");2039fprintf(fp," int _id; // State identifier\n");2040fprintf(fp," Node *_leaf; // Ideal (non-machine-node) leaf of match tree\n");2041fprintf(fp," State *_kids[2]; // Children of state node in label tree\n");2042fprintf(fp,"\n");2043fprintf(fp," State(void);\n");2044fprintf(fp," DEBUG_ONLY( ~State(void); )\n");2045fprintf(fp,"\n");2046fprintf(fp," // Methods created by ADLC and invoked by Reduce\n");2047fprintf(fp," MachOper *MachOperGenerator(int opcode);\n");2048fprintf(fp," MachNode *MachNodeGenerator(int opcode);\n");2049fprintf(fp,"\n");2050fprintf(fp," // Assign a state to a node, definition of method produced by ADLC\n");2051fprintf(fp," bool DFA( int opcode, const Node *ideal );\n");2052fprintf(fp,"\n");2053fprintf(fp," bool valid(uint index) {\n");2054fprintf(fp," return %s;\n", state__valid);2055fprintf(fp," }\n");2056fprintf(fp," unsigned int rule(uint index) {\n");2057fprintf(fp," return _rule[index] >> 1;\n");2058fprintf(fp," }\n");2059fprintf(fp," unsigned int cost(uint index) {\n");2060fprintf(fp," return _cost[index];\n");2061fprintf(fp," }\n");2062fprintf(fp,"\n");2063fprintf(fp,"#ifndef PRODUCT\n");2064fprintf(fp," void dump(); // Debugging prints\n");2065fprintf(fp," void dump(int depth);\n");2066fprintf(fp,"#endif\n");2067if (_dfa_small) {2068// Generate the routine name we'll need2069for (int i = 1; i < _last_opcode; i++) {2070if (_mlistab[i] == NULL) continue;2071fprintf(fp, " void _sub_Op_%s(const Node *n);\n", NodeClassNames[i]);2072}2073}2074fprintf(fp,"};\n");2075fprintf(fp,"\n");2076fprintf(fp,"\n");20772078}207920802081//---------------------------buildMachOperEnum---------------------------------2082// Build enumeration for densely packed operands.2083// This enumeration is used to index into the arrays in the State objects2084// that indicate cost and a successfull rule match.20852086// Information needed to generate the ReduceOp mapping for the DFA2087class OutputMachOperands : public OutputMap {2088public:2089OutputMachOperands(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)2090: OutputMap(hpp, cpp, globals, AD, "MachOperands") {};20912092void declaration() { }2093void definition() { fprintf(_cpp, "enum MachOperands {\n"); }2094void closing() { fprintf(_cpp, " _LAST_MACH_OPER\n");2095OutputMap::closing();2096}2097void map(OpClassForm &opc) {2098const char* opc_ident_to_upper = _AD.machOperEnum(opc._ident);2099fprintf(_cpp, " %s", opc_ident_to_upper);2100delete[] opc_ident_to_upper;2101}2102void map(OperandForm &oper) {2103const char* oper_ident_to_upper = _AD.machOperEnum(oper._ident);2104fprintf(_cpp, " %s", oper_ident_to_upper);2105delete[] oper_ident_to_upper;2106}2107void map(char *name) {2108const char* name_to_upper = _AD.machOperEnum(name);2109fprintf(_cpp, " %s", name_to_upper);2110delete[] name_to_upper;2111}21122113bool do_instructions() { return false; }2114void map(InstructForm &inst){ assert( false, "ShouldNotCallThis()"); }2115};211621172118void ArchDesc::buildMachOperEnum(FILE *fp_hpp) {2119// Construct the table for MachOpcodes2120OutputMachOperands output_mach_operands(fp_hpp, fp_hpp, _globalNames, *this);2121build_map(output_mach_operands);2122}212321242125//---------------------------buildMachEnum----------------------------------2126// Build enumeration for all MachOpers and all MachNodes21272128// Information needed to generate the ReduceOp mapping for the DFA2129class OutputMachOpcodes : public OutputMap {2130int begin_inst_chain_rule;2131int end_inst_chain_rule;2132int begin_rematerialize;2133int end_rematerialize;2134int end_instructions;2135public:2136OutputMachOpcodes(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)2137: OutputMap(hpp, cpp, globals, AD, "MachOpcodes"),2138begin_inst_chain_rule(-1), end_inst_chain_rule(-1),2139begin_rematerialize(-1), end_rematerialize(-1),2140end_instructions(-1)2141{};21422143void declaration() { }2144void definition() { fprintf(_cpp, "enum MachOpcodes {\n"); }2145void closing() {2146if( begin_inst_chain_rule != -1 )2147fprintf(_cpp, " _BEGIN_INST_CHAIN_RULE = %d,\n", begin_inst_chain_rule);2148if( end_inst_chain_rule != -1 )2149fprintf(_cpp, " _END_INST_CHAIN_RULE = %d,\n", end_inst_chain_rule);2150if( begin_rematerialize != -1 )2151fprintf(_cpp, " _BEGIN_REMATERIALIZE = %d,\n", begin_rematerialize);2152if( end_rematerialize != -1 )2153fprintf(_cpp, " _END_REMATERIALIZE = %d,\n", end_rematerialize);2154// always execute since do_instructions() is true, and avoids trailing comma2155fprintf(_cpp, " _last_Mach_Node = %d \n", end_instructions);2156OutputMap::closing();2157}2158void map(OpClassForm &opc) { fprintf(_cpp, " %s_rule", opc._ident ); }2159void map(OperandForm &oper) { fprintf(_cpp, " %s_rule", oper._ident ); }2160void map(char *name) { if (name) fprintf(_cpp, " %s_rule", name);2161else fprintf(_cpp, " 0"); }2162void map(InstructForm &inst) {fprintf(_cpp, " %s_rule", inst._ident ); }21632164void record_position(OutputMap::position place, int idx ) {2165switch(place) {2166case OutputMap::BEGIN_INST_CHAIN_RULES :2167begin_inst_chain_rule = idx;2168break;2169case OutputMap::END_INST_CHAIN_RULES :2170end_inst_chain_rule = idx;2171break;2172case OutputMap::BEGIN_REMATERIALIZE :2173begin_rematerialize = idx;2174break;2175case OutputMap::END_REMATERIALIZE :2176end_rematerialize = idx;2177break;2178case OutputMap::END_INSTRUCTIONS :2179end_instructions = idx;2180break;2181default:2182break;2183}2184}2185};218621872188void ArchDesc::buildMachOpcodesEnum(FILE *fp_hpp) {2189// Construct the table for MachOpcodes2190OutputMachOpcodes output_mach_opcodes(fp_hpp, fp_hpp, _globalNames, *this);2191build_map(output_mach_opcodes);2192}219321942195// Generate an enumeration of the pipeline states, and both2196// the functional units (resources) and the masks for2197// specifying resources2198void ArchDesc::build_pipeline_enums(FILE *fp_hpp) {2199int stagelen = (int)strlen("undefined");2200int stagenum = 0;22012202if (_pipeline) { // Find max enum string length2203const char *stage;2204for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) {2205int len = (int)strlen(stage);2206if (stagelen < len) stagelen = len;2207}2208}22092210// Generate a list of stages2211fprintf(fp_hpp, "\n");2212fprintf(fp_hpp, "// Pipeline Stages\n");2213fprintf(fp_hpp, "enum machPipelineStages {\n");2214fprintf(fp_hpp, " stage_%-*s = 0,\n", stagelen, "undefined");22152216if( _pipeline ) {2217const char *stage;2218for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; )2219fprintf(fp_hpp, " stage_%-*s = %d,\n", stagelen, stage, ++stagenum);2220}22212222fprintf(fp_hpp, " stage_%-*s = %d\n", stagelen, "count", stagenum);2223fprintf(fp_hpp, "};\n");22242225fprintf(fp_hpp, "\n");2226fprintf(fp_hpp, "// Pipeline Resources\n");2227fprintf(fp_hpp, "enum machPipelineResources {\n");2228int rescount = 0;22292230if( _pipeline ) {2231const char *resource;2232int reslen = 0;22332234// Generate a list of resources, and masks2235for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {2236int len = (int)strlen(resource);2237if (reslen < len)2238reslen = len;2239}22402241for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {2242const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();2243int mask = resform->mask();2244if ((mask & (mask-1)) == 0)2245fprintf(fp_hpp, " resource_%-*s = %d,\n", reslen, resource, rescount++);2246}2247fprintf(fp_hpp, "\n");2248for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {2249const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();2250fprintf(fp_hpp, " res_mask_%-*s = 0x%08x,\n", reslen, resource, resform->mask());2251}2252fprintf(fp_hpp, "\n");2253}2254fprintf(fp_hpp, " resource_count = %d\n", rescount);2255fprintf(fp_hpp, "};\n");2256}225722582259