Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/output_h.cpp
32285 views
/*1* Copyright (c) 1998, 2014, 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 _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 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 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 <=744#ifdef SPARC74564746#else74732748#endif749) {750fprintf(fp_hpp, "protected:\n");751fprintf(fp_hpp, " %s _mask;\n\n", _pipeline->_maxcycleused <= 32 ? "uint" : "uint64_t" );752fprintf(fp_hpp, "public:\n");753fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : _mask(0) {}\n\n");754if (_pipeline->_maxcycleused <= 32)755fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask) : _mask(mask) {}\n\n");756else {757fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n");758fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n");759}760fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");761fprintf(fp_hpp, " _mask = in._mask;\n");762fprintf(fp_hpp, " return *this;\n");763fprintf(fp_hpp, " }\n\n");764fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");765fprintf(fp_hpp, " return ((_mask & in2._mask) != 0);\n");766fprintf(fp_hpp, " }\n\n");767fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");768fprintf(fp_hpp, " _mask <<= n;\n");769fprintf(fp_hpp, " return *this;\n");770fprintf(fp_hpp, " }\n\n");771fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &in2) {\n");772fprintf(fp_hpp, " _mask |= in2._mask;\n");773fprintf(fp_hpp, " }\n\n");774fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");775fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");776}777else {778fprintf(fp_hpp, "protected:\n");779uint masklen = (_pipeline->_maxcycleused + 31) >> 5;780uint l;781fprintf(fp_hpp, " uint ");782for (l = 1; l <= masklen; l++)783fprintf(fp_hpp, "_mask%d%s", l, l < masklen ? ", " : ";\n\n");784fprintf(fp_hpp, "public:\n");785fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : ");786for (l = 1; l <= masklen; l++)787fprintf(fp_hpp, "_mask%d(0)%s", l, l < masklen ? ", " : " {}\n\n");788fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(");789for (l = 1; l <= masklen; l++)790fprintf(fp_hpp, "uint mask%d%s", l, l < masklen ? ", " : ") : ");791for (l = 1; l <= masklen; l++)792fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n");793794fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");795for (l = 1; l <= masklen; l++)796fprintf(fp_hpp, " _mask%d = in._mask%d;\n", l, l);797fprintf(fp_hpp, " return *this;\n");798fprintf(fp_hpp, " }\n\n");799fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n");800fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask out;\n");801for (l = 1; l <= masklen; l++)802fprintf(fp_hpp, " out._mask%d = _mask%d & in2._mask%d;\n", l, l, l);803fprintf(fp_hpp, " return out;\n");804fprintf(fp_hpp, " }\n\n");805fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");806fprintf(fp_hpp, " return (");807for (l = 1; l <= masklen; l++)808fprintf(fp_hpp, "((_mask%d & in2._mask%d) != 0)%s", l, l, l < masklen ? " || " : "");809fprintf(fp_hpp, ") ? true : false;\n");810fprintf(fp_hpp, " }\n\n");811fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");812fprintf(fp_hpp, " if (n >= 32)\n");813fprintf(fp_hpp, " do {\n ");814for (l = masklen; l > 1; l--)815fprintf(fp_hpp, " _mask%d = _mask%d;", l, l-1);816fprintf(fp_hpp, " _mask%d = 0;\n", 1);817fprintf(fp_hpp, " } while ((n -= 32) >= 32);\n\n");818fprintf(fp_hpp, " if (n > 0) {\n");819fprintf(fp_hpp, " uint m = 32 - n;\n");820fprintf(fp_hpp, " uint mask = (1 << n) - 1;\n");821fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n;\n", 2, 1, 1);822for (l = 2; l < masklen; l++) {823fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n; _mask%d |= temp%d;\n", l+1, l, l, l, l);824}825fprintf(fp_hpp, " _mask%d <<= n; _mask%d |= temp%d;\n", masklen, masklen, masklen);826fprintf(fp_hpp, " }\n");827828fprintf(fp_hpp, " return *this;\n");829fprintf(fp_hpp, " }\n\n");830fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &);\n\n");831fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");832fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");833}834835fprintf(fp_hpp, " friend class Pipeline_Use;\n\n");836fprintf(fp_hpp, " friend class Pipeline_Use_Element;\n\n");837fprintf(fp_hpp, "};\n\n");838839uint rescount = 0;840const char *resource;841842for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {843int mask = _pipeline->_resdict[resource]->is_resource()->mask();844if ((mask & (mask-1)) == 0)845rescount++;846}847848fprintf(fp_hpp, "// Pipeline_Use_Element Class\n");849fprintf(fp_hpp, "class Pipeline_Use_Element {\n");850fprintf(fp_hpp, "protected:\n");851fprintf(fp_hpp, " // Mask of used functional units\n");852fprintf(fp_hpp, " uint _used;\n\n");853fprintf(fp_hpp, " // Lower and upper bound of functional unit number range\n");854fprintf(fp_hpp, " uint _lb, _ub;\n\n");855fprintf(fp_hpp, " // Indicates multiple functionals units available\n");856fprintf(fp_hpp, " bool _multiple;\n\n");857fprintf(fp_hpp, " // Mask of specific used cycles\n");858fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask _mask;\n\n");859fprintf(fp_hpp, "public:\n");860fprintf(fp_hpp, " Pipeline_Use_Element() {}\n\n");861fprintf(fp_hpp, " Pipeline_Use_Element(uint used, uint lb, uint ub, bool multiple, Pipeline_Use_Cycle_Mask mask)\n");862fprintf(fp_hpp, " : _used(used), _lb(lb), _ub(ub), _multiple(multiple), _mask(mask) {}\n\n");863fprintf(fp_hpp, " uint used() const { return _used; }\n\n");864fprintf(fp_hpp, " uint lowerBound() const { return _lb; }\n\n");865fprintf(fp_hpp, " uint upperBound() const { return _ub; }\n\n");866fprintf(fp_hpp, " bool multiple() const { return _multiple; }\n\n");867fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask mask() const { return _mask; }\n\n");868fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Element &in2) const {\n");869fprintf(fp_hpp, " return ((_used & in2._used) != 0 && _mask.overlaps(in2._mask));\n");870fprintf(fp_hpp, " }\n\n");871fprintf(fp_hpp, " void step(uint cycles) {\n");872fprintf(fp_hpp, " _used = 0;\n");873fprintf(fp_hpp, " _mask <<= cycles;\n");874fprintf(fp_hpp, " }\n\n");875fprintf(fp_hpp, " friend class Pipeline_Use;\n");876fprintf(fp_hpp, "};\n\n");877878fprintf(fp_hpp, "// Pipeline_Use Class\n");879fprintf(fp_hpp, "class Pipeline_Use {\n");880fprintf(fp_hpp, "protected:\n");881fprintf(fp_hpp, " // These resources can be used\n");882fprintf(fp_hpp, " uint _resources_used;\n\n");883fprintf(fp_hpp, " // These resources are used; excludes multiple choice functional units\n");884fprintf(fp_hpp, " uint _resources_used_exclusively;\n\n");885fprintf(fp_hpp, " // Number of elements\n");886fprintf(fp_hpp, " uint _count;\n\n");887fprintf(fp_hpp, " // This is the array of Pipeline_Use_Elements\n");888fprintf(fp_hpp, " Pipeline_Use_Element * _elements;\n\n");889fprintf(fp_hpp, "public:\n");890fprintf(fp_hpp, " Pipeline_Use(uint resources_used, uint resources_used_exclusively, uint count, Pipeline_Use_Element *elements)\n");891fprintf(fp_hpp, " : _resources_used(resources_used)\n");892fprintf(fp_hpp, " , _resources_used_exclusively(resources_used_exclusively)\n");893fprintf(fp_hpp, " , _count(count)\n");894fprintf(fp_hpp, " , _elements(elements)\n");895fprintf(fp_hpp, " {}\n\n");896fprintf(fp_hpp, " uint resourcesUsed() const { return _resources_used; }\n\n");897fprintf(fp_hpp, " uint resourcesUsedExclusively() const { return _resources_used_exclusively; }\n\n");898fprintf(fp_hpp, " uint count() const { return _count; }\n\n");899fprintf(fp_hpp, " Pipeline_Use_Element * element(uint i) const { return &_elements[i]; }\n\n");900fprintf(fp_hpp, " uint full_latency(uint delay, const Pipeline_Use &pred) const;\n\n");901fprintf(fp_hpp, " void add_usage(const Pipeline_Use &pred);\n\n");902fprintf(fp_hpp, " void reset() {\n");903fprintf(fp_hpp, " _resources_used = _resources_used_exclusively = 0;\n");904fprintf(fp_hpp, " };\n\n");905fprintf(fp_hpp, " void step(uint cycles) {\n");906fprintf(fp_hpp, " reset();\n");907fprintf(fp_hpp, " for (uint i = 0; i < %d; i++)\n",908rescount);909fprintf(fp_hpp, " (&_elements[i])->step(cycles);\n");910fprintf(fp_hpp, " };\n\n");911fprintf(fp_hpp, " static const Pipeline_Use elaborated_use;\n");912fprintf(fp_hpp, " static const Pipeline_Use_Element elaborated_elements[%d];\n\n",913rescount);914fprintf(fp_hpp, " friend class Pipeline;\n");915fprintf(fp_hpp, "};\n\n");916917fprintf(fp_hpp, "// Pipeline Class\n");918fprintf(fp_hpp, "class Pipeline {\n");919fprintf(fp_hpp, "public:\n");920921fprintf(fp_hpp, " static bool enabled() { return %s; }\n\n",922_pipeline ? "true" : "false" );923924assert( _pipeline->_maxInstrsPerBundle &&925( _pipeline->_instrUnitSize || _pipeline->_bundleUnitSize) &&926_pipeline->_instrFetchUnitSize &&927_pipeline->_instrFetchUnits,928"unspecified pipeline architecture units");929930uint unitSize = _pipeline->_instrUnitSize ? _pipeline->_instrUnitSize : _pipeline->_bundleUnitSize;931932fprintf(fp_hpp, " enum {\n");933fprintf(fp_hpp, " _variable_size_instructions = %d,\n",934_pipeline->_variableSizeInstrs ? 1 : 0);935fprintf(fp_hpp, " _fixed_size_instructions = %d,\n",936_pipeline->_variableSizeInstrs ? 0 : 1);937fprintf(fp_hpp, " _branch_has_delay_slot = %d,\n",938_pipeline->_branchHasDelaySlot ? 1 : 0);939fprintf(fp_hpp, " _max_instrs_per_bundle = %d,\n",940_pipeline->_maxInstrsPerBundle);941fprintf(fp_hpp, " _max_bundles_per_cycle = %d,\n",942_pipeline->_maxBundlesPerCycle);943fprintf(fp_hpp, " _max_instrs_per_cycle = %d\n",944_pipeline->_maxBundlesPerCycle * _pipeline->_maxInstrsPerBundle);945fprintf(fp_hpp, " };\n\n");946947fprintf(fp_hpp, " static bool instr_has_unit_size() { return %s; }\n\n",948_pipeline->_instrUnitSize != 0 ? "true" : "false" );949if( _pipeline->_bundleUnitSize != 0 )950if( _pipeline->_instrUnitSize != 0 )951fprintf(fp_hpp, "// Individual Instructions may be bundled together by the hardware\n\n");952else953fprintf(fp_hpp, "// Instructions exist only in bundles\n\n");954else955fprintf(fp_hpp, "// Bundling is not supported\n\n");956if( _pipeline->_instrUnitSize != 0 )957fprintf(fp_hpp, " // Size of an instruction\n");958else959fprintf(fp_hpp, " // Size of an individual instruction does not exist - unsupported\n");960fprintf(fp_hpp, " static uint instr_unit_size() {");961if( _pipeline->_instrUnitSize == 0 )962fprintf(fp_hpp, " assert( false, \"Instructions are only in bundles\" );");963fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_instrUnitSize);964965if( _pipeline->_bundleUnitSize != 0 )966fprintf(fp_hpp, " // Size of a bundle\n");967else968fprintf(fp_hpp, " // Bundles do not exist - unsupported\n");969fprintf(fp_hpp, " static uint bundle_unit_size() {");970if( _pipeline->_bundleUnitSize == 0 )971fprintf(fp_hpp, " assert( false, \"Bundles are not supported\" );");972fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_bundleUnitSize);973974fprintf(fp_hpp, " static bool requires_bundling() { return %s; }\n\n",975_pipeline->_bundleUnitSize != 0 && _pipeline->_instrUnitSize == 0 ? "true" : "false" );976977fprintf(fp_hpp, "private:\n");978fprintf(fp_hpp, " Pipeline(); // Not a legal constructor\n");979fprintf(fp_hpp, "\n");980fprintf(fp_hpp, " const unsigned char _read_stage_count;\n");981fprintf(fp_hpp, " const unsigned char _write_stage;\n");982fprintf(fp_hpp, " const unsigned char _fixed_latency;\n");983fprintf(fp_hpp, " const unsigned char _instruction_count;\n");984fprintf(fp_hpp, " const bool _has_fixed_latency;\n");985fprintf(fp_hpp, " const bool _has_branch_delay;\n");986fprintf(fp_hpp, " const bool _has_multiple_bundles;\n");987fprintf(fp_hpp, " const bool _force_serialization;\n");988fprintf(fp_hpp, " const bool _may_have_no_code;\n");989fprintf(fp_hpp, " const enum machPipelineStages * const _read_stages;\n");990fprintf(fp_hpp, " const enum machPipelineStages * const _resource_stage;\n");991fprintf(fp_hpp, " const uint * const _resource_cycles;\n");992fprintf(fp_hpp, " const Pipeline_Use _resource_use;\n");993fprintf(fp_hpp, "\n");994fprintf(fp_hpp, "public:\n");995fprintf(fp_hpp, " Pipeline(uint write_stage,\n");996fprintf(fp_hpp, " uint count,\n");997fprintf(fp_hpp, " bool has_fixed_latency,\n");998fprintf(fp_hpp, " uint fixed_latency,\n");999fprintf(fp_hpp, " uint instruction_count,\n");1000fprintf(fp_hpp, " bool has_branch_delay,\n");1001fprintf(fp_hpp, " bool has_multiple_bundles,\n");1002fprintf(fp_hpp, " bool force_serialization,\n");1003fprintf(fp_hpp, " bool may_have_no_code,\n");1004fprintf(fp_hpp, " enum machPipelineStages * const dst,\n");1005fprintf(fp_hpp, " enum machPipelineStages * const stage,\n");1006fprintf(fp_hpp, " uint * const cycles,\n");1007fprintf(fp_hpp, " Pipeline_Use resource_use)\n");1008fprintf(fp_hpp, " : _write_stage(write_stage)\n");1009fprintf(fp_hpp, " , _read_stage_count(count)\n");1010fprintf(fp_hpp, " , _has_fixed_latency(has_fixed_latency)\n");1011fprintf(fp_hpp, " , _fixed_latency(fixed_latency)\n");1012fprintf(fp_hpp, " , _read_stages(dst)\n");1013fprintf(fp_hpp, " , _resource_stage(stage)\n");1014fprintf(fp_hpp, " , _resource_cycles(cycles)\n");1015fprintf(fp_hpp, " , _resource_use(resource_use)\n");1016fprintf(fp_hpp, " , _instruction_count(instruction_count)\n");1017fprintf(fp_hpp, " , _has_branch_delay(has_branch_delay)\n");1018fprintf(fp_hpp, " , _has_multiple_bundles(has_multiple_bundles)\n");1019fprintf(fp_hpp, " , _force_serialization(force_serialization)\n");1020fprintf(fp_hpp, " , _may_have_no_code(may_have_no_code)\n");1021fprintf(fp_hpp, " {};\n");1022fprintf(fp_hpp, "\n");1023fprintf(fp_hpp, " uint writeStage() const {\n");1024fprintf(fp_hpp, " return (_write_stage);\n");1025fprintf(fp_hpp, " }\n");1026fprintf(fp_hpp, "\n");1027fprintf(fp_hpp, " enum machPipelineStages readStage(int ndx) const {\n");1028fprintf(fp_hpp, " return (ndx < _read_stage_count ? _read_stages[ndx] : stage_undefined);");1029fprintf(fp_hpp, " }\n\n");1030fprintf(fp_hpp, " uint resourcesUsed() const {\n");1031fprintf(fp_hpp, " return _resource_use.resourcesUsed();\n }\n\n");1032fprintf(fp_hpp, " uint resourcesUsedExclusively() const {\n");1033fprintf(fp_hpp, " return _resource_use.resourcesUsedExclusively();\n }\n\n");1034fprintf(fp_hpp, " bool hasFixedLatency() const {\n");1035fprintf(fp_hpp, " return (_has_fixed_latency);\n }\n\n");1036fprintf(fp_hpp, " uint fixedLatency() const {\n");1037fprintf(fp_hpp, " return (_fixed_latency);\n }\n\n");1038fprintf(fp_hpp, " uint functional_unit_latency(uint start, const Pipeline *pred) const;\n\n");1039fprintf(fp_hpp, " uint operand_latency(uint opnd, const Pipeline *pred) const;\n\n");1040fprintf(fp_hpp, " const Pipeline_Use& resourceUse() const {\n");1041fprintf(fp_hpp, " return (_resource_use); }\n\n");1042fprintf(fp_hpp, " const Pipeline_Use_Element * resourceUseElement(uint i) const {\n");1043fprintf(fp_hpp, " return (&_resource_use._elements[i]); }\n\n");1044fprintf(fp_hpp, " uint resourceUseCount() const {\n");1045fprintf(fp_hpp, " return (_resource_use._count); }\n\n");1046fprintf(fp_hpp, " uint instructionCount() const {\n");1047fprintf(fp_hpp, " return (_instruction_count); }\n\n");1048fprintf(fp_hpp, " bool hasBranchDelay() const {\n");1049fprintf(fp_hpp, " return (_has_branch_delay); }\n\n");1050fprintf(fp_hpp, " bool hasMultipleBundles() const {\n");1051fprintf(fp_hpp, " return (_has_multiple_bundles); }\n\n");1052fprintf(fp_hpp, " bool forceSerialization() const {\n");1053fprintf(fp_hpp, " return (_force_serialization); }\n\n");1054fprintf(fp_hpp, " bool mayHaveNoCode() const {\n");1055fprintf(fp_hpp, " return (_may_have_no_code); }\n\n");1056fprintf(fp_hpp, "//const Pipeline_Use_Cycle_Mask& resourceUseMask(int resource) const {\n");1057fprintf(fp_hpp, "// return (_resource_use_masks[resource]); }\n\n");1058fprintf(fp_hpp, "\n#ifndef PRODUCT\n");1059fprintf(fp_hpp, " static const char * stageName(uint i);\n");1060fprintf(fp_hpp, "#endif\n");1061fprintf(fp_hpp, "};\n\n");10621063fprintf(fp_hpp, "// Bundle class\n");1064fprintf(fp_hpp, "class Bundle {\n");10651066uint mshift = 0;1067for (uint msize = _pipeline->_maxInstrsPerBundle * _pipeline->_maxBundlesPerCycle; msize != 0; msize >>= 1)1068mshift++;10691070uint rshift = rescount;10711072fprintf(fp_hpp, "protected:\n");1073fprintf(fp_hpp, " enum {\n");1074fprintf(fp_hpp, " _unused_delay = 0x%x,\n", 0);1075fprintf(fp_hpp, " _use_nop_delay = 0x%x,\n", 1);1076fprintf(fp_hpp, " _use_unconditional_delay = 0x%x,\n", 2);1077fprintf(fp_hpp, " _use_conditional_delay = 0x%x,\n", 3);1078fprintf(fp_hpp, " _used_in_conditional_delay = 0x%x,\n", 4);1079fprintf(fp_hpp, " _used_in_unconditional_delay = 0x%x,\n", 5);1080fprintf(fp_hpp, " _used_in_all_conditional_delays = 0x%x,\n", 6);1081fprintf(fp_hpp, "\n");1082fprintf(fp_hpp, " _use_delay = 0x%x,\n", 3);1083fprintf(fp_hpp, " _used_in_delay = 0x%x\n", 4);1084fprintf(fp_hpp, " };\n\n");1085fprintf(fp_hpp, " uint _flags : 3,\n");1086fprintf(fp_hpp, " _starts_bundle : 1,\n");1087fprintf(fp_hpp, " _instr_count : %d,\n", mshift);1088fprintf(fp_hpp, " _resources_used : %d;\n", rshift);1089fprintf(fp_hpp, "public:\n");1090fprintf(fp_hpp, " Bundle() : _flags(_unused_delay), _starts_bundle(0), _instr_count(0), _resources_used(0) {}\n\n");1091fprintf(fp_hpp, " void set_instr_count(uint i) { _instr_count = i; }\n");1092fprintf(fp_hpp, " void set_resources_used(uint i) { _resources_used = i; }\n");1093fprintf(fp_hpp, " void clear_usage() { _flags = _unused_delay; }\n");1094fprintf(fp_hpp, " void set_starts_bundle() { _starts_bundle = true; }\n");10951096fprintf(fp_hpp, " uint flags() const { return (_flags); }\n");1097fprintf(fp_hpp, " uint instr_count() const { return (_instr_count); }\n");1098fprintf(fp_hpp, " uint resources_used() const { return (_resources_used); }\n");1099fprintf(fp_hpp, " bool starts_bundle() const { return (_starts_bundle != 0); }\n");11001101fprintf(fp_hpp, " void set_use_nop_delay() { _flags = _use_nop_delay; }\n");1102fprintf(fp_hpp, " void set_use_unconditional_delay() { _flags = _use_unconditional_delay; }\n");1103fprintf(fp_hpp, " void set_use_conditional_delay() { _flags = _use_conditional_delay; }\n");1104fprintf(fp_hpp, " void set_used_in_unconditional_delay() { _flags = _used_in_unconditional_delay; }\n");1105fprintf(fp_hpp, " void set_used_in_conditional_delay() { _flags = _used_in_conditional_delay; }\n");1106fprintf(fp_hpp, " void set_used_in_all_conditional_delays() { _flags = _used_in_all_conditional_delays; }\n");11071108fprintf(fp_hpp, " bool use_nop_delay() { return (_flags == _use_nop_delay); }\n");1109fprintf(fp_hpp, " bool use_unconditional_delay() { return (_flags == _use_unconditional_delay); }\n");1110fprintf(fp_hpp, " bool use_conditional_delay() { return (_flags == _use_conditional_delay); }\n");1111fprintf(fp_hpp, " bool used_in_unconditional_delay() { return (_flags == _used_in_unconditional_delay); }\n");1112fprintf(fp_hpp, " bool used_in_conditional_delay() { return (_flags == _used_in_conditional_delay); }\n");1113fprintf(fp_hpp, " bool used_in_all_conditional_delays() { return (_flags == _used_in_all_conditional_delays); }\n");1114fprintf(fp_hpp, " bool use_delay() { return ((_flags & _use_delay) != 0); }\n");1115fprintf(fp_hpp, " bool used_in_delay() { return ((_flags & _used_in_delay) != 0); }\n\n");11161117fprintf(fp_hpp, " enum {\n");1118fprintf(fp_hpp, " _nop_count = %d\n",1119_pipeline->_nopcnt);1120fprintf(fp_hpp, " };\n\n");1121fprintf(fp_hpp, " static void initialize_nops(MachNode *nop_list[%d], Compile* C);\n\n",1122_pipeline->_nopcnt);1123fprintf(fp_hpp, "#ifndef PRODUCT\n");1124fprintf(fp_hpp, " void dump(outputStream *st = tty) const;\n");1125fprintf(fp_hpp, "#endif\n");1126fprintf(fp_hpp, "};\n\n");11271128// const char *classname;1129// for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) {1130// PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass();1131// fprintf(fp_hpp, "// Pipeline Class Instance for \"%s\"\n", classname);1132// }1133}11341135//------------------------------declareClasses---------------------------------1136// Construct the class hierarchy of MachNode classes from the instruction &1137// operand lists1138void ArchDesc::declareClasses(FILE *fp) {11391140// Declare an array containing the machine register names, strings.1141declareRegNames(fp, _register);11421143// Declare an array containing the machine register encoding values1144declareRegEncodes(fp, _register);11451146// Generate declarations for the total number of operands1147fprintf(fp,"\n");1148fprintf(fp,"// Total number of operands defined in architecture definition\n");1149int num_operands = 0;1150OperandForm *op;1151for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != NULL; ) {1152// Ensure this is a machine-world instruction1153if (op->ideal_only()) continue;11541155++num_operands;1156}1157int first_operand_class = num_operands;1158OpClassForm *opc;1159for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != NULL; ) {1160// Ensure this is a machine-world instruction1161if (opc->ideal_only()) continue;11621163++num_operands;1164}1165fprintf(fp,"#define FIRST_OPERAND_CLASS %d\n", first_operand_class);1166fprintf(fp,"#define NUM_OPERANDS %d\n", num_operands);1167fprintf(fp,"\n");1168// Generate declarations for the total number of instructions1169fprintf(fp,"// Total number of instructions defined in architecture definition\n");1170fprintf(fp,"#define NUM_INSTRUCTIONS %d\n",instructFormCount());117111721173// Generate Machine Classes for each operand defined in AD file1174fprintf(fp,"\n");1175fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n");1176// Iterate through all operands1177_operands.reset();1178OperandForm *oper;1179for( ; (oper = (OperandForm*)_operands.iter()) != NULL;) {1180// Ensure this is a machine-world instruction1181if (oper->ideal_only() ) continue;1182// The declaration of labelOper is in machine-independent file: machnode1183if ( strcmp(oper->_ident,"label") == 0 ) continue;1184// The declaration of methodOper is in machine-independent file: machnode1185if ( strcmp(oper->_ident,"method") == 0 ) continue;11861187// Build class definition for this operand1188fprintf(fp,"\n");1189fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident);1190fprintf(fp,"private:\n");1191// Operand definitions that depend upon number of input edges1192{1193uint num_edges = oper->num_edges(_globalNames);1194if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;}1195fprintf(fp," virtual uint num_edges() const { return %d; }\n",1196num_edges );1197}1198if( num_edges > 0 ) {1199in_RegMask(fp);1200}1201}12021203// Support storing constants inside the MachOper1204declareConstStorage(fp,_globalNames,oper);12051206// Support storage of the condition codes1207if( oper->is_ideal_bool() ) {1208fprintf(fp," virtual int ccode() const { \n");1209fprintf(fp," switch (_c0) {\n");1210fprintf(fp," case BoolTest::eq : return equal();\n");1211fprintf(fp," case BoolTest::gt : return greater();\n");1212fprintf(fp," case BoolTest::lt : return less();\n");1213fprintf(fp," case BoolTest::ne : return not_equal();\n");1214fprintf(fp," case BoolTest::le : return less_equal();\n");1215fprintf(fp," case BoolTest::ge : return greater_equal();\n");1216fprintf(fp," case BoolTest::overflow : return overflow();\n");1217fprintf(fp," case BoolTest::no_overflow: return no_overflow();\n");1218fprintf(fp," default : ShouldNotReachHere(); return 0;\n");1219fprintf(fp," }\n");1220fprintf(fp," };\n");1221}12221223// Support storage of the condition codes1224if( oper->is_ideal_bool() ) {1225fprintf(fp," virtual void negate() { \n");1226fprintf(fp," _c0 = (BoolTest::mask)((int)_c0^0x4); \n");1227fprintf(fp," };\n");1228}12291230// Declare constructor.1231// Parameters start with condition code, then all other constants1232//1233// (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)1234// (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }1235//1236Form::DataType constant_type = oper->simple_type(_globalNames);1237defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames),1238oper->_components, oper->is_ideal_bool(),1239constant_type, _globalNames);12401241// Clone function1242fprintf(fp," virtual MachOper *clone(Compile* C) const;\n");12431244// Support setting a spill offset into a constant operand.1245// We only support setting an 'int' offset, while in the1246// LP64 build spill offsets are added with an AddP which1247// requires a long constant. Thus we don't support spilling1248// in frames larger than 4Gig.1249if( oper->has_conI(_globalNames) ||1250oper->has_conL(_globalNames) )1251fprintf(fp, " virtual void set_con( jint c0 ) { _c0 = c0; }\n");12521253// virtual functions for encoding and format1254// fprintf(fp," virtual void encode() const {\n %s }\n",1255// (oper->_encrule)?(oper->_encrule->_encrule):"");1256// Check the interface type, and generate the correct query functions1257// encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER.12581259fprintf(fp," virtual uint opcode() const { return %s; }\n",1260machOperEnum(oper->_ident));12611262// virtual function to look up ideal return type of machine instruction1263//1264// (1) virtual const Type *type() const { return .....; }1265//1266if ((oper->_matrule) && (oper->_matrule->_lChild == NULL) &&1267(oper->_matrule->_rChild == NULL)) {1268unsigned int position = 0;1269const char *opret, *opname, *optype;1270oper->_matrule->base_operand(position,_globalNames,opret,opname,optype);1271fprintf(fp," virtual const Type *type() const {");1272const char *type = getIdealType(optype);1273if( type != NULL ) {1274Form::DataType data_type = oper->is_base_constant(_globalNames);1275// Check if we are an ideal pointer type1276if( data_type == Form::idealP || data_type == Form::idealN || data_type == Form::idealNKlass ) {1277// Return the ideal type we already have: <TypePtr *>1278fprintf(fp," return _c0;");1279} else {1280// Return the appropriate bottom type1281fprintf(fp," return %s;", getIdealType(optype));1282}1283} else {1284fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;");1285}1286fprintf(fp," }\n");1287} else {1288// Check for user-defined stack slots, based upon sRegX1289Form::DataType data_type = oper->is_user_name_for_sReg();1290if( data_type != Form::none ){1291const char *type = NULL;1292switch( data_type ) {1293case Form::idealI: type = "TypeInt::INT"; break;1294case Form::idealP: type = "TypePtr::BOTTOM";break;1295case Form::idealF: type = "Type::FLOAT"; break;1296case Form::idealD: type = "Type::DOUBLE"; break;1297case Form::idealL: type = "TypeLong::LONG"; break;1298case Form::none: // fall through1299default:1300assert( false, "No support for this type of stackSlot");1301}1302fprintf(fp," virtual const Type *type() const { return %s; } // stackSlotX\n", type);1303}1304}130513061307//1308// virtual functions for defining the encoding interface.1309//1310// Access the linearized ideal register mask,1311// map to physical register encoding1312if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) {1313// Just use the default virtual 'reg' call1314} else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) {1315// Special handling for operand 'sReg', a Stack Slot Register.1316// Map linearized ideal register mask to stack slot number1317fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node) const {\n");1318fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n");1319fprintf(fp," }\n");1320fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n");1321fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n");1322fprintf(fp," }\n");1323}13241325// Output the operand specific access functions used by an enc_class1326// These are only defined when we want to override the default virtual func1327if (oper->_interface != NULL) {1328fprintf(fp,"\n");1329// Check if it is a Memory Interface1330if ( oper->_interface->is_MemInterface() != NULL ) {1331MemInterface *mem_interface = oper->_interface->is_MemInterface();1332const char *base = mem_interface->_base;1333if( base != NULL ) {1334define_oper_interface(fp, *oper, _globalNames, "base", base);1335}1336char *index = mem_interface->_index;1337if( index != NULL ) {1338define_oper_interface(fp, *oper, _globalNames, "index", index);1339}1340const char *scale = mem_interface->_scale;1341if( scale != NULL ) {1342define_oper_interface(fp, *oper, _globalNames, "scale", scale);1343}1344const char *disp = mem_interface->_disp;1345if( disp != NULL ) {1346define_oper_interface(fp, *oper, _globalNames, "disp", disp);1347oper->disp_is_oop(fp, _globalNames);1348}1349if( oper->stack_slots_only(_globalNames) ) {1350// should not call this:1351fprintf(fp," virtual int constant_disp() const { return Type::OffsetBot; }");1352} else if ( disp != NULL ) {1353define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp);1354}1355} // end Memory Interface1356// Check if it is a Conditional Interface1357else if (oper->_interface->is_CondInterface() != NULL) {1358CondInterface *cInterface = oper->_interface->is_CondInterface();1359const char *equal = cInterface->_equal;1360if( equal != NULL ) {1361define_oper_interface(fp, *oper, _globalNames, "equal", equal);1362}1363const char *not_equal = cInterface->_not_equal;1364if( not_equal != NULL ) {1365define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal);1366}1367const char *less = cInterface->_less;1368if( less != NULL ) {1369define_oper_interface(fp, *oper, _globalNames, "less", less);1370}1371const char *greater_equal = cInterface->_greater_equal;1372if( greater_equal != NULL ) {1373define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal);1374}1375const char *less_equal = cInterface->_less_equal;1376if( less_equal != NULL ) {1377define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal);1378}1379const char *greater = cInterface->_greater;1380if( greater != NULL ) {1381define_oper_interface(fp, *oper, _globalNames, "greater", greater);1382}1383const char *overflow = cInterface->_overflow;1384if( overflow != NULL ) {1385define_oper_interface(fp, *oper, _globalNames, "overflow", overflow);1386}1387const char *no_overflow = cInterface->_no_overflow;1388if( no_overflow != NULL ) {1389define_oper_interface(fp, *oper, _globalNames, "no_overflow", no_overflow);1390}1391} // end Conditional Interface1392// Check if it is a Constant Interface1393else if (oper->_interface->is_ConstInterface() != NULL ) {1394assert( oper->num_consts(_globalNames) == 1,1395"Must have one constant when using CONST_INTER encoding");1396if (!strcmp(oper->ideal_type(_globalNames), "ConI")) {1397// Access the locally stored constant1398fprintf(fp," virtual intptr_t constant() const {");1399fprintf(fp, " return (intptr_t)_c0;");1400fprintf(fp," }\n");1401}1402else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) {1403// Access the locally stored constant1404fprintf(fp," virtual intptr_t constant() const {");1405fprintf(fp, " return _c0->get_con();");1406fprintf(fp, " }\n");1407// Generate query to determine if this pointer is an oop1408fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");1409fprintf(fp, " return _c0->reloc();");1410fprintf(fp, " }\n");1411}1412else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) {1413// Access the locally stored constant1414fprintf(fp," virtual intptr_t constant() const {");1415fprintf(fp, " return _c0->get_ptrtype()->get_con();");1416fprintf(fp, " }\n");1417// Generate query to determine if this pointer is an oop1418fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");1419fprintf(fp, " return _c0->get_ptrtype()->reloc();");1420fprintf(fp, " }\n");1421}1422else if (!strcmp(oper->ideal_type(_globalNames), "ConNKlass")) {1423// Access the locally stored constant1424fprintf(fp," virtual intptr_t constant() const {");1425fprintf(fp, " return _c0->get_ptrtype()->get_con();");1426fprintf(fp, " }\n");1427// Generate query to determine if this pointer is an oop1428fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");1429fprintf(fp, " return _c0->get_ptrtype()->reloc();");1430fprintf(fp, " }\n");1431}1432else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) {1433fprintf(fp," virtual intptr_t constant() const {");1434// We don't support addressing modes with > 4Gig offsets.1435// Truncate to int.1436fprintf(fp, " return (intptr_t)_c0;");1437fprintf(fp, " }\n");1438fprintf(fp," virtual jlong constantL() const {");1439fprintf(fp, " return _c0;");1440fprintf(fp, " }\n");1441}1442else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) {1443fprintf(fp," virtual intptr_t constant() const {");1444fprintf(fp, " ShouldNotReachHere(); return 0; ");1445fprintf(fp, " }\n");1446fprintf(fp," virtual jfloat constantF() const {");1447fprintf(fp, " return (jfloat)_c0;");1448fprintf(fp, " }\n");1449}1450else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) {1451fprintf(fp," virtual intptr_t constant() const {");1452fprintf(fp, " ShouldNotReachHere(); return 0; ");1453fprintf(fp, " }\n");1454fprintf(fp," virtual jdouble constantD() const {");1455fprintf(fp, " return _c0;");1456fprintf(fp, " }\n");1457}1458}1459else if (oper->_interface->is_RegInterface() != NULL) {1460// make sure that a fixed format string isn't used for an1461// operand which might be assiged to multiple registers.1462// Otherwise the opto assembly output could be misleading.1463if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) {1464syntax_err(oper->_linenum,1465"Only bound registers can have fixed formats: %s\n",1466oper->_ident);1467}1468}1469else {1470assert( false, "ShouldNotReachHere();");1471}1472}14731474fprintf(fp,"\n");1475// // Currently all XXXOper::hash() methods are identical (990820)1476// declare_hash(fp);1477// // Currently all XXXOper::Cmp() methods are identical (990820)1478// declare_cmp(fp);14791480// Do not place dump_spec() and Name() into PRODUCT code1481// int_format and ext_format are not needed in PRODUCT code either1482fprintf(fp, "#ifndef PRODUCT\n");14831484// Declare int_format() and ext_format()1485gen_oper_format(fp, _globalNames, *oper);14861487// Machine independent print functionality for debugging1488// IF we have constants, create a dump_spec function for the derived class1489//1490// (1) virtual void dump_spec() const {1491// (2) st->print("#%d", _c#); // Constant != ConP1492// OR _c#->dump_on(st); // Type ConP1493// ...1494// (3) }1495uint num_consts = oper->num_consts(_globalNames);1496if( num_consts > 0 ) {1497// line (1)1498fprintf(fp, " virtual void dump_spec(outputStream *st) const {\n");1499// generate format string for st->print1500// Iterate over the component list & spit out the right thing1501uint i = 0;1502const char *type = oper->ideal_type(_globalNames);1503Component *comp;1504oper->_components.reset();1505if ((comp = oper->_components.iter()) == NULL) {1506assert(num_consts == 1, "Bad component list detected.\n");1507i = dump_spec_constant( fp, type, i, oper );1508// Check that type actually matched1509assert( i != 0, "Non-constant operand lacks component list.");1510} // end if NULL1511else {1512// line (2)1513// dump all components1514oper->_components.reset();1515while((comp = oper->_components.iter()) != NULL) {1516type = comp->base_type(_globalNames);1517i = dump_spec_constant( fp, type, i, NULL );1518}1519}1520// finish line (3)1521fprintf(fp," }\n");1522}15231524fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",1525oper->_ident);15261527fprintf(fp,"#endif\n");15281529// Close definition of this XxxMachOper1530fprintf(fp,"};\n");1531}153215331534// Generate Machine Classes for each instruction defined in AD file1535fprintf(fp,"\n");1536fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");1537declare_pipe_classes(fp);15381539// Generate Machine Classes for each instruction defined in AD file1540fprintf(fp,"\n");1541fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");1542_instructions.reset();1543InstructForm *instr;1544for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {1545// Ensure this is a machine-world instruction1546if ( instr->ideal_only() ) continue;15471548// Build class definition for this instruction1549fprintf(fp,"\n");1550fprintf(fp,"class %sNode : public %s { \n",1551instr->_ident, instr->mach_base_class(_globalNames) );1552fprintf(fp,"private:\n");1553fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() );1554if ( instr->is_ideal_jump() ) {1555fprintf(fp, " GrowableArray<Label*> _index2label;\n");1556}15571558fprintf(fp, "public:\n");15591560Attribute *att = instr->_attribs;1561// Fields of the node specified in the ad file.1562while (att != NULL) {1563if (strncmp(att->_ident, "ins_field_", 10) == 0) {1564const char *field_name = att->_ident+10;1565const char *field_type = att->_val;1566fprintf(fp, " %s _%s;\n", field_type, field_name);1567}1568att = (Attribute *)att->_next;1569}15701571fprintf(fp," MachOper *opnd_array(uint operand_index) const {\n");1572fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");1573fprintf(fp," return _opnd_array[operand_index];\n");1574fprintf(fp," }\n");1575fprintf(fp," void set_opnd_array(uint operand_index, MachOper *operand) {\n");1576fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");1577fprintf(fp," _opnd_array[operand_index] = operand;\n");1578fprintf(fp," }\n");1579fprintf(fp,"private:\n");1580if ( instr->is_ideal_jump() ) {1581fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n");1582fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);\n");1583fprintf(fp," }\n");1584}1585if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {1586fprintf(fp," const RegMask *_cisc_RegMask;\n");1587}15881589out_RegMask(fp); // output register mask1590fprintf(fp," virtual uint rule() const { return %s_rule; }\n",1591instr->_ident);15921593// If this instruction contains a labelOper1594// Declare Node::methods that set operand Label's contents1595int label_position = instr->label_position();1596if( label_position != -1 ) {1597// Set/Save the label, stored in labelOper::_branch_label1598fprintf(fp," virtual void label_set( Label* label, uint block_num );\n");1599fprintf(fp," virtual void save_label( Label** label, uint* block_num );\n");1600}16011602// If this instruction contains a methodOper1603// Declare Node::methods that set operand method's contents1604int method_position = instr->method_position();1605if( method_position != -1 ) {1606// Set the address method, stored in methodOper::_method1607fprintf(fp," virtual void method_set( intptr_t method );\n");1608}16091610// virtual functions for attributes1611//1612// Each instruction attribute results in a virtual call of same name.1613// The ins_cost is not handled here.1614Attribute *attr = instr->_attribs;1615Attribute *avoid_back_to_back_attr = NULL;1616while (attr != NULL) {1617if (strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") == 0) {1618fprintf(fp, " virtual bool is_TrapBasedCheckNode() const { return %s; }\n", attr->_val);1619} else if (strcmp (attr->_ident, "ins_cost") != 0 &&1620strncmp(attr->_ident, "ins_field_", 10) != 0 &&1621// Must match function in node.hpp: return type bool, no prefix "ins_".1622strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") != 0 &&1623strcmp (attr->_ident, "ins_short_branch") != 0) {1624fprintf(fp, " virtual int %s() const { return %s; }\n", attr->_ident, attr->_val);1625}1626if (strcmp(attr->_ident, "ins_avoid_back_to_back") == 0) {1627avoid_back_to_back_attr = attr;1628}1629attr = (Attribute *)attr->_next;1630}16311632// virtual functions for encode and format16331634// Virtual function for evaluating the constant.1635if (instr->is_mach_constant()) {1636fprintf(fp," virtual void eval_constant(Compile* C);\n");1637}16381639// Output the opcode function and the encode function here using the1640// encoding class information in the _insencode slot.1641if ( instr->_insencode ) {1642if (instr->postalloc_expands()) {1643fprintf(fp," virtual bool requires_postalloc_expand() const { return true; }\n");1644fprintf(fp," virtual void postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_);\n");1645} else {1646fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n");1647}1648}16491650// virtual function for getting the size of an instruction1651if ( instr->_size ) {1652fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n");1653}16541655// Return the top-level ideal opcode.1656// Use MachNode::ideal_Opcode() for nodes based on MachNode class1657// if the ideal_Opcode == Op_Node.1658if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||1659strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {1660fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n",1661instr->ideal_Opcode(_globalNames) );1662}16631664if (instr->needs_constant_base() &&1665!instr->is_mach_constant()) { // These inherit the funcion from MachConstantNode.1666fprintf(fp," virtual uint mach_constant_base_node_input() const { ");1667if (instr->is_ideal_call() != Form::invalid_type &&1668instr->is_ideal_call() != Form::JAVA_LEAF) {1669// MachConstantBase goes behind arguments, but before jvms.1670fprintf(fp,"assert(tf() && tf()->domain(), \"\"); return tf()->domain()->cnt();");1671} else {1672fprintf(fp,"return req()-1;");1673}1674fprintf(fp," }\n");1675}16761677// Allow machine-independent optimization, invert the sense of the IF test1678if( instr->is_ideal_if() ) {1679fprintf(fp," virtual void negate() { \n");1680// Identify which operand contains the negate(able) ideal condition code1681int idx = 0;1682instr->_components.reset();1683for( Component *comp; (comp = instr->_components.iter()) != NULL; ) {1684// Check that component is an operand1685Form *form = (Form*)_globalNames[comp->_type];1686OperandForm *opForm = form ? form->is_operand() : NULL;1687if( opForm == NULL ) continue;16881689// Lookup the position of the operand in the instruction.1690if( opForm->is_ideal_bool() ) {1691idx = instr->operand_position(comp->_name, comp->_usedef);1692assert( idx != NameList::Not_in_list, "Did not find component in list that contained it.");1693break;1694}1695}1696fprintf(fp," opnd_array(%d)->negate();\n", idx);1697fprintf(fp," _prob = 1.0f - _prob;\n");1698fprintf(fp," };\n");1699}170017011702// Identify which input register matches the input register.1703uint matching_input = instr->two_address(_globalNames);17041705// Generate the method if it returns != 0 otherwise use MachNode::two_adr()1706if( matching_input != 0 ) {1707fprintf(fp," virtual uint two_adr() const ");1708fprintf(fp,"{ return oper_input_base()");1709for( uint i = 2; i <= matching_input; i++ )1710fprintf(fp," + opnd_array(%d)->num_edges()",i-1);1711fprintf(fp,"; }\n");1712}17131714// Declare cisc_version, if applicable1715// MachNode *cisc_version( int offset /* ,... */ );1716instr->declare_cisc_version(*this, fp);17171718// If there is an explicit peephole rule, build it1719if ( instr->peepholes() != NULL ) {1720fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile *C);\n");1721}17221723// Output the declaration for number of relocation entries1724if ( instr->reloc(_globalNames) != 0 ) {1725fprintf(fp," virtual int reloc() const;\n");1726}17271728if (instr->alignment() != 1) {1729fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment());1730fprintf(fp," virtual int compute_padding(int current_offset) const;\n");1731}17321733// Starting point for inputs matcher wants.1734// Use MachNode::oper_input_base() for nodes based on MachNode class1735// if the base == 1.1736if ( instr->oper_input_base(_globalNames) != 1 ||1737strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {1738fprintf(fp," virtual uint oper_input_base() const { return %d; }\n",1739instr->oper_input_base(_globalNames));1740}17411742// Make the constructor and following methods 'public:'1743fprintf(fp,"public:\n");17441745// Constructor1746if ( instr->is_ideal_jump() ) {1747fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);1748} else {1749fprintf(fp," %sNode() { ", instr->_ident);1750if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {1751fprintf(fp,"_cisc_RegMask = NULL; ");1752}1753}17541755fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());17561757bool node_flags_set = false;1758// flag: if this instruction matches an ideal 'Copy*' node1759if ( instr->is_ideal_copy() != 0 ) {1760fprintf(fp,"init_flags(Flag_is_Copy");1761node_flags_set = true;1762}17631764// Is an instruction is a constant? If so, get its type1765Form::DataType data_type;1766const char *opType = NULL;1767const char *result = NULL;1768data_type = instr->is_chain_of_constant(_globalNames, opType, result);1769// Check if this instruction is a constant1770if ( data_type != Form::none ) {1771if ( node_flags_set ) {1772fprintf(fp," | Flag_is_Con");1773} else {1774fprintf(fp,"init_flags(Flag_is_Con");1775node_flags_set = true;1776}1777}17781779// flag: if this instruction is cisc alternate1780if ( can_cisc_spill() && instr->is_cisc_alternate() ) {1781if ( node_flags_set ) {1782fprintf(fp," | Flag_is_cisc_alternate");1783} else {1784fprintf(fp,"init_flags(Flag_is_cisc_alternate");1785node_flags_set = true;1786}1787}17881789// flag: if this instruction has short branch form1790if ( instr->has_short_branch_form() ) {1791if ( node_flags_set ) {1792fprintf(fp," | Flag_may_be_short_branch");1793} else {1794fprintf(fp,"init_flags(Flag_may_be_short_branch");1795node_flags_set = true;1796}1797}17981799// flag: if this instruction should not be generated back to back.1800if (avoid_back_to_back_attr != NULL) {1801if (node_flags_set) {1802fprintf(fp," | (%s)", avoid_back_to_back_attr->_val);1803} else {1804fprintf(fp,"init_flags((%s)", avoid_back_to_back_attr->_val);1805node_flags_set = true;1806}1807}18081809// Check if machine instructions that USE memory, but do not DEF memory,1810// depend upon a node that defines memory in machine-independent graph.1811if ( instr->needs_anti_dependence_check(_globalNames) ) {1812if ( node_flags_set ) {1813fprintf(fp," | Flag_needs_anti_dependence_check");1814} else {1815fprintf(fp,"init_flags(Flag_needs_anti_dependence_check");1816node_flags_set = true;1817}1818}18191820// flag: if this instruction is implemented with a call1821if ( instr->_has_call ) {1822if ( node_flags_set ) {1823fprintf(fp," | Flag_has_call");1824} else {1825fprintf(fp,"init_flags(Flag_has_call");1826node_flags_set = true;1827}1828}18291830if ( node_flags_set ) {1831fprintf(fp,"); ");1832}18331834fprintf(fp,"}\n");18351836// size_of, used by base class's clone to obtain the correct size.1837fprintf(fp," virtual uint size_of() const {");1838fprintf(fp, " return sizeof(%sNode);", instr->_ident);1839fprintf(fp, " }\n");18401841// Virtual methods which are only generated to override base class1842if( instr->expands() || instr->needs_projections() ||1843instr->has_temps() ||1844instr->is_mach_constant() ||1845instr->needs_constant_base() ||1846instr->_matrule != NULL &&1847instr->num_opnds() != instr->num_unique_opnds() ) {1848fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list, Node* mem);\n");1849}18501851if (instr->is_pinned(_globalNames)) {1852fprintf(fp," virtual bool pinned() const { return ");1853if (instr->is_parm(_globalNames)) {1854fprintf(fp,"_in[0]->pinned();");1855} else {1856fprintf(fp,"true;");1857}1858fprintf(fp," }\n");1859}1860if (instr->is_projection(_globalNames)) {1861fprintf(fp," virtual const Node *is_block_proj() const { return this; }\n");1862}1863if ( instr->num_post_match_opnds() != 01864|| instr->is_chain_of_constant(_globalNames) ) {1865fprintf(fp," friend MachNode *State::MachNodeGenerator(int opcode, Compile* C);\n");1866}1867if ( instr->rematerialize(_globalNames, get_registers()) ) {1868fprintf(fp," // Rematerialize %s\n", instr->_ident);1869}18701871// Declare short branch methods, if applicable1872instr->declare_short_branch_methods(fp);18731874// See if there is an "ins_pipe" declaration for this instruction1875if (instr->_ins_pipe) {1876fprintf(fp," static const Pipeline *pipeline_class();\n");1877fprintf(fp," virtual const Pipeline *pipeline() const;\n");1878}18791880// Generate virtual function for MachNodeX::bottom_type when necessary1881//1882// Note on accuracy: Pointer-types of machine nodes need to be accurate,1883// or else alias analysis on the matched graph may produce bad code.1884// Moreover, the aliasing decisions made on machine-node graph must be1885// no less accurate than those made on the ideal graph, or else the graph1886// may fail to schedule. (Reason: Memory ops which are reordered in1887// the ideal graph might look interdependent in the machine graph,1888// thereby removing degrees of scheduling freedom that the optimizer1889// assumed would be available.)1890//1891// %%% We should handle many of these cases with an explicit ADL clause:1892// instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %}1893if( data_type != Form::none ) {1894// A constant's bottom_type returns a Type containing its constant value18951896// !!!!!1897// Convert all ints, floats, ... to machine-independent TypeXs1898// as is done for pointers1899//1900// Construct appropriate constant type containing the constant value.1901fprintf(fp," virtual const class Type *bottom_type() const {\n");1902switch( data_type ) {1903case Form::idealI:1904fprintf(fp," return TypeInt::make(opnd_array(1)->constant());\n");1905break;1906case Form::idealP:1907case Form::idealN:1908case Form::idealNKlass:1909fprintf(fp," return opnd_array(1)->type();\n");1910break;1911case Form::idealD:1912fprintf(fp," return TypeD::make(opnd_array(1)->constantD());\n");1913break;1914case Form::idealF:1915fprintf(fp," return TypeF::make(opnd_array(1)->constantF());\n");1916break;1917case Form::idealL:1918fprintf(fp," return TypeLong::make(opnd_array(1)->constantL());\n");1919break;1920default:1921assert( false, "Unimplemented()" );1922break;1923}1924fprintf(fp," };\n");1925}1926/* else if ( instr->_matrule && instr->_matrule->_rChild &&1927( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==01928|| strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {1929// !!!!! !!!!!1930// Provide explicit bottom type for conversions to int1931// On Intel the result operand is a stackSlot, untyped.1932fprintf(fp," virtual const class Type *bottom_type() const {");1933fprintf(fp, " return TypeInt::INT;");1934fprintf(fp, " };\n");1935}*/1936else if( instr->is_ideal_copy() &&1937!strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) {1938// !!!!!1939// Special hack for ideal Copy of pointer. Bottom type is oop or not depending on input.1940fprintf(fp," const Type *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n");1941}1942else if( instr->is_ideal_loadPC() ) {1943// LoadPCNode provides the return address of a call to native code.1944// Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM1945// since it is a pointer to an internal VM location and must have a zero offset.1946// Allocation detects derived pointers, in part, by their non-zero offsets.1947fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n");1948}1949else if( instr->is_ideal_box() ) {1950// BoxNode provides the address of a stack slot.1951// Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM1952// This prevent s insert_anti_dependencies from complaining. It will1953// complain if it sees that the pointer base is TypePtr::BOTTOM since1954// it doesn't understand what that might alias.1955fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n");1956}1957else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveP") ) {1958int offset = 1;1959// Special special hack to see if the Cmp? has been incorporated in the conditional move1960MatchNode *rl = instr->_matrule->_rChild->_lChild;1961if( rl && !strcmp(rl->_opType, "Binary") ) {1962MatchNode *rlr = rl->_rChild;1963if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)1964offset = 2;1965}1966// Special hack for ideal CMoveP; ideal type depends on inputs1967fprintf(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",1968offset, offset+1, offset+1);1969}1970else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) {1971int offset = 1;1972// Special special hack to see if the Cmp? has been incorporated in the conditional move1973MatchNode *rl = instr->_matrule->_rChild->_lChild;1974if( rl && !strcmp(rl->_opType, "Binary") ) {1975MatchNode *rlr = rl->_rChild;1976if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)1977offset = 2;1978}1979// Special hack for ideal CMoveN; ideal type depends on inputs1980fprintf(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",1981offset, offset+1, offset+1);1982}1983else if (instr->is_tls_instruction()) {1984// Special hack for tlsLoadP1985fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");1986}1987else if ( instr->is_ideal_if() ) {1988fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");1989}1990else if ( instr->is_ideal_membar() ) {1991fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");1992}19931994// Check where 'ideal_type' must be customized1995/*1996if ( instr->_matrule && instr->_matrule->_rChild &&1997( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==01998|| strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {1999fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");2000}*/20012002// Analyze machine instructions that either USE or DEF memory.2003int memory_operand = instr->memory_operand(_globalNames);2004if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {2005if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {2006fprintf(fp," virtual const TypePtr *adr_type() const;\n");2007}2008fprintf(fp," virtual const MachOper *memory_operand() const;\n");2009}20102011fprintf(fp, "#ifndef PRODUCT\n");20122013// virtual function for generating the user's assembler output2014gen_inst_format(fp, _globalNames,*instr);20152016// Machine independent print functionality for debugging2017fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",2018instr->_ident);20192020fprintf(fp, "#endif\n");20212022// Close definition of this XxxMachNode2023fprintf(fp,"};\n");2024};20252026}20272028void ArchDesc::defineStateClass(FILE *fp) {2029static const char *state__valid = "_valid[((uint)index) >> 5] & (0x1 << (((uint)index) & 0x0001F))";2030static const char *state__set_valid= "_valid[((uint)index) >> 5] |= (0x1 << (((uint)index) & 0x0001F))";20312032fprintf(fp,"\n");2033fprintf(fp,"// MACROS to inline and constant fold State::valid(index)...\n");2034fprintf(fp,"// when given a constant 'index' in dfa_<arch>.cpp\n");2035fprintf(fp,"// uint word = index >> 5; // Shift out bit position\n");2036fprintf(fp,"// uint bitpos = index & 0x0001F; // Mask off word bits\n");2037fprintf(fp,"#define STATE__VALID(index) ");2038fprintf(fp," (%s)\n", state__valid);2039fprintf(fp,"\n");2040fprintf(fp,"#define STATE__NOT_YET_VALID(index) ");2041fprintf(fp," ( (%s) == 0 )\n", state__valid);2042fprintf(fp,"\n");2043fprintf(fp,"#define STATE__VALID_CHILD(state,index) ");2044fprintf(fp," ( state && (state->%s) )\n", state__valid);2045fprintf(fp,"\n");2046fprintf(fp,"#define STATE__SET_VALID(index) ");2047fprintf(fp," (%s)\n", state__set_valid);2048fprintf(fp,"\n");2049fprintf(fp,2050"//---------------------------State-------------------------------------------\n");2051fprintf(fp,"// State contains an integral cost vector, indexed by machine operand opcodes,\n");2052fprintf(fp,"// a rule vector consisting of machine operand/instruction opcodes, and also\n");2053fprintf(fp,"// indexed by machine operand opcodes, pointers to the children in the label\n");2054fprintf(fp,"// tree generated by the Label routines in ideal nodes (currently limited to\n");2055fprintf(fp,"// two for convenience, but this could change).\n");2056fprintf(fp,"class State : public ResourceObj {\n");2057fprintf(fp,"public:\n");2058fprintf(fp," int _id; // State identifier\n");2059fprintf(fp," Node *_leaf; // Ideal (non-machine-node) leaf of match tree\n");2060fprintf(fp," State *_kids[2]; // Children of state node in label tree\n");2061fprintf(fp," unsigned int _cost[_LAST_MACH_OPER]; // Cost vector, indexed by operand opcodes\n");2062fprintf(fp," unsigned int _rule[_LAST_MACH_OPER]; // Rule vector, indexed by operand opcodes\n");2063fprintf(fp," unsigned int _valid[(_LAST_MACH_OPER/32)+1]; // Bit Map of valid Cost/Rule entries\n");2064fprintf(fp,"\n");2065fprintf(fp," State(void); // Constructor\n");2066fprintf(fp," DEBUG_ONLY( ~State(void); ) // Destructor\n");2067fprintf(fp,"\n");2068fprintf(fp," // Methods created by ADLC and invoked by Reduce\n");2069fprintf(fp," MachOper *MachOperGenerator( int opcode, Compile* C );\n");2070fprintf(fp," MachNode *MachNodeGenerator( int opcode, Compile* C );\n");2071fprintf(fp,"\n");2072fprintf(fp," // Assign a state to a node, definition of method produced by ADLC\n");2073fprintf(fp," bool DFA( int opcode, const Node *ideal );\n");2074fprintf(fp,"\n");2075fprintf(fp," // Access function for _valid bit vector\n");2076fprintf(fp," bool valid(uint index) {\n");2077fprintf(fp," return( STATE__VALID(index) != 0 );\n");2078fprintf(fp," }\n");2079fprintf(fp,"\n");2080fprintf(fp," // Set function for _valid bit vector\n");2081fprintf(fp," void set_valid(uint index) {\n");2082fprintf(fp," STATE__SET_VALID(index);\n");2083fprintf(fp," }\n");2084fprintf(fp,"\n");2085fprintf(fp,"#ifndef PRODUCT\n");2086fprintf(fp," void dump(); // Debugging prints\n");2087fprintf(fp," void dump(int depth);\n");2088fprintf(fp,"#endif\n");2089if (_dfa_small) {2090// Generate the routine name we'll need2091for (int i = 1; i < _last_opcode; i++) {2092if (_mlistab[i] == NULL) continue;2093fprintf(fp, " void _sub_Op_%s(const Node *n);\n", NodeClassNames[i]);2094}2095}2096fprintf(fp,"};\n");2097fprintf(fp,"\n");2098fprintf(fp,"\n");20992100}210121022103//---------------------------buildMachOperEnum---------------------------------2104// Build enumeration for densely packed operands.2105// This enumeration is used to index into the arrays in the State objects2106// that indicate cost and a successfull rule match.21072108// Information needed to generate the ReduceOp mapping for the DFA2109class OutputMachOperands : public OutputMap {2110public:2111OutputMachOperands(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)2112: OutputMap(hpp, cpp, globals, AD, "MachOperands") {};21132114void declaration() { }2115void definition() { fprintf(_cpp, "enum MachOperands {\n"); }2116void closing() { fprintf(_cpp, " _LAST_MACH_OPER\n");2117OutputMap::closing();2118}2119void map(OpClassForm &opc) {2120const char* opc_ident_to_upper = _AD.machOperEnum(opc._ident);2121fprintf(_cpp, " %s", opc_ident_to_upper);2122delete[] opc_ident_to_upper;2123}2124void map(OperandForm &oper) {2125const char* oper_ident_to_upper = _AD.machOperEnum(oper._ident);2126fprintf(_cpp, " %s", oper_ident_to_upper);2127delete[] oper_ident_to_upper;2128}2129void map(char *name) {2130const char* name_to_upper = _AD.machOperEnum(name);2131fprintf(_cpp, " %s", name_to_upper);2132delete[] name_to_upper;2133}21342135bool do_instructions() { return false; }2136void map(InstructForm &inst){ assert( false, "ShouldNotCallThis()"); }2137};213821392140void ArchDesc::buildMachOperEnum(FILE *fp_hpp) {2141// Construct the table for MachOpcodes2142OutputMachOperands output_mach_operands(fp_hpp, fp_hpp, _globalNames, *this);2143build_map(output_mach_operands);2144}214521462147//---------------------------buildMachEnum----------------------------------2148// Build enumeration for all MachOpers and all MachNodes21492150// Information needed to generate the ReduceOp mapping for the DFA2151class OutputMachOpcodes : public OutputMap {2152int begin_inst_chain_rule;2153int end_inst_chain_rule;2154int begin_rematerialize;2155int end_rematerialize;2156int end_instructions;2157public:2158OutputMachOpcodes(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)2159: OutputMap(hpp, cpp, globals, AD, "MachOpcodes"),2160begin_inst_chain_rule(-1), end_inst_chain_rule(-1),2161begin_rematerialize(-1), end_rematerialize(-1),2162end_instructions(-1)2163{};21642165void declaration() { }2166void definition() { fprintf(_cpp, "enum MachOpcodes {\n"); }2167void closing() {2168if( begin_inst_chain_rule != -1 )2169fprintf(_cpp, " _BEGIN_INST_CHAIN_RULE = %d,\n", begin_inst_chain_rule);2170if( end_inst_chain_rule != -1 )2171fprintf(_cpp, " _END_INST_CHAIN_RULE = %d,\n", end_inst_chain_rule);2172if( begin_rematerialize != -1 )2173fprintf(_cpp, " _BEGIN_REMATERIALIZE = %d,\n", begin_rematerialize);2174if( end_rematerialize != -1 )2175fprintf(_cpp, " _END_REMATERIALIZE = %d,\n", end_rematerialize);2176// always execute since do_instructions() is true, and avoids trailing comma2177fprintf(_cpp, " _last_Mach_Node = %d \n", end_instructions);2178OutputMap::closing();2179}2180void map(OpClassForm &opc) { fprintf(_cpp, " %s_rule", opc._ident ); }2181void map(OperandForm &oper) { fprintf(_cpp, " %s_rule", oper._ident ); }2182void map(char *name) { if (name) fprintf(_cpp, " %s_rule", name);2183else fprintf(_cpp, " 0"); }2184void map(InstructForm &inst) {fprintf(_cpp, " %s_rule", inst._ident ); }21852186void record_position(OutputMap::position place, int idx ) {2187switch(place) {2188case OutputMap::BEGIN_INST_CHAIN_RULES :2189begin_inst_chain_rule = idx;2190break;2191case OutputMap::END_INST_CHAIN_RULES :2192end_inst_chain_rule = idx;2193break;2194case OutputMap::BEGIN_REMATERIALIZE :2195begin_rematerialize = idx;2196break;2197case OutputMap::END_REMATERIALIZE :2198end_rematerialize = idx;2199break;2200case OutputMap::END_INSTRUCTIONS :2201end_instructions = idx;2202break;2203default:2204break;2205}2206}2207};220822092210void ArchDesc::buildMachOpcodesEnum(FILE *fp_hpp) {2211// Construct the table for MachOpcodes2212OutputMachOpcodes output_mach_opcodes(fp_hpp, fp_hpp, _globalNames, *this);2213build_map(output_mach_opcodes);2214}221522162217// Generate an enumeration of the pipeline states, and both2218// the functional units (resources) and the masks for2219// specifying resources2220void ArchDesc::build_pipeline_enums(FILE *fp_hpp) {2221int stagelen = (int)strlen("undefined");2222int stagenum = 0;22232224if (_pipeline) { // Find max enum string length2225const char *stage;2226for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) {2227int len = (int)strlen(stage);2228if (stagelen < len) stagelen = len;2229}2230}22312232// Generate a list of stages2233fprintf(fp_hpp, "\n");2234fprintf(fp_hpp, "// Pipeline Stages\n");2235fprintf(fp_hpp, "enum machPipelineStages {\n");2236fprintf(fp_hpp, " stage_%-*s = 0,\n", stagelen, "undefined");22372238if( _pipeline ) {2239const char *stage;2240for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; )2241fprintf(fp_hpp, " stage_%-*s = %d,\n", stagelen, stage, ++stagenum);2242}22432244fprintf(fp_hpp, " stage_%-*s = %d\n", stagelen, "count", stagenum);2245fprintf(fp_hpp, "};\n");22462247fprintf(fp_hpp, "\n");2248fprintf(fp_hpp, "// Pipeline Resources\n");2249fprintf(fp_hpp, "enum machPipelineResources {\n");2250int rescount = 0;22512252if( _pipeline ) {2253const char *resource;2254int reslen = 0;22552256// Generate a list of resources, and masks2257for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {2258int len = (int)strlen(resource);2259if (reslen < len)2260reslen = len;2261}22622263for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {2264const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();2265int mask = resform->mask();2266if ((mask & (mask-1)) == 0)2267fprintf(fp_hpp, " resource_%-*s = %d,\n", reslen, resource, rescount++);2268}2269fprintf(fp_hpp, "\n");2270for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {2271const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();2272fprintf(fp_hpp, " res_mask_%-*s = 0x%08x,\n", reslen, resource, resform->mask());2273}2274fprintf(fp_hpp, "\n");2275}2276fprintf(fp_hpp, " resource_count = %d\n", rescount);2277fprintf(fp_hpp, "};\n");2278}227922802281