duke@435: /* twisti@1038: * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // output_h.cpp - Class HPP file output routines for architecture definition duke@435: #include "adlc.hpp" duke@435: duke@435: duke@435: // Generate the #define that describes the number of registers. duke@435: static void defineRegCount(FILE *fp, RegisterForm *registers) { duke@435: if (registers) { duke@435: int regCount = AdlcVMDeps::Physical + registers->_rdefs.count(); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"// the number of reserved registers + machine registers.\n"); duke@435: fprintf(fp,"#define REG_COUNT %d\n", regCount); duke@435: } duke@435: } duke@435: duke@435: // Output enumeration of machine register numbers duke@435: // (1) duke@435: // // Enumerate machine registers starting after reserved regs. duke@435: // // in the order of occurrence in the register block. duke@435: // enum MachRegisterNumbers { duke@435: // EAX_num = 0, duke@435: // ... duke@435: // _last_Mach_Reg duke@435: // } duke@435: void ArchDesc::buildMachRegisterNumbers(FILE *fp_hpp) { duke@435: if (_register) { duke@435: RegDef *reg_def = NULL; duke@435: duke@435: // Output a #define for the number of machine registers duke@435: defineRegCount(fp_hpp, _register); duke@435: duke@435: // Count all the Save_On_Entry and Always_Save registers duke@435: int saved_on_entry = 0; duke@435: int c_saved_on_entry = 0; duke@435: _register->reset_RegDefs(); duke@435: while( (reg_def = _register->iter_RegDefs()) != NULL ) { duke@435: if( strcmp(reg_def->_callconv,"SOE") == 0 || duke@435: strcmp(reg_def->_callconv,"AS") == 0 ) ++saved_on_entry; duke@435: if( strcmp(reg_def->_c_conv,"SOE") == 0 || duke@435: strcmp(reg_def->_c_conv,"AS") == 0 ) ++c_saved_on_entry; duke@435: } duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, "// the number of save_on_entry + always_saved registers.\n"); duke@435: fprintf(fp_hpp, "#define MAX_SAVED_ON_ENTRY_REG_COUNT %d\n", max(saved_on_entry,c_saved_on_entry)); duke@435: fprintf(fp_hpp, "#define SAVED_ON_ENTRY_REG_COUNT %d\n", saved_on_entry); duke@435: fprintf(fp_hpp, "#define C_SAVED_ON_ENTRY_REG_COUNT %d\n", c_saved_on_entry); duke@435: duke@435: // (1) duke@435: // Build definition for enumeration of register numbers duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, "// Enumerate machine register numbers starting after reserved regs.\n"); duke@435: fprintf(fp_hpp, "// in the order of occurrence in the register block.\n"); duke@435: fprintf(fp_hpp, "enum MachRegisterNumbers {\n"); duke@435: duke@435: // Output the register number for each register in the allocation classes duke@435: _register->reset_RegDefs(); duke@435: int i = 0; duke@435: while( (reg_def = _register->iter_RegDefs()) != NULL ) { duke@435: fprintf(fp_hpp," %s_num,\t\t// %d\n", reg_def->_regname, i++); duke@435: } duke@435: // Finish defining enumeration duke@435: fprintf(fp_hpp, " _last_Mach_Reg\t// %d\n", i); duke@435: fprintf(fp_hpp, "};\n"); duke@435: } duke@435: duke@435: fprintf(fp_hpp, "\n// Size of register-mask in ints\n"); duke@435: fprintf(fp_hpp, "#define RM_SIZE %d\n",RegisterForm::RegMask_Size()); duke@435: fprintf(fp_hpp, "// Unroll factor for loops over the data in a RegMask\n"); duke@435: fprintf(fp_hpp, "#define FORALL_BODY "); duke@435: int len = RegisterForm::RegMask_Size(); duke@435: for( int i = 0; i < len; i++ ) duke@435: fprintf(fp_hpp, "BODY(%d) ",i); duke@435: fprintf(fp_hpp, "\n\n"); duke@435: duke@435: fprintf(fp_hpp,"class RegMask;\n"); duke@435: // All RegMasks are declared "extern const ..." in ad_.hpp duke@435: // fprintf(fp_hpp,"extern RegMask STACK_OR_STACK_SLOTS_mask;\n\n"); duke@435: } duke@435: duke@435: duke@435: // Output enumeration of machine register encodings duke@435: // (2) duke@435: // // Enumerate machine registers starting after reserved regs. duke@435: // // in the order of occurrence in the alloc_class(es). duke@435: // enum MachRegisterEncodes { duke@435: // EAX_enc = 0x00, duke@435: // ... duke@435: // } duke@435: void ArchDesc::buildMachRegisterEncodes(FILE *fp_hpp) { duke@435: if (_register) { duke@435: RegDef *reg_def = NULL; duke@435: RegDef *reg_def_next = NULL; duke@435: duke@435: // (2) duke@435: // Build definition for enumeration of encode values duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, "// Enumerate machine registers starting after reserved regs.\n"); duke@435: fprintf(fp_hpp, "// in the order of occurrence in the alloc_class(es).\n"); duke@435: fprintf(fp_hpp, "enum MachRegisterEncodes {\n"); duke@435: duke@435: // Output the register encoding for each register in the allocation classes duke@435: _register->reset_RegDefs(); duke@435: reg_def_next = _register->iter_RegDefs(); duke@435: while( (reg_def = reg_def_next) != NULL ) { duke@435: reg_def_next = _register->iter_RegDefs(); duke@435: fprintf(fp_hpp," %s_enc = %s%s\n", duke@435: reg_def->_regname, reg_def->register_encode(), reg_def_next == NULL? "" : "," ); duke@435: } duke@435: // Finish defining enumeration duke@435: fprintf(fp_hpp, "};\n"); duke@435: duke@435: } // Done with register form duke@435: } duke@435: duke@435: duke@435: // Declare an array containing the machine register names, strings. duke@435: static void declareRegNames(FILE *fp, RegisterForm *registers) { duke@435: if (registers) { duke@435: // fprintf(fp,"\n"); duke@435: // fprintf(fp,"// An array of character pointers to machine register names.\n"); duke@435: // fprintf(fp,"extern const char *regName[];\n"); duke@435: } duke@435: } duke@435: duke@435: // Declare an array containing the machine register sizes in 32-bit words. duke@435: void ArchDesc::declareRegSizes(FILE *fp) { duke@435: // regSize[] is not used duke@435: } duke@435: duke@435: // Declare an array containing the machine register encoding values duke@435: static void declareRegEncodes(FILE *fp, RegisterForm *registers) { duke@435: if (registers) { duke@435: // // // duke@435: // fprintf(fp,"\n"); duke@435: // fprintf(fp,"// An array containing the machine register encode values\n"); duke@435: // fprintf(fp,"extern const char regEncode[];\n"); duke@435: } duke@435: } duke@435: duke@435: duke@435: // --------------------------------------------------------------------------- duke@435: //------------------------------Utilities to build Instruction Classes-------- duke@435: // --------------------------------------------------------------------------- duke@435: static void out_RegMask(FILE *fp) { duke@435: fprintf(fp," virtual const RegMask &out_RegMask() const;\n"); duke@435: } duke@435: duke@435: // --------------------------------------------------------------------------- duke@435: //--------Utilities to build MachOper and MachNode derived Classes------------ duke@435: // --------------------------------------------------------------------------- duke@435: duke@435: //------------------------------Utilities to build Operand Classes------------ duke@435: static void in_RegMask(FILE *fp) { duke@435: fprintf(fp," virtual const RegMask *in_RegMask(int index) const;\n"); duke@435: } duke@435: duke@435: static void declare_hash(FILE *fp) { duke@435: fprintf(fp," virtual uint hash() const;\n"); duke@435: } duke@435: duke@435: static void declare_cmp(FILE *fp) { duke@435: fprintf(fp," virtual uint cmp( const MachOper &oper ) const;\n"); duke@435: } duke@435: duke@435: static void declareConstStorage(FILE *fp, FormDict &globals, OperandForm *oper) { duke@435: int i = 0; duke@435: Component *comp; duke@435: duke@435: if (oper->num_consts(globals) == 0) return; duke@435: // Iterate over the component list looking for constants duke@435: oper->_components.reset(); duke@435: if ((comp = oper->_components.iter()) == NULL) { duke@435: assert(oper->num_consts(globals) == 1, "Bad component list detected.\n"); duke@435: const char *type = oper->ideal_type(globals); duke@435: if (!strcmp(type, "ConI")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp," int32 _c%d;\n", i); duke@435: } duke@435: else if (!strcmp(type, "ConP")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp," const TypePtr *_c%d;\n", i); duke@435: } coleenp@548: else if (!strcmp(type, "ConN")) { coleenp@548: if (i > 0) fprintf(fp,", "); coleenp@548: fprintf(fp," const TypeNarrowOop *_c%d;\n", i); coleenp@548: } duke@435: else if (!strcmp(type, "ConL")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp," jlong _c%d;\n", i); duke@435: } duke@435: else if (!strcmp(type, "ConF")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp," jfloat _c%d;\n", i); duke@435: } duke@435: else if (!strcmp(type, "ConD")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp," jdouble _c%d;\n", i); duke@435: } duke@435: else if (!strcmp(type, "Bool")) { duke@435: fprintf(fp,"private:\n"); duke@435: fprintf(fp," BoolTest::mask _c%d;\n", i); duke@435: fprintf(fp,"public:\n"); duke@435: } duke@435: else { duke@435: assert(0, "Non-constant operand lacks component list."); duke@435: } duke@435: } // end if NULL duke@435: else { duke@435: oper->_components.reset(); duke@435: while ((comp = oper->_components.iter()) != NULL) { duke@435: if (!strcmp(comp->base_type(globals), "ConI")) { duke@435: fprintf(fp," jint _c%d;\n", i); duke@435: i++; duke@435: } duke@435: else if (!strcmp(comp->base_type(globals), "ConP")) { duke@435: fprintf(fp," const TypePtr *_c%d;\n", i); duke@435: i++; duke@435: } coleenp@548: else if (!strcmp(comp->base_type(globals), "ConN")) { coleenp@548: fprintf(fp," const TypePtr *_c%d;\n", i); coleenp@548: i++; coleenp@548: } duke@435: else if (!strcmp(comp->base_type(globals), "ConL")) { duke@435: fprintf(fp," jlong _c%d;\n", i); duke@435: i++; duke@435: } duke@435: else if (!strcmp(comp->base_type(globals), "ConF")) { duke@435: fprintf(fp," jfloat _c%d;\n", i); duke@435: i++; duke@435: } duke@435: else if (!strcmp(comp->base_type(globals), "ConD")) { duke@435: fprintf(fp," jdouble _c%d;\n", i); duke@435: i++; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Declare constructor. duke@435: // Parameters start with condition code, then all other constants duke@435: // duke@435: // (0) public: duke@435: // (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn) duke@435: // (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { } duke@435: // duke@435: static void defineConstructor(FILE *fp, const char *name, uint num_consts, duke@435: ComponentList &lst, bool is_ideal_bool, duke@435: Form::DataType constant_type, FormDict &globals) { duke@435: fprintf(fp,"public:\n"); duke@435: // generate line (1) duke@435: fprintf(fp," %sOper(", name); duke@435: if( num_consts == 0 ) { duke@435: fprintf(fp,") {}\n"); duke@435: return; duke@435: } duke@435: duke@435: // generate parameters for constants duke@435: uint i = 0; duke@435: Component *comp; duke@435: lst.reset(); duke@435: if ((comp = lst.iter()) == NULL) { duke@435: assert(num_consts == 1, "Bad component list detected.\n"); duke@435: switch( constant_type ) { duke@435: case Form::idealI : { duke@435: fprintf(fp,is_ideal_bool ? "BoolTest::mask c%d" : "int32 c%d", i); duke@435: break; duke@435: } coleenp@548: case Form::idealN : { fprintf(fp,"const TypeNarrowOop *c%d", i); break; } duke@435: case Form::idealP : { fprintf(fp,"const TypePtr *c%d", i); break; } duke@435: case Form::idealL : { fprintf(fp,"jlong c%d", i); break; } duke@435: case Form::idealF : { fprintf(fp,"jfloat c%d", i); break; } duke@435: case Form::idealD : { fprintf(fp,"jdouble c%d", i); break; } duke@435: default: duke@435: assert(!is_ideal_bool, "Non-constant operand lacks component list."); duke@435: break; duke@435: } duke@435: } // end if NULL duke@435: else { duke@435: lst.reset(); duke@435: while((comp = lst.iter()) != NULL) { duke@435: if (!strcmp(comp->base_type(globals), "ConI")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp,"int32 c%d", i); duke@435: i++; duke@435: } duke@435: else if (!strcmp(comp->base_type(globals), "ConP")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp,"const TypePtr *c%d", i); duke@435: i++; duke@435: } coleenp@548: else if (!strcmp(comp->base_type(globals), "ConN")) { coleenp@548: if (i > 0) fprintf(fp,", "); coleenp@548: fprintf(fp,"const TypePtr *c%d", i); coleenp@548: i++; coleenp@548: } duke@435: else if (!strcmp(comp->base_type(globals), "ConL")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp,"jlong c%d", i); duke@435: i++; duke@435: } duke@435: else if (!strcmp(comp->base_type(globals), "ConF")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp,"jfloat c%d", i); duke@435: i++; duke@435: } duke@435: else if (!strcmp(comp->base_type(globals), "ConD")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp,"jdouble c%d", i); duke@435: i++; duke@435: } duke@435: else if (!strcmp(comp->base_type(globals), "Bool")) { duke@435: if (i > 0) fprintf(fp,", "); duke@435: fprintf(fp,"BoolTest::mask c%d", i); duke@435: i++; duke@435: } duke@435: } duke@435: } duke@435: // finish line (1) and start line (2) duke@435: fprintf(fp,") : "); duke@435: // generate initializers for constants duke@435: i = 0; duke@435: fprintf(fp,"_c%d(c%d)", i, i); duke@435: for( i = 1; i < num_consts; ++i) { duke@435: fprintf(fp,", _c%d(c%d)", i, i); duke@435: } duke@435: // The body for the constructor is empty duke@435: fprintf(fp," {}\n"); duke@435: } duke@435: duke@435: // --------------------------------------------------------------------------- duke@435: // Utilities to generate format rules for machine operands and instructions duke@435: // --------------------------------------------------------------------------- duke@435: duke@435: // Generate the format rule for condition codes never@850: static void defineCCodeDump(OperandForm* oper, FILE *fp, int i) { never@850: assert(oper != NULL, "what"); never@850: CondInterface* cond = oper->_interface->is_CondInterface(); never@850: fprintf(fp, " if( _c%d == BoolTest::eq ) st->print(\"%s\");\n",i,cond->_equal_format); never@850: fprintf(fp, " else if( _c%d == BoolTest::ne ) st->print(\"%s\");\n",i,cond->_not_equal_format); never@850: fprintf(fp, " else if( _c%d == BoolTest::le ) st->print(\"%s\");\n",i,cond->_less_equal_format); never@850: fprintf(fp, " else if( _c%d == BoolTest::ge ) st->print(\"%s\");\n",i,cond->_greater_equal_format); never@850: fprintf(fp, " else if( _c%d == BoolTest::lt ) st->print(\"%s\");\n",i,cond->_less_format); never@850: fprintf(fp, " else if( _c%d == BoolTest::gt ) st->print(\"%s\");\n",i,cond->_greater_format); duke@435: } duke@435: duke@435: // Output code that dumps constant values, increment "i" if type is constant never@850: static uint dump_spec_constant(FILE *fp, const char *ideal_type, uint i, OperandForm* oper) { duke@435: if (!strcmp(ideal_type, "ConI")) { duke@435: fprintf(fp," st->print(\"#%%d\", _c%d);\n", i); duke@435: ++i; duke@435: } duke@435: else if (!strcmp(ideal_type, "ConP")) { duke@435: fprintf(fp," _c%d->dump_on(st);\n", i); duke@435: ++i; duke@435: } coleenp@548: else if (!strcmp(ideal_type, "ConN")) { never@852: fprintf(fp," _c%d->dump_on(st);\n", i); coleenp@548: ++i; coleenp@548: } duke@435: else if (!strcmp(ideal_type, "ConL")) { duke@435: fprintf(fp," st->print(\"#\" INT64_FORMAT, _c%d);\n", i); duke@435: ++i; duke@435: } duke@435: else if (!strcmp(ideal_type, "ConF")) { duke@435: fprintf(fp," st->print(\"#%%f\", _c%d);\n", i); duke@435: ++i; duke@435: } duke@435: else if (!strcmp(ideal_type, "ConD")) { duke@435: fprintf(fp," st->print(\"#%%f\", _c%d);\n", i); duke@435: ++i; duke@435: } duke@435: else if (!strcmp(ideal_type, "Bool")) { never@850: defineCCodeDump(oper, fp,i); duke@435: ++i; duke@435: } duke@435: duke@435: return i; duke@435: } duke@435: duke@435: // Generate the format rule for an operand duke@435: void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) { duke@435: if (!for_c_file) { duke@435: // invoked after output #ifndef PRODUCT to ad_.hpp duke@435: // compile the bodies separately, to cut down on recompilations duke@435: fprintf(fp," virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n"); duke@435: fprintf(fp," virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n"); duke@435: return; duke@435: } duke@435: duke@435: // Local pointer indicates remaining part of format rule duke@435: uint idx = 0; // position of operand in match rule duke@435: duke@435: // Generate internal format function, used when stored locally duke@435: fprintf(fp, "\n#ifndef PRODUCT\n"); duke@435: fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident); duke@435: // Generate the user-defined portion of the format duke@435: if (oper._format) { duke@435: if ( oper._format->_strings.count() != 0 ) { duke@435: // No initialization code for int_format duke@435: duke@435: // Build the format from the entries in strings and rep_vars duke@435: const char *string = NULL; duke@435: oper._format->_rep_vars.reset(); duke@435: oper._format->_strings.reset(); duke@435: while ( (string = oper._format->_strings.iter()) != NULL ) { duke@435: fprintf(fp," "); duke@435: duke@435: // Check if this is a standard string or a replacement variable duke@435: if ( string != NameList::_signal ) { duke@435: // Normal string duke@435: // Pass through to st->print duke@435: fprintf(fp,"st->print(\"%s\");\n", string); duke@435: } else { duke@435: // Replacement variable duke@435: const char *rep_var = oper._format->_rep_vars.iter(); duke@435: // Check that it is a local name, and an operand coleenp@548: const Form* form = oper._localNames[rep_var]; coleenp@548: if (form == NULL) { coleenp@548: globalAD->syntax_err(oper._linenum, coleenp@548: "\'%s\' not found in format for %s\n", rep_var, oper._ident); coleenp@548: assert(form, "replacement variable was not found in local names"); coleenp@548: } coleenp@548: OperandForm *op = form->is_operand(); duke@435: // Get index if register or constant duke@435: if ( op->_matrule && op->_matrule->is_base_register(globals) ) { duke@435: idx = oper.register_position( globals, rep_var); duke@435: } duke@435: else if (op->_matrule && op->_matrule->is_base_constant(globals)) { duke@435: idx = oper.constant_position( globals, rep_var); duke@435: } else { duke@435: idx = 0; duke@435: } duke@435: duke@435: // output invocation of "$..."s format function duke@435: if ( op != NULL ) op->int_format(fp, globals, idx); duke@435: duke@435: if ( idx == -1 ) { duke@435: fprintf(stderr, duke@435: "Using a name, %s, that isn't in match rule\n", rep_var); duke@435: assert( strcmp(op->_ident,"label")==0, "Unimplemented"); duke@435: } duke@435: } // Done with a replacement variable duke@435: } // Done with all format strings duke@435: } else { duke@435: // Default formats for base operands (RegI, RegP, ConI, ConP, ...) duke@435: oper.int_format(fp, globals, 0); duke@435: } duke@435: duke@435: } else { // oper._format == NULL duke@435: // Provide a few special case formats where the AD writer cannot. duke@435: if ( strcmp(oper._ident,"Universe")==0 ) { duke@435: fprintf(fp, " st->print(\"$$univ\");\n"); duke@435: } duke@435: // labelOper::int_format is defined in ad_<...>.cpp duke@435: } duke@435: // ALWAYS! Provide a special case output for condition codes. duke@435: if( oper.is_ideal_bool() ) { never@850: defineCCodeDump(&oper, fp,0); duke@435: } duke@435: fprintf(fp,"}\n"); duke@435: duke@435: // Generate external format function, when data is stored externally duke@435: fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident); duke@435: // Generate the user-defined portion of the format duke@435: if (oper._format) { duke@435: if ( oper._format->_strings.count() != 0 ) { duke@435: duke@435: // Check for a replacement string "$..." duke@435: if ( oper._format->_rep_vars.count() != 0 ) { duke@435: // Initialization code for ext_format duke@435: } duke@435: duke@435: // Build the format from the entries in strings and rep_vars duke@435: const char *string = NULL; duke@435: oper._format->_rep_vars.reset(); duke@435: oper._format->_strings.reset(); duke@435: while ( (string = oper._format->_strings.iter()) != NULL ) { duke@435: fprintf(fp," "); duke@435: duke@435: // Check if this is a standard string or a replacement variable duke@435: if ( string != NameList::_signal ) { duke@435: // Normal string duke@435: // Pass through to st->print duke@435: fprintf(fp,"st->print(\"%s\");\n", string); duke@435: } else { duke@435: // Replacement variable duke@435: const char *rep_var = oper._format->_rep_vars.iter(); coleenp@548: // Check that it is a local name, and an operand coleenp@548: const Form* form = oper._localNames[rep_var]; coleenp@548: if (form == NULL) { coleenp@548: globalAD->syntax_err(oper._linenum, coleenp@548: "\'%s\' not found in format for %s\n", rep_var, oper._ident); coleenp@548: assert(form, "replacement variable was not found in local names"); coleenp@548: } coleenp@548: OperandForm *op = form->is_operand(); duke@435: // Get index if register or constant duke@435: if ( op->_matrule && op->_matrule->is_base_register(globals) ) { duke@435: idx = oper.register_position( globals, rep_var); duke@435: } duke@435: else if (op->_matrule && op->_matrule->is_base_constant(globals)) { duke@435: idx = oper.constant_position( globals, rep_var); duke@435: } else { duke@435: idx = 0; duke@435: } duke@435: // output invocation of "$..."s format function duke@435: if ( op != NULL ) op->ext_format(fp, globals, idx); duke@435: duke@435: // Lookup the index position of the replacement variable duke@435: idx = oper._components.operand_position_format(rep_var); duke@435: if ( idx == -1 ) { duke@435: fprintf(stderr, duke@435: "Using a name, %s, that isn't in match rule\n", rep_var); duke@435: assert( strcmp(op->_ident,"label")==0, "Unimplemented"); duke@435: } duke@435: } // Done with a replacement variable duke@435: } // Done with all format strings duke@435: duke@435: } else { duke@435: // Default formats for base operands (RegI, RegP, ConI, ConP, ...) duke@435: oper.ext_format(fp, globals, 0); duke@435: } duke@435: } else { // oper._format == NULL duke@435: // Provide a few special case formats where the AD writer cannot. duke@435: if ( strcmp(oper._ident,"Universe")==0 ) { duke@435: fprintf(fp, " st->print(\"$$univ\");\n"); duke@435: } duke@435: // labelOper::ext_format is defined in ad_<...>.cpp duke@435: } duke@435: // ALWAYS! Provide a special case output for condition codes. duke@435: if( oper.is_ideal_bool() ) { never@850: defineCCodeDump(&oper, fp,0); duke@435: } duke@435: fprintf(fp, "}\n"); duke@435: fprintf(fp, "#endif\n"); duke@435: } duke@435: duke@435: duke@435: // Generate the format rule for an instruction duke@435: void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &inst, bool for_c_file = false) { duke@435: if (!for_c_file) { duke@435: // compile the bodies separately, to cut down on recompilations duke@435: // #ifndef PRODUCT region generated by caller duke@435: fprintf(fp," virtual void format(PhaseRegAlloc *ra, outputStream *st) const;\n"); duke@435: return; duke@435: } duke@435: duke@435: // Define the format function duke@435: fprintf(fp, "#ifndef PRODUCT\n"); duke@435: fprintf(fp, "void %sNode::format(PhaseRegAlloc *ra, outputStream *st) const {\n", inst._ident); duke@435: duke@435: // Generate the user-defined portion of the format duke@435: if( inst._format ) { duke@435: // If there are replacement variables, twisti@1040: // Generate index values needed for determining the operand position duke@435: if( inst._format->_rep_vars.count() ) duke@435: inst.index_temps(fp, globals); duke@435: duke@435: // Build the format from the entries in strings and rep_vars duke@435: const char *string = NULL; duke@435: inst._format->_rep_vars.reset(); duke@435: inst._format->_strings.reset(); duke@435: while( (string = inst._format->_strings.iter()) != NULL ) { duke@435: fprintf(fp," "); duke@435: // Check if this is a standard string or a replacement variable never@850: if( string == NameList::_signal ) { // Replacement variable never@850: const char* rep_var = inst._format->_rep_vars.iter(); never@850: inst.rep_var_format( fp, rep_var); never@850: } else if( string == NameList::_signal3 ) { // Replacement variable in raw text never@850: const char* rep_var = inst._format->_rep_vars.iter(); never@850: const Form *form = inst._localNames[rep_var]; never@850: if (form == NULL) { never@850: fprintf(stderr, "unknown replacement variable in format statement: '%s'\n", rep_var); never@850: assert(false, "ShouldNotReachHere()"); never@850: } never@850: OpClassForm *opc = form->is_opclass(); never@850: assert( opc, "replacement variable was not found in local names"); never@850: // Lookup the index position of the replacement variable never@850: int idx = inst.operand_position_format(rep_var); never@850: if ( idx == -1 ) { never@850: assert( strcmp(opc->_ident,"label")==0, "Unimplemented"); never@850: assert( false, "ShouldNotReachHere()"); never@850: } never@850: never@850: if (inst.is_noninput_operand(idx)) { never@850: assert( false, "ShouldNotReachHere()"); never@850: } else { never@850: // Output the format call for this operand never@850: fprintf(fp,"opnd_array(%d)",idx); never@850: } never@850: rep_var = inst._format->_rep_vars.iter(); never@850: inst._format->_strings.iter(); never@850: if ( strcmp(rep_var,"$constant") == 0 && opc->is_operand()) { never@850: Form::DataType constant_type = form->is_operand()->is_base_constant(globals); never@850: if ( constant_type == Form::idealD ) { never@850: fprintf(fp,"->constantD()"); never@850: } else if ( constant_type == Form::idealF ) { never@850: fprintf(fp,"->constantF()"); never@850: } else if ( constant_type == Form::idealL ) { never@850: fprintf(fp,"->constantL()"); never@850: } else { never@850: fprintf(fp,"->constant()"); never@850: } never@850: } else if ( strcmp(rep_var,"$cmpcode") == 0) { never@850: fprintf(fp,"->ccode()"); never@850: } else { never@850: assert( false, "ShouldNotReachHere()"); never@850: } never@850: } else if( string == NameList::_signal2 ) // Raw program text never@850: fputs(inst._format->_strings.iter(), fp); never@850: else duke@435: fprintf(fp,"st->print(\"%s\");\n", string); duke@435: } // Done with all format strings duke@435: } // Done generating the user-defined portion of the format duke@435: duke@435: // Add call debug info automatically duke@435: Form::CallType call_type = inst.is_ideal_call(); duke@435: if( call_type != Form::invalid_type ) { duke@435: switch( call_type ) { duke@435: case Form::JAVA_DYNAMIC: duke@435: fprintf(fp," _method->print_short_name();\n"); duke@435: break; duke@435: case Form::JAVA_STATIC: duke@435: fprintf(fp," if( _method ) _method->print_short_name(st); else st->print(\" wrapper for: %%s\", _name);\n"); duke@435: fprintf(fp," if( !_method ) dump_trap_args(st);\n"); duke@435: break; duke@435: case Form::JAVA_COMPILED: duke@435: case Form::JAVA_INTERP: duke@435: break; duke@435: case Form::JAVA_RUNTIME: duke@435: case Form::JAVA_LEAF: duke@435: case Form::JAVA_NATIVE: duke@435: fprintf(fp," st->print(\" %%s\", _name);"); duke@435: break; duke@435: default: duke@435: assert(0,"ShouldNotReacHere"); duke@435: } duke@435: fprintf(fp, " st->print_cr(\"\");\n" ); duke@435: fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" ); duke@435: fprintf(fp, " st->print(\" # \");\n" ); duke@435: fprintf(fp, " if( _jvms ) _oop_map->print_on(st);\n"); duke@435: } duke@435: else if(inst.is_ideal_safepoint()) { duke@435: fprintf(fp, " st->print(\"\");\n" ); duke@435: fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" ); duke@435: fprintf(fp, " st->print(\" # \");\n" ); duke@435: fprintf(fp, " if( _jvms ) _oop_map->print_on(st);\n"); duke@435: } duke@435: else if( inst.is_ideal_if() ) { duke@435: fprintf(fp, " st->print(\" P=%%f C=%%f\",_prob,_fcnt);\n" ); duke@435: } duke@435: else if( inst.is_ideal_mem() ) { duke@435: // Print out the field name if available to improve readability duke@435: fprintf(fp, " if (ra->C->alias_type(adr_type())->field() != NULL) {\n"); duke@435: fprintf(fp, " st->print(\" ! Field \");\n"); duke@435: fprintf(fp, " if( ra->C->alias_type(adr_type())->is_volatile() )\n"); duke@435: fprintf(fp, " st->print(\" Volatile\");\n"); duke@435: fprintf(fp, " ra->C->alias_type(adr_type())->field()->holder()->name()->print_symbol_on(st);\n"); duke@435: fprintf(fp, " st->print(\".\");\n"); duke@435: fprintf(fp, " ra->C->alias_type(adr_type())->field()->name()->print_symbol_on(st);\n"); duke@435: fprintf(fp, " } else\n"); duke@435: // Make sure 'Volatile' gets printed out duke@435: fprintf(fp, " if( ra->C->alias_type(adr_type())->is_volatile() )\n"); duke@435: fprintf(fp, " st->print(\" Volatile!\");\n"); duke@435: } duke@435: duke@435: // Complete the definition of the format function duke@435: fprintf(fp, " }\n#endif\n"); duke@435: } duke@435: duke@435: static bool is_non_constant(char* x) { duke@435: // Tells whether the string (part of an operator interface) is non-constant. duke@435: // Simply detect whether there is an occurrence of a formal parameter, duke@435: // which will always begin with '$'. duke@435: return strchr(x, '$') == 0; duke@435: } duke@435: duke@435: void ArchDesc::declare_pipe_classes(FILE *fp_hpp) { duke@435: if (!_pipeline) duke@435: return; duke@435: duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, "// Pipeline_Use_Cycle_Mask Class\n"); duke@435: fprintf(fp_hpp, "class Pipeline_Use_Cycle_Mask {\n"); duke@435: duke@435: if (_pipeline->_maxcycleused <= duke@435: #ifdef SPARC duke@435: 64 duke@435: #else duke@435: 32 duke@435: #endif duke@435: ) { duke@435: fprintf(fp_hpp, "protected:\n"); duke@435: fprintf(fp_hpp, " %s _mask;\n\n", _pipeline->_maxcycleused <= 32 ? "uint" : "uint64_t" ); duke@435: fprintf(fp_hpp, "public:\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : _mask(0) {}\n\n"); duke@435: if (_pipeline->_maxcycleused <= 32) duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask) : _mask(mask) {}\n\n"); duke@435: else { duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n"); duke@435: } duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n"); duke@435: fprintf(fp_hpp, " _mask = in._mask;\n"); duke@435: fprintf(fp_hpp, " return *this;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n"); duke@435: fprintf(fp_hpp, " return ((_mask & in2._mask) != 0);\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n"); duke@435: fprintf(fp_hpp, " _mask <<= n;\n"); duke@435: fprintf(fp_hpp, " return *this;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &in2) {\n"); duke@435: fprintf(fp_hpp, " _mask |= in2._mask;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n"); duke@435: fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n"); duke@435: } duke@435: else { duke@435: fprintf(fp_hpp, "protected:\n"); duke@435: uint masklen = (_pipeline->_maxcycleused + 31) >> 5; duke@435: uint l; duke@435: fprintf(fp_hpp, " uint "); duke@435: for (l = 1; l <= masklen; l++) duke@435: fprintf(fp_hpp, "_mask%d%s", l, l < masklen ? ", " : ";\n\n"); duke@435: fprintf(fp_hpp, "public:\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : "); duke@435: for (l = 1; l <= masklen; l++) duke@435: fprintf(fp_hpp, "_mask%d(0)%s", l, l < masklen ? ", " : " {}\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask("); duke@435: for (l = 1; l <= masklen; l++) duke@435: fprintf(fp_hpp, "uint mask%d%s", l, l < masklen ? ", " : ") : "); duke@435: for (l = 1; l <= masklen; l++) duke@435: fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n"); duke@435: duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n"); duke@435: for (l = 1; l <= masklen; l++) duke@435: fprintf(fp_hpp, " _mask%d = in._mask%d;\n", l, l); duke@435: fprintf(fp_hpp, " return *this;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask out;\n"); duke@435: for (l = 1; l <= masklen; l++) duke@435: fprintf(fp_hpp, " out._mask%d = _mask%d & in2._mask%d;\n", l, l, l); duke@435: fprintf(fp_hpp, " return out;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n"); duke@435: fprintf(fp_hpp, " return ("); duke@435: for (l = 1; l <= masklen; l++) duke@435: fprintf(fp_hpp, "((_mask%d & in2._mask%d) != 0)%s", l, l, l < masklen ? " || " : ""); duke@435: fprintf(fp_hpp, ") ? true : false;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n"); duke@435: fprintf(fp_hpp, " if (n >= 32)\n"); duke@435: fprintf(fp_hpp, " do {\n "); duke@435: for (l = masklen; l > 1; l--) duke@435: fprintf(fp_hpp, " _mask%d = _mask%d;", l, l-1); duke@435: fprintf(fp_hpp, " _mask%d = 0;\n", 1); duke@435: fprintf(fp_hpp, " } while ((n -= 32) >= 32);\n\n"); duke@435: fprintf(fp_hpp, " if (n > 0) {\n"); duke@435: fprintf(fp_hpp, " uint m = 32 - n;\n"); duke@435: fprintf(fp_hpp, " uint mask = (1 << n) - 1;\n"); duke@435: fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n;\n", 2, 1, 1); duke@435: for (l = 2; l < masklen; l++) { duke@435: fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n; _mask%d |= temp%d;\n", l+1, l, l, l, l); duke@435: } duke@435: fprintf(fp_hpp, " _mask%d <<= n; _mask%d |= temp%d;\n", masklen, masklen, masklen); duke@435: fprintf(fp_hpp, " }\n"); duke@435: duke@435: fprintf(fp_hpp, " return *this;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &);\n\n"); duke@435: fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n"); duke@435: fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n"); duke@435: } duke@435: duke@435: fprintf(fp_hpp, " friend class Pipeline_Use;\n\n"); duke@435: fprintf(fp_hpp, " friend class Pipeline_Use_Element;\n\n"); duke@435: fprintf(fp_hpp, "};\n\n"); duke@435: duke@435: uint rescount = 0; duke@435: const char *resource; duke@435: duke@435: for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { duke@435: int mask = _pipeline->_resdict[resource]->is_resource()->mask(); duke@435: if ((mask & (mask-1)) == 0) duke@435: rescount++; duke@435: } duke@435: duke@435: fprintf(fp_hpp, "// Pipeline_Use_Element Class\n"); duke@435: fprintf(fp_hpp, "class Pipeline_Use_Element {\n"); duke@435: fprintf(fp_hpp, "protected:\n"); duke@435: fprintf(fp_hpp, " // Mask of used functional units\n"); duke@435: fprintf(fp_hpp, " uint _used;\n\n"); duke@435: fprintf(fp_hpp, " // Lower and upper bound of functional unit number range\n"); duke@435: fprintf(fp_hpp, " uint _lb, _ub;\n\n"); duke@435: fprintf(fp_hpp, " // Indicates multiple functionals units available\n"); duke@435: fprintf(fp_hpp, " bool _multiple;\n\n"); duke@435: fprintf(fp_hpp, " // Mask of specific used cycles\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask _mask;\n\n"); duke@435: fprintf(fp_hpp, "public:\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Element() {}\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Element(uint used, uint lb, uint ub, bool multiple, Pipeline_Use_Cycle_Mask mask)\n"); duke@435: fprintf(fp_hpp, " : _used(used), _lb(lb), _ub(ub), _multiple(multiple), _mask(mask) {}\n\n"); duke@435: fprintf(fp_hpp, " uint used() const { return _used; }\n\n"); duke@435: fprintf(fp_hpp, " uint lowerBound() const { return _lb; }\n\n"); duke@435: fprintf(fp_hpp, " uint upperBound() const { return _ub; }\n\n"); duke@435: fprintf(fp_hpp, " bool multiple() const { return _multiple; }\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask mask() const { return _mask; }\n\n"); duke@435: fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Element &in2) const {\n"); duke@435: fprintf(fp_hpp, " return ((_used & in2._used) != 0 && _mask.overlaps(in2._mask));\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " void step(uint cycles) {\n"); duke@435: fprintf(fp_hpp, " _used = 0;\n"); duke@435: fprintf(fp_hpp, " _mask <<= cycles;\n"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " friend class Pipeline_Use;\n"); duke@435: fprintf(fp_hpp, "};\n\n"); duke@435: duke@435: fprintf(fp_hpp, "// Pipeline_Use Class\n"); duke@435: fprintf(fp_hpp, "class Pipeline_Use {\n"); duke@435: fprintf(fp_hpp, "protected:\n"); duke@435: fprintf(fp_hpp, " // These resources can be used\n"); duke@435: fprintf(fp_hpp, " uint _resources_used;\n\n"); duke@435: fprintf(fp_hpp, " // These resources are used; excludes multiple choice functional units\n"); duke@435: fprintf(fp_hpp, " uint _resources_used_exclusively;\n\n"); duke@435: fprintf(fp_hpp, " // Number of elements\n"); duke@435: fprintf(fp_hpp, " uint _count;\n\n"); duke@435: fprintf(fp_hpp, " // This is the array of Pipeline_Use_Elements\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Element * _elements;\n\n"); duke@435: fprintf(fp_hpp, "public:\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use(uint resources_used, uint resources_used_exclusively, uint count, Pipeline_Use_Element *elements)\n"); duke@435: fprintf(fp_hpp, " : _resources_used(resources_used)\n"); duke@435: fprintf(fp_hpp, " , _resources_used_exclusively(resources_used_exclusively)\n"); duke@435: fprintf(fp_hpp, " , _count(count)\n"); duke@435: fprintf(fp_hpp, " , _elements(elements)\n"); duke@435: fprintf(fp_hpp, " {}\n\n"); duke@435: fprintf(fp_hpp, " uint resourcesUsed() const { return _resources_used; }\n\n"); duke@435: fprintf(fp_hpp, " uint resourcesUsedExclusively() const { return _resources_used_exclusively; }\n\n"); duke@435: fprintf(fp_hpp, " uint count() const { return _count; }\n\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use_Element * element(uint i) const { return &_elements[i]; }\n\n"); duke@435: fprintf(fp_hpp, " uint full_latency(uint delay, const Pipeline_Use &pred) const;\n\n"); duke@435: fprintf(fp_hpp, " void add_usage(const Pipeline_Use &pred);\n\n"); duke@435: fprintf(fp_hpp, " void reset() {\n"); duke@435: fprintf(fp_hpp, " _resources_used = _resources_used_exclusively = 0;\n"); duke@435: fprintf(fp_hpp, " };\n\n"); duke@435: fprintf(fp_hpp, " void step(uint cycles) {\n"); duke@435: fprintf(fp_hpp, " reset();\n"); duke@435: fprintf(fp_hpp, " for (uint i = 0; i < %d; i++)\n", duke@435: rescount); duke@435: fprintf(fp_hpp, " (&_elements[i])->step(cycles);\n"); duke@435: fprintf(fp_hpp, " };\n\n"); duke@435: fprintf(fp_hpp, " static const Pipeline_Use elaborated_use;\n"); duke@435: fprintf(fp_hpp, " static const Pipeline_Use_Element elaborated_elements[%d];\n\n", duke@435: rescount); duke@435: fprintf(fp_hpp, " friend class Pipeline;\n"); duke@435: fprintf(fp_hpp, "};\n\n"); duke@435: duke@435: fprintf(fp_hpp, "// Pipeline Class\n"); duke@435: fprintf(fp_hpp, "class Pipeline {\n"); duke@435: fprintf(fp_hpp, "public:\n"); duke@435: duke@435: fprintf(fp_hpp, " static bool enabled() { return %s; }\n\n", duke@435: _pipeline ? "true" : "false" ); duke@435: duke@435: assert( _pipeline->_maxInstrsPerBundle && duke@435: ( _pipeline->_instrUnitSize || _pipeline->_bundleUnitSize) && duke@435: _pipeline->_instrFetchUnitSize && duke@435: _pipeline->_instrFetchUnits, duke@435: "unspecified pipeline architecture units"); duke@435: duke@435: uint unitSize = _pipeline->_instrUnitSize ? _pipeline->_instrUnitSize : _pipeline->_bundleUnitSize; duke@435: duke@435: fprintf(fp_hpp, " enum {\n"); duke@435: fprintf(fp_hpp, " _variable_size_instructions = %d,\n", duke@435: _pipeline->_variableSizeInstrs ? 1 : 0); duke@435: fprintf(fp_hpp, " _fixed_size_instructions = %d,\n", duke@435: _pipeline->_variableSizeInstrs ? 0 : 1); duke@435: fprintf(fp_hpp, " _branch_has_delay_slot = %d,\n", duke@435: _pipeline->_branchHasDelaySlot ? 1 : 0); duke@435: fprintf(fp_hpp, " _max_instrs_per_bundle = %d,\n", duke@435: _pipeline->_maxInstrsPerBundle); duke@435: fprintf(fp_hpp, " _max_bundles_per_cycle = %d,\n", duke@435: _pipeline->_maxBundlesPerCycle); duke@435: fprintf(fp_hpp, " _max_instrs_per_cycle = %d\n", duke@435: _pipeline->_maxBundlesPerCycle * _pipeline->_maxInstrsPerBundle); duke@435: fprintf(fp_hpp, " };\n\n"); duke@435: duke@435: fprintf(fp_hpp, " static bool instr_has_unit_size() { return %s; }\n\n", duke@435: _pipeline->_instrUnitSize != 0 ? "true" : "false" ); duke@435: if( _pipeline->_bundleUnitSize != 0 ) duke@435: if( _pipeline->_instrUnitSize != 0 ) duke@435: fprintf(fp_hpp, "// Individual Instructions may be bundled together by the hardware\n\n"); duke@435: else duke@435: fprintf(fp_hpp, "// Instructions exist only in bundles\n\n"); duke@435: else duke@435: fprintf(fp_hpp, "// Bundling is not supported\n\n"); duke@435: if( _pipeline->_instrUnitSize != 0 ) duke@435: fprintf(fp_hpp, " // Size of an instruction\n"); duke@435: else duke@435: fprintf(fp_hpp, " // Size of an individual instruction does not exist - unsupported\n"); duke@435: fprintf(fp_hpp, " static uint instr_unit_size() {"); duke@435: if( _pipeline->_instrUnitSize == 0 ) duke@435: fprintf(fp_hpp, " assert( false, \"Instructions are only in bundles\" );"); duke@435: fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_instrUnitSize); duke@435: duke@435: if( _pipeline->_bundleUnitSize != 0 ) duke@435: fprintf(fp_hpp, " // Size of a bundle\n"); duke@435: else duke@435: fprintf(fp_hpp, " // Bundles do not exist - unsupported\n"); duke@435: fprintf(fp_hpp, " static uint bundle_unit_size() {"); duke@435: if( _pipeline->_bundleUnitSize == 0 ) duke@435: fprintf(fp_hpp, " assert( false, \"Bundles are not supported\" );"); duke@435: fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_bundleUnitSize); duke@435: duke@435: fprintf(fp_hpp, " static bool requires_bundling() { return %s; }\n\n", duke@435: _pipeline->_bundleUnitSize != 0 && _pipeline->_instrUnitSize == 0 ? "true" : "false" ); duke@435: duke@435: fprintf(fp_hpp, "private:\n"); duke@435: fprintf(fp_hpp, " Pipeline(); // Not a legal constructor\n"); duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, " const unsigned char _read_stage_count;\n"); duke@435: fprintf(fp_hpp, " const unsigned char _write_stage;\n"); duke@435: fprintf(fp_hpp, " const unsigned char _fixed_latency;\n"); duke@435: fprintf(fp_hpp, " const unsigned char _instruction_count;\n"); duke@435: fprintf(fp_hpp, " const bool _has_fixed_latency;\n"); duke@435: fprintf(fp_hpp, " const bool _has_branch_delay;\n"); duke@435: fprintf(fp_hpp, " const bool _has_multiple_bundles;\n"); duke@435: fprintf(fp_hpp, " const bool _force_serialization;\n"); duke@435: fprintf(fp_hpp, " const bool _may_have_no_code;\n"); duke@435: fprintf(fp_hpp, " const enum machPipelineStages * const _read_stages;\n"); duke@435: fprintf(fp_hpp, " const enum machPipelineStages * const _resource_stage;\n"); duke@435: fprintf(fp_hpp, " const uint * const _resource_cycles;\n"); duke@435: fprintf(fp_hpp, " const Pipeline_Use _resource_use;\n"); duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, "public:\n"); duke@435: fprintf(fp_hpp, " Pipeline(uint write_stage,\n"); duke@435: fprintf(fp_hpp, " uint count,\n"); duke@435: fprintf(fp_hpp, " bool has_fixed_latency,\n"); duke@435: fprintf(fp_hpp, " uint fixed_latency,\n"); duke@435: fprintf(fp_hpp, " uint instruction_count,\n"); duke@435: fprintf(fp_hpp, " bool has_branch_delay,\n"); duke@435: fprintf(fp_hpp, " bool has_multiple_bundles,\n"); duke@435: fprintf(fp_hpp, " bool force_serialization,\n"); duke@435: fprintf(fp_hpp, " bool may_have_no_code,\n"); duke@435: fprintf(fp_hpp, " enum machPipelineStages * const dst,\n"); duke@435: fprintf(fp_hpp, " enum machPipelineStages * const stage,\n"); duke@435: fprintf(fp_hpp, " uint * const cycles,\n"); duke@435: fprintf(fp_hpp, " Pipeline_Use resource_use)\n"); duke@435: fprintf(fp_hpp, " : _write_stage(write_stage)\n"); duke@435: fprintf(fp_hpp, " , _read_stage_count(count)\n"); duke@435: fprintf(fp_hpp, " , _has_fixed_latency(has_fixed_latency)\n"); duke@435: fprintf(fp_hpp, " , _fixed_latency(fixed_latency)\n"); duke@435: fprintf(fp_hpp, " , _read_stages(dst)\n"); duke@435: fprintf(fp_hpp, " , _resource_stage(stage)\n"); duke@435: fprintf(fp_hpp, " , _resource_cycles(cycles)\n"); duke@435: fprintf(fp_hpp, " , _resource_use(resource_use)\n"); duke@435: fprintf(fp_hpp, " , _instruction_count(instruction_count)\n"); duke@435: fprintf(fp_hpp, " , _has_branch_delay(has_branch_delay)\n"); duke@435: fprintf(fp_hpp, " , _has_multiple_bundles(has_multiple_bundles)\n"); duke@435: fprintf(fp_hpp, " , _force_serialization(force_serialization)\n"); duke@435: fprintf(fp_hpp, " , _may_have_no_code(may_have_no_code)\n"); duke@435: fprintf(fp_hpp, " {};\n"); duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, " uint writeStage() const {\n"); duke@435: fprintf(fp_hpp, " return (_write_stage);\n"); duke@435: fprintf(fp_hpp, " }\n"); duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, " enum machPipelineStages readStage(int ndx) const {\n"); duke@435: fprintf(fp_hpp, " return (ndx < _read_stage_count ? _read_stages[ndx] : stage_undefined);"); duke@435: fprintf(fp_hpp, " }\n\n"); duke@435: fprintf(fp_hpp, " uint resourcesUsed() const {\n"); duke@435: fprintf(fp_hpp, " return _resource_use.resourcesUsed();\n }\n\n"); duke@435: fprintf(fp_hpp, " uint resourcesUsedExclusively() const {\n"); duke@435: fprintf(fp_hpp, " return _resource_use.resourcesUsedExclusively();\n }\n\n"); duke@435: fprintf(fp_hpp, " bool hasFixedLatency() const {\n"); duke@435: fprintf(fp_hpp, " return (_has_fixed_latency);\n }\n\n"); duke@435: fprintf(fp_hpp, " uint fixedLatency() const {\n"); duke@435: fprintf(fp_hpp, " return (_fixed_latency);\n }\n\n"); duke@435: fprintf(fp_hpp, " uint functional_unit_latency(uint start, const Pipeline *pred) const;\n\n"); duke@435: fprintf(fp_hpp, " uint operand_latency(uint opnd, const Pipeline *pred) const;\n\n"); duke@435: fprintf(fp_hpp, " const Pipeline_Use& resourceUse() const {\n"); duke@435: fprintf(fp_hpp, " return (_resource_use); }\n\n"); duke@435: fprintf(fp_hpp, " const Pipeline_Use_Element * resourceUseElement(uint i) const {\n"); duke@435: fprintf(fp_hpp, " return (&_resource_use._elements[i]); }\n\n"); duke@435: fprintf(fp_hpp, " uint resourceUseCount() const {\n"); duke@435: fprintf(fp_hpp, " return (_resource_use._count); }\n\n"); duke@435: fprintf(fp_hpp, " uint instructionCount() const {\n"); duke@435: fprintf(fp_hpp, " return (_instruction_count); }\n\n"); duke@435: fprintf(fp_hpp, " bool hasBranchDelay() const {\n"); duke@435: fprintf(fp_hpp, " return (_has_branch_delay); }\n\n"); duke@435: fprintf(fp_hpp, " bool hasMultipleBundles() const {\n"); duke@435: fprintf(fp_hpp, " return (_has_multiple_bundles); }\n\n"); duke@435: fprintf(fp_hpp, " bool forceSerialization() const {\n"); duke@435: fprintf(fp_hpp, " return (_force_serialization); }\n\n"); duke@435: fprintf(fp_hpp, " bool mayHaveNoCode() const {\n"); duke@435: fprintf(fp_hpp, " return (_may_have_no_code); }\n\n"); duke@435: fprintf(fp_hpp, "//const Pipeline_Use_Cycle_Mask& resourceUseMask(int resource) const {\n"); duke@435: fprintf(fp_hpp, "// return (_resource_use_masks[resource]); }\n\n"); duke@435: fprintf(fp_hpp, "\n#ifndef PRODUCT\n"); duke@435: fprintf(fp_hpp, " static const char * stageName(uint i);\n"); duke@435: fprintf(fp_hpp, "#endif\n"); duke@435: fprintf(fp_hpp, "};\n\n"); duke@435: duke@435: fprintf(fp_hpp, "// Bundle class\n"); duke@435: fprintf(fp_hpp, "class Bundle {\n"); duke@435: duke@435: uint mshift = 0; duke@435: for (uint msize = _pipeline->_maxInstrsPerBundle * _pipeline->_maxBundlesPerCycle; msize != 0; msize >>= 1) duke@435: mshift++; duke@435: duke@435: uint rshift = rescount; duke@435: duke@435: fprintf(fp_hpp, "protected:\n"); duke@435: fprintf(fp_hpp, " enum {\n"); duke@435: fprintf(fp_hpp, " _unused_delay = 0x%x,\n", 0); duke@435: fprintf(fp_hpp, " _use_nop_delay = 0x%x,\n", 1); duke@435: fprintf(fp_hpp, " _use_unconditional_delay = 0x%x,\n", 2); duke@435: fprintf(fp_hpp, " _use_conditional_delay = 0x%x,\n", 3); duke@435: fprintf(fp_hpp, " _used_in_conditional_delay = 0x%x,\n", 4); duke@435: fprintf(fp_hpp, " _used_in_unconditional_delay = 0x%x,\n", 5); duke@435: fprintf(fp_hpp, " _used_in_all_conditional_delays = 0x%x,\n", 6); duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, " _use_delay = 0x%x,\n", 3); duke@435: fprintf(fp_hpp, " _used_in_delay = 0x%x\n", 4); duke@435: fprintf(fp_hpp, " };\n\n"); duke@435: fprintf(fp_hpp, " uint _flags : 3,\n"); duke@435: fprintf(fp_hpp, " _starts_bundle : 1,\n"); duke@435: fprintf(fp_hpp, " _instr_count : %d,\n", mshift); duke@435: fprintf(fp_hpp, " _resources_used : %d;\n", rshift); duke@435: fprintf(fp_hpp, "public:\n"); duke@435: fprintf(fp_hpp, " Bundle() : _flags(_unused_delay), _starts_bundle(0), _instr_count(0), _resources_used(0) {}\n\n"); duke@435: fprintf(fp_hpp, " void set_instr_count(uint i) { _instr_count = i; }\n"); duke@435: fprintf(fp_hpp, " void set_resources_used(uint i) { _resources_used = i; }\n"); duke@435: fprintf(fp_hpp, " void clear_usage() { _flags = _unused_delay; }\n"); duke@435: fprintf(fp_hpp, " void set_starts_bundle() { _starts_bundle = true; }\n"); duke@435: duke@435: fprintf(fp_hpp, " uint flags() const { return (_flags); }\n"); duke@435: fprintf(fp_hpp, " uint instr_count() const { return (_instr_count); }\n"); duke@435: fprintf(fp_hpp, " uint resources_used() const { return (_resources_used); }\n"); duke@435: fprintf(fp_hpp, " bool starts_bundle() const { return (_starts_bundle != 0); }\n"); duke@435: duke@435: fprintf(fp_hpp, " void set_use_nop_delay() { _flags = _use_nop_delay; }\n"); duke@435: fprintf(fp_hpp, " void set_use_unconditional_delay() { _flags = _use_unconditional_delay; }\n"); duke@435: fprintf(fp_hpp, " void set_use_conditional_delay() { _flags = _use_conditional_delay; }\n"); duke@435: fprintf(fp_hpp, " void set_used_in_unconditional_delay() { _flags = _used_in_unconditional_delay; }\n"); duke@435: fprintf(fp_hpp, " void set_used_in_conditional_delay() { _flags = _used_in_conditional_delay; }\n"); duke@435: fprintf(fp_hpp, " void set_used_in_all_conditional_delays() { _flags = _used_in_all_conditional_delays; }\n"); duke@435: duke@435: fprintf(fp_hpp, " bool use_nop_delay() { return (_flags == _use_nop_delay); }\n"); duke@435: fprintf(fp_hpp, " bool use_unconditional_delay() { return (_flags == _use_unconditional_delay); }\n"); duke@435: fprintf(fp_hpp, " bool use_conditional_delay() { return (_flags == _use_conditional_delay); }\n"); duke@435: fprintf(fp_hpp, " bool used_in_unconditional_delay() { return (_flags == _used_in_unconditional_delay); }\n"); duke@435: fprintf(fp_hpp, " bool used_in_conditional_delay() { return (_flags == _used_in_conditional_delay); }\n"); duke@435: fprintf(fp_hpp, " bool used_in_all_conditional_delays() { return (_flags == _used_in_all_conditional_delays); }\n"); duke@435: fprintf(fp_hpp, " bool use_delay() { return ((_flags & _use_delay) != 0); }\n"); duke@435: fprintf(fp_hpp, " bool used_in_delay() { return ((_flags & _used_in_delay) != 0); }\n\n"); duke@435: duke@435: fprintf(fp_hpp, " enum {\n"); duke@435: fprintf(fp_hpp, " _nop_count = %d\n", duke@435: _pipeline->_nopcnt); duke@435: fprintf(fp_hpp, " };\n\n"); duke@435: fprintf(fp_hpp, " static void initialize_nops(MachNode *nop_list[%d], Compile* C);\n\n", duke@435: _pipeline->_nopcnt); duke@435: fprintf(fp_hpp, "#ifndef PRODUCT\n"); duke@435: fprintf(fp_hpp, " void dump() const;\n"); duke@435: fprintf(fp_hpp, "#endif\n"); duke@435: fprintf(fp_hpp, "};\n\n"); duke@435: duke@435: // const char *classname; duke@435: // for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) { duke@435: // PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass(); duke@435: // fprintf(fp_hpp, "// Pipeline Class Instance for \"%s\"\n", classname); duke@435: // } duke@435: } duke@435: duke@435: //------------------------------declareClasses--------------------------------- duke@435: // Construct the class hierarchy of MachNode classes from the instruction & duke@435: // operand lists duke@435: void ArchDesc::declareClasses(FILE *fp) { duke@435: duke@435: // Declare an array containing the machine register names, strings. duke@435: declareRegNames(fp, _register); duke@435: duke@435: // Declare an array containing the machine register encoding values duke@435: declareRegEncodes(fp, _register); duke@435: duke@435: // Generate declarations for the total number of operands duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"// Total number of operands defined in architecture definition\n"); duke@435: int num_operands = 0; duke@435: OperandForm *op; duke@435: for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != NULL; ) { duke@435: // Ensure this is a machine-world instruction duke@435: if (op->ideal_only()) continue; duke@435: duke@435: ++num_operands; duke@435: } duke@435: int first_operand_class = num_operands; duke@435: OpClassForm *opc; duke@435: for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != NULL; ) { duke@435: // Ensure this is a machine-world instruction duke@435: if (opc->ideal_only()) continue; duke@435: duke@435: ++num_operands; duke@435: } duke@435: fprintf(fp,"#define FIRST_OPERAND_CLASS %d\n", first_operand_class); duke@435: fprintf(fp,"#define NUM_OPERANDS %d\n", num_operands); duke@435: fprintf(fp,"\n"); duke@435: // Generate declarations for the total number of instructions duke@435: fprintf(fp,"// Total number of instructions defined in architecture definition\n"); duke@435: fprintf(fp,"#define NUM_INSTRUCTIONS %d\n",instructFormCount()); duke@435: duke@435: duke@435: // Generate Machine Classes for each operand defined in AD file duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n"); duke@435: // Iterate through all operands duke@435: _operands.reset(); duke@435: OperandForm *oper; duke@435: for( ; (oper = (OperandForm*)_operands.iter()) != NULL;) { duke@435: // Ensure this is a machine-world instruction duke@435: if (oper->ideal_only() ) continue; duke@435: // The declaration of labelOper is in machine-independent file: machnode duke@435: if ( strcmp(oper->_ident,"label") == 0 ) continue; duke@435: // The declaration of methodOper is in machine-independent file: machnode duke@435: if ( strcmp(oper->_ident,"method") == 0 ) continue; duke@435: duke@435: // Build class definition for this operand duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident); duke@435: fprintf(fp,"private:\n"); duke@435: // Operand definitions that depend upon number of input edges duke@435: { duke@435: uint num_edges = oper->num_edges(_globalNames); duke@435: if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;} duke@435: fprintf(fp," virtual uint num_edges() const { return %d; }\n", duke@435: num_edges ); duke@435: } duke@435: if( num_edges > 0 ) { duke@435: in_RegMask(fp); duke@435: } duke@435: } duke@435: duke@435: // Support storing constants inside the MachOper duke@435: declareConstStorage(fp,_globalNames,oper); duke@435: duke@435: // Support storage of the condition codes duke@435: if( oper->is_ideal_bool() ) { duke@435: fprintf(fp," virtual int ccode() const { \n"); duke@435: fprintf(fp," switch (_c0) {\n"); duke@435: fprintf(fp," case BoolTest::eq : return equal();\n"); duke@435: fprintf(fp," case BoolTest::gt : return greater();\n"); duke@435: fprintf(fp," case BoolTest::lt : return less();\n"); duke@435: fprintf(fp," case BoolTest::ne : return not_equal();\n"); duke@435: fprintf(fp," case BoolTest::le : return less_equal();\n"); duke@435: fprintf(fp," case BoolTest::ge : return greater_equal();\n"); duke@435: fprintf(fp," default : ShouldNotReachHere(); return 0;\n"); duke@435: fprintf(fp," }\n"); duke@435: fprintf(fp," };\n"); duke@435: } duke@435: duke@435: // Support storage of the condition codes duke@435: if( oper->is_ideal_bool() ) { duke@435: fprintf(fp," virtual void negate() { \n"); duke@435: fprintf(fp," _c0 = (BoolTest::mask)((int)_c0^0x4); \n"); duke@435: fprintf(fp," };\n"); duke@435: } duke@435: duke@435: // Declare constructor. duke@435: // Parameters start with condition code, then all other constants duke@435: // duke@435: // (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn) duke@435: // (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { } duke@435: // duke@435: Form::DataType constant_type = oper->simple_type(_globalNames); duke@435: defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames), duke@435: oper->_components, oper->is_ideal_bool(), duke@435: constant_type, _globalNames); duke@435: duke@435: // Clone function duke@435: fprintf(fp," virtual MachOper *clone(Compile* C) const;\n"); duke@435: duke@435: // Support setting a spill offset into a constant operand. duke@435: // We only support setting an 'int' offset, while in the duke@435: // LP64 build spill offsets are added with an AddP which duke@435: // requires a long constant. Thus we don't support spilling duke@435: // in frames larger than 4Gig. duke@435: if( oper->has_conI(_globalNames) || duke@435: oper->has_conL(_globalNames) ) duke@435: fprintf(fp, " virtual void set_con( jint c0 ) { _c0 = c0; }\n"); duke@435: duke@435: // virtual functions for encoding and format duke@435: // fprintf(fp," virtual void encode() const {\n %s }\n", duke@435: // (oper->_encrule)?(oper->_encrule->_encrule):""); duke@435: // Check the interface type, and generate the correct query functions duke@435: // encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER. duke@435: duke@435: fprintf(fp," virtual uint opcode() const { return %s; }\n", duke@435: machOperEnum(oper->_ident)); duke@435: duke@435: // virtual function to look up ideal return type of machine instruction duke@435: // duke@435: // (1) virtual const Type *type() const { return .....; } duke@435: // duke@435: if ((oper->_matrule) && (oper->_matrule->_lChild == NULL) && duke@435: (oper->_matrule->_rChild == NULL)) { duke@435: unsigned int position = 0; duke@435: const char *opret, *opname, *optype; duke@435: oper->_matrule->base_operand(position,_globalNames,opret,opname,optype); duke@435: fprintf(fp," virtual const Type *type() const {"); duke@435: const char *type = getIdealType(optype); duke@435: if( type != NULL ) { duke@435: Form::DataType data_type = oper->is_base_constant(_globalNames); duke@435: // Check if we are an ideal pointer type coleenp@548: if( data_type == Form::idealP || data_type == Form::idealN ) { duke@435: // Return the ideal type we already have: duke@435: fprintf(fp," return _c0;"); duke@435: } else { duke@435: // Return the appropriate bottom type duke@435: fprintf(fp," return %s;", getIdealType(optype)); duke@435: } duke@435: } else { duke@435: fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;"); duke@435: } duke@435: fprintf(fp," }\n"); duke@435: } else { duke@435: // Check for user-defined stack slots, based upon sRegX duke@435: Form::DataType data_type = oper->is_user_name_for_sReg(); duke@435: if( data_type != Form::none ){ duke@435: const char *type = NULL; duke@435: switch( data_type ) { duke@435: case Form::idealI: type = "TypeInt::INT"; break; duke@435: case Form::idealP: type = "TypePtr::BOTTOM";break; duke@435: case Form::idealF: type = "Type::FLOAT"; break; duke@435: case Form::idealD: type = "Type::DOUBLE"; break; duke@435: case Form::idealL: type = "TypeLong::LONG"; break; duke@435: case Form::none: // fall through duke@435: default: duke@435: assert( false, "No support for this type of stackSlot"); duke@435: } duke@435: fprintf(fp," virtual const Type *type() const { return %s; } // stackSlotX\n", type); duke@435: } duke@435: } duke@435: duke@435: duke@435: // duke@435: // virtual functions for defining the encoding interface. duke@435: // duke@435: // Access the linearized ideal register mask, duke@435: // map to physical register encoding duke@435: if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) { duke@435: // Just use the default virtual 'reg' call duke@435: } else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) { duke@435: // Special handling for operand 'sReg', a Stack Slot Register. duke@435: // Map linearized ideal register mask to stack slot number duke@435: fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node) const {\n"); duke@435: fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n"); duke@435: fprintf(fp," }\n"); duke@435: fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n"); duke@435: fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n"); duke@435: fprintf(fp," }\n"); duke@435: } duke@435: duke@435: // Output the operand specific access functions used by an enc_class duke@435: // These are only defined when we want to override the default virtual func duke@435: if (oper->_interface != NULL) { duke@435: fprintf(fp,"\n"); duke@435: // Check if it is a Memory Interface duke@435: if ( oper->_interface->is_MemInterface() != NULL ) { duke@435: MemInterface *mem_interface = oper->_interface->is_MemInterface(); duke@435: const char *base = mem_interface->_base; duke@435: if( base != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "base", base); duke@435: } duke@435: char *index = mem_interface->_index; duke@435: if( index != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "index", index); duke@435: } duke@435: const char *scale = mem_interface->_scale; duke@435: if( scale != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "scale", scale); duke@435: } duke@435: const char *disp = mem_interface->_disp; duke@435: if( disp != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "disp", disp); duke@435: oper->disp_is_oop(fp, _globalNames); duke@435: } duke@435: if( oper->stack_slots_only(_globalNames) ) { duke@435: // should not call this: duke@435: fprintf(fp," virtual int constant_disp() const { return Type::OffsetBot; }"); duke@435: } else if ( disp != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp); duke@435: } duke@435: } // end Memory Interface duke@435: // Check if it is a Conditional Interface duke@435: else if (oper->_interface->is_CondInterface() != NULL) { duke@435: CondInterface *cInterface = oper->_interface->is_CondInterface(); duke@435: const char *equal = cInterface->_equal; duke@435: if( equal != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "equal", equal); duke@435: } duke@435: const char *not_equal = cInterface->_not_equal; duke@435: if( not_equal != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal); duke@435: } duke@435: const char *less = cInterface->_less; duke@435: if( less != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "less", less); duke@435: } duke@435: const char *greater_equal = cInterface->_greater_equal; duke@435: if( greater_equal != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal); duke@435: } duke@435: const char *less_equal = cInterface->_less_equal; duke@435: if( less_equal != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal); duke@435: } duke@435: const char *greater = cInterface->_greater; duke@435: if( greater != NULL ) { duke@435: define_oper_interface(fp, *oper, _globalNames, "greater", greater); duke@435: } duke@435: } // end Conditional Interface duke@435: // Check if it is a Constant Interface duke@435: else if (oper->_interface->is_ConstInterface() != NULL ) { duke@435: assert( oper->num_consts(_globalNames) == 1, duke@435: "Must have one constant when using CONST_INTER encoding"); duke@435: if (!strcmp(oper->ideal_type(_globalNames), "ConI")) { duke@435: // Access the locally stored constant duke@435: fprintf(fp," virtual intptr_t constant() const {"); duke@435: fprintf(fp, " return (intptr_t)_c0;"); duke@435: fprintf(fp," }\n"); duke@435: } duke@435: else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) { duke@435: // Access the locally stored constant duke@435: fprintf(fp," virtual intptr_t constant() const {"); duke@435: fprintf(fp, " return _c0->get_con();"); duke@435: fprintf(fp, " }\n"); duke@435: // Generate query to determine if this pointer is an oop duke@435: fprintf(fp," virtual bool constant_is_oop() const {"); duke@435: fprintf(fp, " return _c0->isa_oop_ptr();"); duke@435: fprintf(fp, " }\n"); duke@435: } coleenp@548: else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) { coleenp@548: // Access the locally stored constant coleenp@548: fprintf(fp," virtual intptr_t constant() const {"); coleenp@548: fprintf(fp, " return _c0->make_oopptr()->get_con();"); coleenp@548: fprintf(fp, " }\n"); coleenp@548: // Generate query to determine if this pointer is an oop coleenp@548: fprintf(fp," virtual bool constant_is_oop() const {"); coleenp@548: fprintf(fp, " return _c0->make_oopptr()->isa_oop_ptr();"); coleenp@548: fprintf(fp, " }\n"); coleenp@548: } duke@435: else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) { duke@435: fprintf(fp," virtual intptr_t constant() const {"); duke@435: // We don't support addressing modes with > 4Gig offsets. duke@435: // Truncate to int. duke@435: fprintf(fp, " return (intptr_t)_c0;"); duke@435: fprintf(fp, " }\n"); duke@435: fprintf(fp," virtual jlong constantL() const {"); duke@435: fprintf(fp, " return _c0;"); duke@435: fprintf(fp, " }\n"); duke@435: } duke@435: else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) { duke@435: fprintf(fp," virtual intptr_t constant() const {"); duke@435: fprintf(fp, " ShouldNotReachHere(); return 0; "); duke@435: fprintf(fp, " }\n"); duke@435: fprintf(fp," virtual jfloat constantF() const {"); duke@435: fprintf(fp, " return (jfloat)_c0;"); duke@435: fprintf(fp, " }\n"); duke@435: } duke@435: else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) { duke@435: fprintf(fp," virtual intptr_t constant() const {"); duke@435: fprintf(fp, " ShouldNotReachHere(); return 0; "); duke@435: fprintf(fp, " }\n"); duke@435: fprintf(fp," virtual jdouble constantD() const {"); duke@435: fprintf(fp, " return _c0;"); duke@435: fprintf(fp, " }\n"); duke@435: } duke@435: } duke@435: else if (oper->_interface->is_RegInterface() != NULL) { duke@435: // make sure that a fixed format string isn't used for an duke@435: // operand which might be assiged to multiple registers. duke@435: // Otherwise the opto assembly output could be misleading. duke@435: if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) { duke@435: syntax_err(oper->_linenum, duke@435: "Only bound registers can have fixed formats: %s\n", duke@435: oper->_ident); duke@435: } duke@435: } duke@435: else { duke@435: assert( false, "ShouldNotReachHere();"); duke@435: } duke@435: } duke@435: duke@435: fprintf(fp,"\n"); duke@435: // // Currently all XXXOper::hash() methods are identical (990820) duke@435: // declare_hash(fp); duke@435: // // Currently all XXXOper::Cmp() methods are identical (990820) duke@435: // declare_cmp(fp); duke@435: duke@435: // Do not place dump_spec() and Name() into PRODUCT code duke@435: // int_format and ext_format are not needed in PRODUCT code either duke@435: fprintf(fp, "#ifndef PRODUCT\n"); duke@435: duke@435: // Declare int_format() and ext_format() duke@435: gen_oper_format(fp, _globalNames, *oper); duke@435: duke@435: // Machine independent print functionality for debugging duke@435: // IF we have constants, create a dump_spec function for the derived class duke@435: // duke@435: // (1) virtual void dump_spec() const { duke@435: // (2) st->print("#%d", _c#); // Constant != ConP duke@435: // OR _c#->dump_on(st); // Type ConP duke@435: // ... duke@435: // (3) } duke@435: uint num_consts = oper->num_consts(_globalNames); duke@435: if( num_consts > 0 ) { duke@435: // line (1) duke@435: fprintf(fp, " virtual void dump_spec(outputStream *st) const {\n"); duke@435: // generate format string for st->print duke@435: // Iterate over the component list & spit out the right thing duke@435: uint i = 0; duke@435: const char *type = oper->ideal_type(_globalNames); duke@435: Component *comp; duke@435: oper->_components.reset(); duke@435: if ((comp = oper->_components.iter()) == NULL) { duke@435: assert(num_consts == 1, "Bad component list detected.\n"); never@850: i = dump_spec_constant( fp, type, i, oper ); duke@435: // Check that type actually matched duke@435: assert( i != 0, "Non-constant operand lacks component list."); duke@435: } // end if NULL duke@435: else { duke@435: // line (2) duke@435: // dump all components duke@435: oper->_components.reset(); duke@435: while((comp = oper->_components.iter()) != NULL) { duke@435: type = comp->base_type(_globalNames); never@850: i = dump_spec_constant( fp, type, i, NULL ); duke@435: } duke@435: } duke@435: // finish line (3) duke@435: fprintf(fp," }\n"); duke@435: } duke@435: duke@435: fprintf(fp," virtual const char *Name() const { return \"%s\";}\n", duke@435: oper->_ident); duke@435: duke@435: fprintf(fp,"#endif\n"); duke@435: duke@435: // Close definition of this XxxMachOper duke@435: fprintf(fp,"};\n"); duke@435: } duke@435: duke@435: duke@435: // Generate Machine Classes for each instruction defined in AD file duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n"); duke@435: declare_pipe_classes(fp); duke@435: duke@435: // Generate Machine Classes for each instruction defined in AD file duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n"); duke@435: _instructions.reset(); duke@435: InstructForm *instr; duke@435: for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { duke@435: // Ensure this is a machine-world instruction duke@435: if ( instr->ideal_only() ) continue; duke@435: duke@435: // Build class definition for this instruction duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"class %sNode : public %s { \n", duke@435: instr->_ident, instr->mach_base_class() ); duke@435: fprintf(fp,"private:\n"); duke@435: fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() ); duke@435: if ( instr->is_ideal_jump() ) { duke@435: fprintf(fp, " GrowableArray _index2label;\n"); duke@435: } duke@435: fprintf(fp,"public:\n"); duke@435: fprintf(fp," MachOper *opnd_array(uint operand_index) const { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); return _opnd_array[operand_index]; }\n"); duke@435: fprintf(fp," void set_opnd_array(uint operand_index, MachOper *operand) { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); _opnd_array[operand_index] = operand; }\n"); duke@435: fprintf(fp,"private:\n"); duke@435: if ( instr->is_ideal_jump() ) { duke@435: fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n"); duke@435: fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);}\n"); duke@435: } duke@435: if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) { duke@435: fprintf(fp," const RegMask *_cisc_RegMask;\n"); duke@435: } duke@435: duke@435: out_RegMask(fp); // output register mask duke@435: fprintf(fp," virtual uint rule() const { return %s_rule; }\n", duke@435: instr->_ident); duke@435: duke@435: // If this instruction contains a labelOper duke@435: // Declare Node::methods that set operand Label's contents duke@435: int label_position = instr->label_position(); duke@435: if( label_position != -1 ) { duke@435: // Set the label, stored in labelOper::_branch_label duke@435: fprintf(fp," virtual void label_set( Label& label, uint block_num );\n"); duke@435: } duke@435: duke@435: // If this instruction contains a methodOper duke@435: // Declare Node::methods that set operand method's contents duke@435: int method_position = instr->method_position(); duke@435: if( method_position != -1 ) { duke@435: // Set the address method, stored in methodOper::_method duke@435: fprintf(fp," virtual void method_set( intptr_t method );\n"); duke@435: } duke@435: duke@435: // virtual functions for attributes duke@435: // duke@435: // Each instruction attribute results in a virtual call of same name. duke@435: // The ins_cost is not handled here. duke@435: Attribute *attr = instr->_attribs; duke@435: bool is_pc_relative = false; duke@435: while (attr != NULL) { duke@435: if (strcmp(attr->_ident,"ins_cost") && duke@435: strcmp(attr->_ident,"ins_pc_relative")) { duke@435: fprintf(fp," int %s() const { return %s; }\n", duke@435: attr->_ident, attr->_val); duke@435: } duke@435: // Check value for ins_pc_relative, and if it is true (1), set the flag duke@435: if (!strcmp(attr->_ident,"ins_pc_relative") && attr->int_val(*this) != 0) duke@435: is_pc_relative = true; duke@435: attr = (Attribute *)attr->_next; duke@435: } duke@435: duke@435: // virtual functions for encode and format duke@435: // duke@435: // Output the opcode function and the encode function here using the duke@435: // encoding class information in the _insencode slot. duke@435: if ( instr->_insencode ) { duke@435: fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n"); duke@435: } duke@435: duke@435: // virtual function for getting the size of an instruction duke@435: if ( instr->_size ) { duke@435: fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n"); duke@435: } duke@435: duke@435: // Return the top-level ideal opcode. duke@435: // Use MachNode::ideal_Opcode() for nodes based on MachNode class duke@435: // if the ideal_Opcode == Op_Node. duke@435: if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 || duke@435: strcmp("MachNode", instr->mach_base_class()) != 0 ) { duke@435: fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n", duke@435: instr->ideal_Opcode(_globalNames) ); duke@435: } duke@435: duke@435: // Allow machine-independent optimization, invert the sense of the IF test duke@435: if( instr->is_ideal_if() ) { duke@435: fprintf(fp," virtual void negate() { \n"); duke@435: // Identify which operand contains the negate(able) ideal condition code duke@435: int idx = 0; duke@435: instr->_components.reset(); duke@435: for( Component *comp; (comp = instr->_components.iter()) != NULL; ) { duke@435: // Check that component is an operand duke@435: Form *form = (Form*)_globalNames[comp->_type]; duke@435: OperandForm *opForm = form ? form->is_operand() : NULL; duke@435: if( opForm == NULL ) continue; duke@435: duke@435: // Lookup the position of the operand in the instruction. duke@435: if( opForm->is_ideal_bool() ) { duke@435: idx = instr->operand_position(comp->_name, comp->_usedef); duke@435: assert( idx != NameList::Not_in_list, "Did not find component in list that contained it."); duke@435: break; duke@435: } duke@435: } duke@435: fprintf(fp," opnd_array(%d)->negate();\n", idx); duke@435: fprintf(fp," _prob = 1.0f - _prob;\n"); duke@435: fprintf(fp," };\n"); duke@435: } duke@435: duke@435: duke@435: // Identify which input register matches the input register. duke@435: uint matching_input = instr->two_address(_globalNames); duke@435: duke@435: // Generate the method if it returns != 0 otherwise use MachNode::two_adr() duke@435: if( matching_input != 0 ) { duke@435: fprintf(fp," virtual uint two_adr() const "); duke@435: fprintf(fp,"{ return oper_input_base()"); duke@435: for( uint i = 2; i <= matching_input; i++ ) duke@435: fprintf(fp," + opnd_array(%d)->num_edges()",i-1); duke@435: fprintf(fp,"; }\n"); duke@435: } duke@435: duke@435: // Declare cisc_version, if applicable duke@435: // MachNode *cisc_version( int offset /* ,... */ ); duke@435: instr->declare_cisc_version(*this, fp); duke@435: duke@435: // If there is an explicit peephole rule, build it duke@435: if ( instr->peepholes() != NULL ) { duke@435: fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile *C);\n"); duke@435: } duke@435: duke@435: // Output the declaration for number of relocation entries duke@435: if ( instr->reloc(_globalNames) != 0 ) { duke@435: fprintf(fp," virtual int reloc() const;\n"); duke@435: } duke@435: duke@435: if (instr->alignment() != 1) { duke@435: fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment()); duke@435: fprintf(fp," virtual int compute_padding(int current_offset) const;\n"); duke@435: } duke@435: duke@435: // Starting point for inputs matcher wants. duke@435: // Use MachNode::oper_input_base() for nodes based on MachNode class duke@435: // if the base == 1. duke@435: if ( instr->oper_input_base(_globalNames) != 1 || duke@435: strcmp("MachNode", instr->mach_base_class()) != 0 ) { duke@435: fprintf(fp," virtual uint oper_input_base() const { return %d; }\n", duke@435: instr->oper_input_base(_globalNames)); duke@435: } duke@435: duke@435: // Make the constructor and following methods 'public:' duke@435: fprintf(fp,"public:\n"); duke@435: duke@435: // Constructor duke@435: if ( instr->is_ideal_jump() ) { duke@435: fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident); duke@435: } else { duke@435: fprintf(fp," %sNode() { ", instr->_ident); duke@435: if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) { duke@435: fprintf(fp,"_cisc_RegMask = NULL; "); duke@435: } duke@435: } duke@435: duke@435: fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds()); duke@435: duke@435: bool node_flags_set = false; duke@435: // flag: if this instruction matches an ideal 'Goto' node duke@435: if ( instr->is_ideal_goto() ) { duke@435: fprintf(fp,"init_flags(Flag_is_Goto"); duke@435: node_flags_set = true; duke@435: } duke@435: duke@435: // flag: if this instruction matches an ideal 'Copy*' node duke@435: if ( instr->is_ideal_copy() != 0 ) { duke@435: if ( node_flags_set ) { duke@435: fprintf(fp," | Flag_is_Copy"); duke@435: } else { duke@435: fprintf(fp,"init_flags(Flag_is_Copy"); duke@435: node_flags_set = true; duke@435: } duke@435: } duke@435: duke@435: // Is an instruction is a constant? If so, get its type duke@435: Form::DataType data_type; duke@435: const char *opType = NULL; duke@435: const char *result = NULL; duke@435: data_type = instr->is_chain_of_constant(_globalNames, opType, result); duke@435: // Check if this instruction is a constant duke@435: if ( data_type != Form::none ) { duke@435: if ( node_flags_set ) { duke@435: fprintf(fp," | Flag_is_Con"); duke@435: } else { duke@435: fprintf(fp,"init_flags(Flag_is_Con"); duke@435: node_flags_set = true; duke@435: } duke@435: } duke@435: duke@435: // flag: if instruction matches 'If' | 'Goto' | 'CountedLoopEnd | 'Jump' duke@435: if ( instr->is_ideal_branch() ) { duke@435: if ( node_flags_set ) { duke@435: fprintf(fp," | Flag_is_Branch"); duke@435: } else { duke@435: fprintf(fp,"init_flags(Flag_is_Branch"); duke@435: node_flags_set = true; duke@435: } duke@435: } duke@435: duke@435: // flag: if this instruction is cisc alternate duke@435: if ( can_cisc_spill() && instr->is_cisc_alternate() ) { duke@435: if ( node_flags_set ) { duke@435: fprintf(fp," | Flag_is_cisc_alternate"); duke@435: } else { duke@435: fprintf(fp,"init_flags(Flag_is_cisc_alternate"); duke@435: node_flags_set = true; duke@435: } duke@435: } duke@435: duke@435: // flag: if this instruction is pc relative duke@435: if ( is_pc_relative ) { duke@435: if ( node_flags_set ) { duke@435: fprintf(fp," | Flag_is_pc_relative"); duke@435: } else { duke@435: fprintf(fp,"init_flags(Flag_is_pc_relative"); duke@435: node_flags_set = true; duke@435: } duke@435: } duke@435: duke@435: // flag: if this instruction has short branch form duke@435: if ( instr->has_short_branch_form() ) { duke@435: if ( node_flags_set ) { duke@435: fprintf(fp," | Flag_may_be_short_branch"); duke@435: } else { duke@435: fprintf(fp,"init_flags(Flag_may_be_short_branch"); duke@435: node_flags_set = true; duke@435: } duke@435: } duke@435: duke@435: // Check if machine instructions that USE memory, but do not DEF memory, duke@435: // depend upon a node that defines memory in machine-independent graph. duke@435: if ( instr->needs_anti_dependence_check(_globalNames) ) { duke@435: if ( node_flags_set ) { duke@435: fprintf(fp," | Flag_needs_anti_dependence_check"); duke@435: } else { duke@435: fprintf(fp,"init_flags(Flag_needs_anti_dependence_check"); duke@435: node_flags_set = true; duke@435: } duke@435: } duke@435: duke@435: if ( node_flags_set ) { duke@435: fprintf(fp,"); "); duke@435: } duke@435: duke@435: if (instr->is_ideal_unlock() || instr->is_ideal_call_leaf()) { duke@435: fprintf(fp,"clear_flag(Flag_is_safepoint_node); "); duke@435: } duke@435: duke@435: fprintf(fp,"}\n"); duke@435: duke@435: // size_of, used by base class's clone to obtain the correct size. duke@435: fprintf(fp," virtual uint size_of() const {"); duke@435: fprintf(fp, " return sizeof(%sNode);", instr->_ident); duke@435: fprintf(fp, " }\n"); duke@435: duke@435: // Virtual methods which are only generated to override base class duke@435: if( instr->expands() || instr->needs_projections() || duke@435: instr->has_temps() || duke@435: instr->_matrule != NULL && duke@435: instr->num_opnds() != instr->num_unique_opnds() ) { duke@435: fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list);\n"); duke@435: } duke@435: duke@435: if (instr->is_pinned(_globalNames)) { duke@435: fprintf(fp," virtual bool pinned() const { return "); duke@435: if (instr->is_parm(_globalNames)) { duke@435: fprintf(fp,"_in[0]->pinned();"); duke@435: } else { duke@435: fprintf(fp,"true;"); duke@435: } duke@435: fprintf(fp," }\n"); duke@435: } duke@435: if (instr->is_projection(_globalNames)) { duke@435: fprintf(fp," virtual const Node *is_block_proj() const { return this; }\n"); duke@435: } duke@435: if ( instr->num_post_match_opnds() != 0 duke@435: || instr->is_chain_of_constant(_globalNames) ) { duke@435: fprintf(fp," friend MachNode *State::MachNodeGenerator(int opcode, Compile* C);\n"); duke@435: } duke@435: if ( instr->rematerialize(_globalNames, get_registers()) ) { duke@435: fprintf(fp," // Rematerialize %s\n", instr->_ident); duke@435: } duke@435: duke@435: // Declare short branch methods, if applicable duke@435: instr->declare_short_branch_methods(fp); duke@435: duke@435: // Instructions containing a constant that will be entered into the duke@435: // float/double table redefine the base virtual function duke@435: #ifdef SPARC duke@435: // Sparc doubles entries in the constant table require more space for duke@435: // alignment. (expires 9/98) duke@435: int table_entries = (3 * instr->num_consts( _globalNames, Form::idealD )) duke@435: + instr->num_consts( _globalNames, Form::idealF ); duke@435: #else duke@435: int table_entries = instr->num_consts( _globalNames, Form::idealD ) duke@435: + instr->num_consts( _globalNames, Form::idealF ); duke@435: #endif duke@435: if( table_entries != 0 ) { duke@435: fprintf(fp," virtual int const_size() const {"); duke@435: fprintf(fp, " return %d;", table_entries); duke@435: fprintf(fp, " }\n"); duke@435: } duke@435: duke@435: duke@435: // See if there is an "ins_pipe" declaration for this instruction duke@435: if (instr->_ins_pipe) { duke@435: fprintf(fp," static const Pipeline *pipeline_class();\n"); duke@435: fprintf(fp," virtual const Pipeline *pipeline() const;\n"); duke@435: } duke@435: duke@435: // Generate virtual function for MachNodeX::bottom_type when necessary duke@435: // duke@435: // Note on accuracy: Pointer-types of machine nodes need to be accurate, duke@435: // or else alias analysis on the matched graph may produce bad code. duke@435: // Moreover, the aliasing decisions made on machine-node graph must be duke@435: // no less accurate than those made on the ideal graph, or else the graph duke@435: // may fail to schedule. (Reason: Memory ops which are reordered in duke@435: // the ideal graph might look interdependent in the machine graph, duke@435: // thereby removing degrees of scheduling freedom that the optimizer duke@435: // assumed would be available.) duke@435: // duke@435: // %%% We should handle many of these cases with an explicit ADL clause: duke@435: // instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %} duke@435: if( data_type != Form::none ) { duke@435: // A constant's bottom_type returns a Type containing its constant value duke@435: duke@435: // !!!!! duke@435: // Convert all ints, floats, ... to machine-independent TypeXs duke@435: // as is done for pointers duke@435: // duke@435: // Construct appropriate constant type containing the constant value. duke@435: fprintf(fp," virtual const class Type *bottom_type() const{\n"); duke@435: switch( data_type ) { duke@435: case Form::idealI: duke@435: fprintf(fp," return TypeInt::make(opnd_array(1)->constant());\n"); duke@435: break; duke@435: case Form::idealP: coleenp@548: case Form::idealN: twisti@1038: fprintf(fp," return opnd_array(1)->type();\n"); duke@435: break; duke@435: case Form::idealD: duke@435: fprintf(fp," return TypeD::make(opnd_array(1)->constantD());\n"); duke@435: break; duke@435: case Form::idealF: duke@435: fprintf(fp," return TypeF::make(opnd_array(1)->constantF());\n"); duke@435: break; duke@435: case Form::idealL: duke@435: fprintf(fp," return TypeLong::make(opnd_array(1)->constantL());\n"); duke@435: break; duke@435: default: duke@435: assert( false, "Unimplemented()" ); duke@435: break; duke@435: } duke@435: fprintf(fp," };\n"); duke@435: } duke@435: /* else if ( instr->_matrule && instr->_matrule->_rChild && duke@435: ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0 duke@435: || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) { duke@435: // !!!!! !!!!! duke@435: // Provide explicit bottom type for conversions to int duke@435: // On Intel the result operand is a stackSlot, untyped. duke@435: fprintf(fp," virtual const class Type *bottom_type() const{"); duke@435: fprintf(fp, " return TypeInt::INT;"); duke@435: fprintf(fp, " };\n"); duke@435: }*/ duke@435: else if( instr->is_ideal_copy() && duke@435: !strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) { duke@435: // !!!!! duke@435: // Special hack for ideal Copy of pointer. Bottom type is oop or not depending on input. duke@435: fprintf(fp," const Type *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n"); duke@435: } duke@435: else if( instr->is_ideal_loadPC() ) { duke@435: // LoadPCNode provides the return address of a call to native code. duke@435: // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM duke@435: // since it is a pointer to an internal VM location and must have a zero offset. duke@435: // Allocation detects derived pointers, in part, by their non-zero offsets. duke@435: fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n"); duke@435: } duke@435: else if( instr->is_ideal_box() ) { duke@435: // BoxNode provides the address of a stack slot. duke@435: // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM duke@435: // This prevent s insert_anti_dependencies from complaining. It will duke@435: // complain if it see that the pointer base is TypePtr::BOTTOM since duke@435: // it doesn't understand what that might alias. duke@435: fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n"); duke@435: } duke@435: else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveP") ) { duke@435: int offset = 1; duke@435: // Special special hack to see if the Cmp? has been incorporated in the conditional move duke@435: MatchNode *rl = instr->_matrule->_rChild->_lChild; duke@435: if( rl && !strcmp(rl->_opType, "Binary") ) { duke@435: MatchNode *rlr = rl->_rChild; duke@435: if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0) duke@435: offset = 2; duke@435: } duke@435: // Special hack for ideal CMoveP; ideal type depends on inputs duke@435: fprintf(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", duke@435: offset, offset+1, offset+1); duke@435: } kvn@728: else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) { kvn@728: int offset = 1; kvn@728: // Special special hack to see if the Cmp? has been incorporated in the conditional move kvn@728: MatchNode *rl = instr->_matrule->_rChild->_lChild; kvn@728: if( rl && !strcmp(rl->_opType, "Binary") ) { kvn@728: MatchNode *rlr = rl->_rChild; kvn@728: if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0) kvn@728: offset = 2; kvn@728: } kvn@728: // Special hack for ideal CMoveN; ideal type depends on inputs kvn@728: fprintf(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", kvn@728: offset, offset+1, offset+1); kvn@728: } duke@435: else if( instr->needs_base_oop_edge(_globalNames) ) { duke@435: // Special hack for ideal AddP. Bottom type is an oop IFF it has a duke@435: // legal base-pointer input. Otherwise it is NOT an oop. duke@435: fprintf(fp," const Type *bottom_type() const { return AddPNode::mach_bottom_type(this); } // AddP\n"); duke@435: } duke@435: else if (instr->is_tls_instruction()) { duke@435: // Special hack for tlsLoadP duke@435: fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n"); duke@435: } duke@435: else if ( instr->is_ideal_if() ) { duke@435: fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n"); duke@435: } duke@435: else if ( instr->is_ideal_membar() ) { duke@435: fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n"); duke@435: } duke@435: duke@435: // Check where 'ideal_type' must be customized duke@435: /* duke@435: if ( instr->_matrule && instr->_matrule->_rChild && duke@435: ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0 duke@435: || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) { duke@435: fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n"); duke@435: }*/ duke@435: duke@435: // Analyze machine instructions that either USE or DEF memory. duke@435: int memory_operand = instr->memory_operand(_globalNames); duke@435: // Some guys kill all of memory duke@435: if ( instr->is_wide_memory_kill(_globalNames) ) { duke@435: memory_operand = InstructForm::MANY_MEMORY_OPERANDS; duke@435: } duke@435: if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) { duke@435: if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) { duke@435: fprintf(fp," virtual const TypePtr *adr_type() const;\n"); duke@435: } duke@435: fprintf(fp," virtual const MachOper *memory_operand() const;\n"); duke@435: } duke@435: duke@435: fprintf(fp, "#ifndef PRODUCT\n"); duke@435: duke@435: // virtual function for generating the user's assembler output duke@435: gen_inst_format(fp, _globalNames,*instr); duke@435: duke@435: // Machine independent print functionality for debugging duke@435: fprintf(fp," virtual const char *Name() const { return \"%s\";}\n", duke@435: instr->_ident); duke@435: duke@435: fprintf(fp, "#endif\n"); duke@435: duke@435: // Close definition of this XxxMachNode duke@435: fprintf(fp,"};\n"); duke@435: }; duke@435: duke@435: } duke@435: duke@435: void ArchDesc::defineStateClass(FILE *fp) { duke@435: static const char *state__valid = "_valid[((uint)index) >> 5] & (0x1 << (((uint)index) & 0x0001F))"; duke@435: static const char *state__set_valid= "_valid[((uint)index) >> 5] |= (0x1 << (((uint)index) & 0x0001F))"; duke@435: duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"// MACROS to inline and constant fold State::valid(index)...\n"); duke@435: fprintf(fp,"// when given a constant 'index' in dfa_.cpp\n"); duke@435: fprintf(fp,"// uint word = index >> 5; // Shift out bit position\n"); duke@435: fprintf(fp,"// uint bitpos = index & 0x0001F; // Mask off word bits\n"); duke@435: fprintf(fp,"#define STATE__VALID(index) "); duke@435: fprintf(fp," (%s)\n", state__valid); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"#define STATE__NOT_YET_VALID(index) "); duke@435: fprintf(fp," ( (%s) == 0 )\n", state__valid); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"#define STATE__VALID_CHILD(state,index) "); duke@435: fprintf(fp," ( state && (state->%s) )\n", state__valid); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"#define STATE__SET_VALID(index) "); duke@435: fprintf(fp," (%s)\n", state__set_valid); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp, duke@435: "//---------------------------State-------------------------------------------\n"); duke@435: fprintf(fp,"// State contains an integral cost vector, indexed by machine operand opcodes,\n"); duke@435: fprintf(fp,"// a rule vector consisting of machine operand/instruction opcodes, and also\n"); duke@435: fprintf(fp,"// indexed by machine operand opcodes, pointers to the children in the label\n"); duke@435: fprintf(fp,"// tree generated by the Label routines in ideal nodes (currently limited to\n"); duke@435: fprintf(fp,"// two for convenience, but this could change).\n"); duke@435: fprintf(fp,"class State : public ResourceObj {\n"); duke@435: fprintf(fp,"public:\n"); duke@435: fprintf(fp," int _id; // State identifier\n"); duke@435: fprintf(fp," Node *_leaf; // Ideal (non-machine-node) leaf of match tree\n"); duke@435: fprintf(fp," State *_kids[2]; // Children of state node in label tree\n"); duke@435: fprintf(fp," unsigned int _cost[_LAST_MACH_OPER]; // Cost vector, indexed by operand opcodes\n"); duke@435: fprintf(fp," unsigned int _rule[_LAST_MACH_OPER]; // Rule vector, indexed by operand opcodes\n"); duke@435: fprintf(fp," unsigned int _valid[(_LAST_MACH_OPER/32)+1]; // Bit Map of valid Cost/Rule entries\n"); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp," State(void); // Constructor\n"); duke@435: fprintf(fp," DEBUG_ONLY( ~State(void); ) // Destructor\n"); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp," // Methods created by ADLC and invoked by Reduce\n"); duke@435: fprintf(fp," MachOper *MachOperGenerator( int opcode, Compile* C );\n"); duke@435: fprintf(fp," MachNode *MachNodeGenerator( int opcode, Compile* C );\n"); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp," // Assign a state to a node, definition of method produced by ADLC\n"); duke@435: fprintf(fp," bool DFA( int opcode, const Node *ideal );\n"); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp," // Access function for _valid bit vector\n"); duke@435: fprintf(fp," bool valid(uint index) {\n"); duke@435: fprintf(fp," return( STATE__VALID(index) != 0 );\n"); duke@435: fprintf(fp," }\n"); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp," // Set function for _valid bit vector\n"); duke@435: fprintf(fp," void set_valid(uint index) {\n"); duke@435: fprintf(fp," STATE__SET_VALID(index);\n"); duke@435: fprintf(fp," }\n"); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"#ifndef PRODUCT\n"); duke@435: fprintf(fp," void dump(); // Debugging prints\n"); duke@435: fprintf(fp," void dump(int depth);\n"); duke@435: fprintf(fp,"#endif\n"); duke@435: if (_dfa_small) { duke@435: // Generate the routine name we'll need duke@435: for (int i = 1; i < _last_opcode; i++) { duke@435: if (_mlistab[i] == NULL) continue; duke@435: fprintf(fp, " void _sub_Op_%s(const Node *n);\n", NodeClassNames[i]); duke@435: } duke@435: } duke@435: fprintf(fp,"};\n"); duke@435: fprintf(fp,"\n"); duke@435: fprintf(fp,"\n"); duke@435: duke@435: } duke@435: duke@435: duke@435: //---------------------------buildMachOperEnum--------------------------------- duke@435: // Build enumeration for densely packed operands. duke@435: // This enumeration is used to index into the arrays in the State objects duke@435: // that indicate cost and a successfull rule match. duke@435: duke@435: // Information needed to generate the ReduceOp mapping for the DFA duke@435: class OutputMachOperands : public OutputMap { duke@435: public: duke@435: OutputMachOperands(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) duke@435: : OutputMap(hpp, cpp, globals, AD) {}; duke@435: duke@435: void declaration() { } duke@435: void definition() { fprintf(_cpp, "enum MachOperands {\n"); } duke@435: void closing() { fprintf(_cpp, " _LAST_MACH_OPER\n"); duke@435: OutputMap::closing(); duke@435: } duke@435: void map(OpClassForm &opc) { fprintf(_cpp, " %s", _AD.machOperEnum(opc._ident) ); } duke@435: void map(OperandForm &oper) { fprintf(_cpp, " %s", _AD.machOperEnum(oper._ident) ); } duke@435: void map(char *name) { fprintf(_cpp, " %s", _AD.machOperEnum(name)); } duke@435: duke@435: bool do_instructions() { return false; } duke@435: void map(InstructForm &inst){ assert( false, "ShouldNotCallThis()"); } duke@435: }; duke@435: duke@435: duke@435: void ArchDesc::buildMachOperEnum(FILE *fp_hpp) { duke@435: // Construct the table for MachOpcodes duke@435: OutputMachOperands output_mach_operands(fp_hpp, fp_hpp, _globalNames, *this); duke@435: build_map(output_mach_operands); duke@435: } duke@435: duke@435: duke@435: //---------------------------buildMachEnum---------------------------------- duke@435: // Build enumeration for all MachOpers and all MachNodes duke@435: duke@435: // Information needed to generate the ReduceOp mapping for the DFA duke@435: class OutputMachOpcodes : public OutputMap { duke@435: int begin_inst_chain_rule; duke@435: int end_inst_chain_rule; duke@435: int begin_rematerialize; duke@435: int end_rematerialize; duke@435: int end_instructions; duke@435: public: duke@435: OutputMachOpcodes(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD) duke@435: : OutputMap(hpp, cpp, globals, AD), duke@435: begin_inst_chain_rule(-1), end_inst_chain_rule(-1), end_instructions(-1) duke@435: {}; duke@435: duke@435: void declaration() { } duke@435: void definition() { fprintf(_cpp, "enum MachOpcodes {\n"); } duke@435: void closing() { duke@435: if( begin_inst_chain_rule != -1 ) duke@435: fprintf(_cpp, " _BEGIN_INST_CHAIN_RULE = %d,\n", begin_inst_chain_rule); duke@435: if( end_inst_chain_rule != -1 ) duke@435: fprintf(_cpp, " _END_INST_CHAIN_RULE = %d,\n", end_inst_chain_rule); duke@435: if( begin_rematerialize != -1 ) duke@435: fprintf(_cpp, " _BEGIN_REMATERIALIZE = %d,\n", begin_rematerialize); duke@435: if( end_rematerialize != -1 ) duke@435: fprintf(_cpp, " _END_REMATERIALIZE = %d,\n", end_rematerialize); duke@435: // always execute since do_instructions() is true, and avoids trailing comma duke@435: fprintf(_cpp, " _last_Mach_Node = %d \n", end_instructions); duke@435: OutputMap::closing(); duke@435: } duke@435: void map(OpClassForm &opc) { fprintf(_cpp, " %s_rule", opc._ident ); } duke@435: void map(OperandForm &oper) { fprintf(_cpp, " %s_rule", oper._ident ); } duke@435: void map(char *name) { if (name) fprintf(_cpp, " %s_rule", name); duke@435: else fprintf(_cpp, " 0"); } duke@435: void map(InstructForm &inst) {fprintf(_cpp, " %s_rule", inst._ident ); } duke@435: duke@435: void record_position(OutputMap::position place, int idx ) { duke@435: switch(place) { duke@435: case OutputMap::BEGIN_INST_CHAIN_RULES : duke@435: begin_inst_chain_rule = idx; duke@435: break; duke@435: case OutputMap::END_INST_CHAIN_RULES : duke@435: end_inst_chain_rule = idx; duke@435: break; duke@435: case OutputMap::BEGIN_REMATERIALIZE : duke@435: begin_rematerialize = idx; duke@435: break; duke@435: case OutputMap::END_REMATERIALIZE : duke@435: end_rematerialize = idx; duke@435: break; duke@435: case OutputMap::END_INSTRUCTIONS : duke@435: end_instructions = idx; duke@435: break; duke@435: default: duke@435: break; duke@435: } duke@435: } duke@435: }; duke@435: duke@435: duke@435: void ArchDesc::buildMachOpcodesEnum(FILE *fp_hpp) { duke@435: // Construct the table for MachOpcodes duke@435: OutputMachOpcodes output_mach_opcodes(fp_hpp, fp_hpp, _globalNames, *this); duke@435: build_map(output_mach_opcodes); duke@435: } duke@435: duke@435: duke@435: // Generate an enumeration of the pipeline states, and both duke@435: // the functional units (resources) and the masks for duke@435: // specifying resources duke@435: void ArchDesc::build_pipeline_enums(FILE *fp_hpp) { duke@435: int stagelen = (int)strlen("undefined"); duke@435: int stagenum = 0; duke@435: duke@435: if (_pipeline) { // Find max enum string length duke@435: const char *stage; duke@435: for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) { duke@435: int len = (int)strlen(stage); duke@435: if (stagelen < len) stagelen = len; duke@435: } duke@435: } duke@435: duke@435: // Generate a list of stages duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, "// Pipeline Stages\n"); duke@435: fprintf(fp_hpp, "enum machPipelineStages {\n"); duke@435: fprintf(fp_hpp, " stage_%-*s = 0,\n", stagelen, "undefined"); duke@435: duke@435: if( _pipeline ) { duke@435: const char *stage; duke@435: for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) duke@435: fprintf(fp_hpp, " stage_%-*s = %d,\n", stagelen, stage, ++stagenum); duke@435: } duke@435: duke@435: fprintf(fp_hpp, " stage_%-*s = %d\n", stagelen, "count", stagenum); duke@435: fprintf(fp_hpp, "};\n"); duke@435: duke@435: fprintf(fp_hpp, "\n"); duke@435: fprintf(fp_hpp, "// Pipeline Resources\n"); duke@435: fprintf(fp_hpp, "enum machPipelineResources {\n"); duke@435: int rescount = 0; duke@435: duke@435: if( _pipeline ) { duke@435: const char *resource; duke@435: int reslen = 0; duke@435: duke@435: // Generate a list of resources, and masks duke@435: for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { duke@435: int len = (int)strlen(resource); duke@435: if (reslen < len) duke@435: reslen = len; duke@435: } duke@435: duke@435: for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { duke@435: const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource(); duke@435: int mask = resform->mask(); duke@435: if ((mask & (mask-1)) == 0) duke@435: fprintf(fp_hpp, " resource_%-*s = %d,\n", reslen, resource, rescount++); duke@435: } duke@435: fprintf(fp_hpp, "\n"); duke@435: for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) { duke@435: const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource(); duke@435: fprintf(fp_hpp, " res_mask_%-*s = 0x%08x,\n", reslen, resource, resform->mask()); duke@435: } duke@435: fprintf(fp_hpp, "\n"); duke@435: } duke@435: fprintf(fp_hpp, " resource_count = %d\n", rescount); duke@435: fprintf(fp_hpp, "};\n"); duke@435: }