983 fprintf(fp_cpp, " if (k < n)\n");
984 fprintf(fp_cpp, " delta = currpipe->operand_latency(k,predpipe);\n\n");
985 fprintf(fp_cpp, " return currpipe->functional_unit_latency(delta, predpipe);\n");
986 }
987 else {
988 fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n");
989 fprintf(fp_cpp, " return %d;\n",
990 non_operand_latency);
991 }
992 fprintf(fp_cpp, "}\n\n");
993
994 // Output the list of nop nodes
995 fprintf(fp_cpp, "// Descriptions for emitting different functional unit nops\n");
996 const char *nop;
997 int nopcnt = 0;
998 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; nopcnt++ );
999
1000 fprintf(fp_cpp, "void Bundle::initialize_nops(MachNode * nop_list[%d], Compile *C) {\n", nopcnt);
1001 int i = 0;
1002 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; i++ ) {
1003 fprintf(fp_cpp, " nop_list[%d] = (MachNode *) new (C) %sNode();\n", i, nop);
1004 }
1005 fprintf(fp_cpp, "};\n\n");
1006 fprintf(fp_cpp, "#ifndef PRODUCT\n");
1007 fprintf(fp_cpp, "void Bundle::dump(outputStream *st) const {\n");
1008 fprintf(fp_cpp, " static const char * bundle_flags[] = {\n");
1009 fprintf(fp_cpp, " \"\",\n");
1010 fprintf(fp_cpp, " \"use nop delay\",\n");
1011 fprintf(fp_cpp, " \"use unconditional delay\",\n");
1012 fprintf(fp_cpp, " \"use conditional delay\",\n");
1013 fprintf(fp_cpp, " \"used in conditional delay\",\n");
1014 fprintf(fp_cpp, " \"used in unconditional delay\",\n");
1015 fprintf(fp_cpp, " \"used in all conditional delays\",\n");
1016 fprintf(fp_cpp, " };\n\n");
1017
1018 fprintf(fp_cpp, " static const char *resource_names[%d] = {", _pipeline->_rescount);
1019 for (i = 0; i < _pipeline->_rescount; i++)
1020 fprintf(fp_cpp, " \"%s\"%c", _pipeline->_reslist.name(i), i < _pipeline->_rescount-1 ? ',' : ' ');
1021 fprintf(fp_cpp, "};\n\n");
1022
1023 // See if the same string is in the table
1311 // ComponentList components_right = instr->_components;
1312 // char *right_comp_type = components_right.at(op_index)->_type;
1313 // OpClassForm *right_opclass = globals[right_comp_type]->is_opclass();
1314 // Form::InterfaceType right_interface_type = right_opclass->interface_type(globals);
1315 //
1316 // return;
1317 // }
1318
1319 // Construct the new sub-tree
1320 static void generate_peepreplace( FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint, PeepReplace *preplace, int max_position ) {
1321 fprintf(fp, " // IF instructions and constraints matched\n");
1322 fprintf(fp, " if( matches ) {\n");
1323 fprintf(fp, " // generate the new sub-tree\n");
1324 fprintf(fp, " assert( true, \"Debug stopping point\");\n");
1325 if( preplace != NULL ) {
1326 // Get the root of the new sub-tree
1327 const char *root_inst = NULL;
1328 preplace->next_instruction(root_inst);
1329 InstructForm *root_form = globals[root_inst]->is_instruction();
1330 assert( root_form != NULL, "Replacement instruction was not previously defined");
1331 fprintf(fp, " %sNode *root = new (C) %sNode();\n", root_inst, root_inst);
1332
1333 int inst_num;
1334 const char *op_name;
1335 int opnds_index = 0; // define result operand
1336 // Then install the use-operands for the new sub-tree
1337 // preplace->reset(); // reset breaks iteration
1338 for( preplace->next_operand( inst_num, op_name );
1339 op_name != NULL;
1340 preplace->next_operand( inst_num, op_name ) ) {
1341 InstructForm *inst_form;
1342 inst_form = globals[pmatch->instruction_name(inst_num)]->is_instruction();
1343 assert( inst_form, "Parser should guaranty this is an instruction");
1344 int inst_op_num = inst_form->operand_position(op_name, Component::USE);
1345 if( inst_op_num == NameList::Not_in_list )
1346 inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF);
1347 assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE");
1348 // find the name of the OperandForm from the local name
1349 const Form *form = inst_form->_localNames[op_name];
1350 OperandForm *op_form = form->is_operand();
1351 if( opnds_index == 0 ) {
1480 // Generate expand code
1481 if( node->expands() ) {
1482 const char *opid;
1483 int new_pos, exp_pos;
1484 const char *new_id = NULL;
1485 const Form *frm = NULL;
1486 InstructForm *new_inst = NULL;
1487 OperandForm *new_oper = NULL;
1488 unsigned numo = node->num_opnds() +
1489 node->_exprule->_newopers.count();
1490
1491 // If necessary, generate any operands created in expand rule
1492 if (node->_exprule->_newopers.count()) {
1493 for(node->_exprule->_newopers.reset();
1494 (new_id = node->_exprule->_newopers.iter()) != NULL; cnt++) {
1495 frm = node->_localNames[new_id];
1496 assert(frm, "Invalid entry in new operands list of expand rule");
1497 new_oper = frm->is_operand();
1498 char *tmp = (char *)node->_exprule->_newopconst[new_id];
1499 if (tmp == NULL) {
1500 fprintf(fp," MachOper *op%d = new (C) %sOper();\n",
1501 cnt, new_oper->_ident);
1502 }
1503 else {
1504 fprintf(fp," MachOper *op%d = new (C) %sOper(%s);\n",
1505 cnt, new_oper->_ident, tmp);
1506 }
1507 }
1508 }
1509 cnt = 0;
1510 // Generate the temps to use for DAG building
1511 for(i = 0; i < numo; i++) {
1512 if (i < node->num_opnds()) {
1513 fprintf(fp," MachNode *tmp%d = this;\n", i);
1514 }
1515 else {
1516 fprintf(fp," MachNode *tmp%d = NULL;\n", i);
1517 }
1518 }
1519 // Build mapping from num_edges to local variables
1520 fprintf(fp," unsigned num0 = 0;\n");
1521 for( i = 1; i < node->num_opnds(); i++ ) {
1522 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();\n",i,i);
1523 }
1524
1549 ExpandRule *expand = node->_exprule;
1550 NameAndList *expand_instr = NULL;
1551 for(expand->reset_instructions();
1552 (expand_instr = expand->iter_instructions()) != NULL; cnt++) {
1553 new_id = expand_instr->name();
1554
1555 InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id];
1556
1557 if (!expand_instruction) {
1558 globalAD->syntax_err(node->_linenum, "In %s: instruction %s used in expand not declared\n",
1559 node->_ident, new_id);
1560 continue;
1561 }
1562
1563 if (expand_instruction->has_temps()) {
1564 globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s",
1565 node->_ident, new_id);
1566 }
1567
1568 // Build the node for the instruction
1569 fprintf(fp,"\n %sNode *n%d = new (C) %sNode();\n", new_id, cnt, new_id);
1570 // Add control edge for this node
1571 fprintf(fp," n%d->add_req(_in[0]);\n", cnt);
1572 // Build the operand for the value this node defines.
1573 Form *form = (Form*)_globalNames[new_id];
1574 assert( form, "'new_id' must be a defined form name");
1575 // Grab the InstructForm for the new instruction
1576 new_inst = form->is_instruction();
1577 assert( new_inst, "'new_id' must be an instruction name");
1578 if( node->is_ideal_if() && new_inst->is_ideal_if() ) {
1579 fprintf(fp, " ((MachIfNode*)n%d)->_prob = _prob;\n",cnt);
1580 fprintf(fp, " ((MachIfNode*)n%d)->_fcnt = _fcnt;\n",cnt);
1581 }
1582
1583 if( node->is_ideal_fastlock() && new_inst->is_ideal_fastlock() ) {
1584 fprintf(fp, " ((MachFastLockNode*)n%d)->_counters = _counters;\n",cnt);
1585 fprintf(fp, " ((MachFastLockNode*)n%d)->_rtm_counters = _rtm_counters;\n",cnt);
1586 fprintf(fp, " ((MachFastLockNode*)n%d)->_stack_rtm_counters = _stack_rtm_counters;\n",cnt);
1587 }
1588
1589 // Fill in the bottom_type where requested
1712 Component *comp = NULL;
1713 // For kills, the choice of projection numbers is arbitrary
1714 int proj_no = 1;
1715 bool declared_def = false;
1716 bool declared_kill = false;
1717
1718 while( (comp = node->_components.iter()) != NULL ) {
1719 // Lookup register class associated with operand type
1720 Form *form = (Form*)_globalNames[comp->_type];
1721 assert( form, "component type must be a defined form");
1722 OperandForm *op = form->is_operand();
1723
1724 if (comp->is(Component::TEMP)) {
1725 fprintf(fp, " // TEMP %s\n", comp->_name);
1726 if (!declared_def) {
1727 // Define the variable "def" to hold new MachProjNodes
1728 fprintf(fp, " MachTempNode *def;\n");
1729 declared_def = true;
1730 }
1731 if (op && op->_interface && op->_interface->is_RegInterface()) {
1732 fprintf(fp," def = new (C) MachTempNode(state->MachOperGenerator( %s, C ));\n",
1733 machOperEnum(op->_ident));
1734 fprintf(fp," add_req(def);\n");
1735 // The operand for TEMP is already constructed during
1736 // this mach node construction, see buildMachNode().
1737 //
1738 // int idx = node->operand_position_format(comp->_name);
1739 // fprintf(fp," set_opnd_array(%d, state->MachOperGenerator( %s, C ));\n",
1740 // idx, machOperEnum(op->_ident));
1741 } else {
1742 assert(false, "can't have temps which aren't registers");
1743 }
1744 } else if (comp->isa(Component::KILL)) {
1745 fprintf(fp, " // DEF/KILL %s\n", comp->_name);
1746
1747 if (!declared_kill) {
1748 // Define the variable "kill" to hold new MachProjNodes
1749 fprintf(fp, " MachProjNode *kill;\n");
1750 declared_kill = true;
1751 }
1752
1753 assert( op, "Support additional KILLS for base operands");
1754 const char *regmask = reg_mask(*op);
1755 const char *ideal_type = op->ideal_type(_globalNames, _register);
1756
1757 if (!op->is_bound_register()) {
1758 syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n",
1759 node->_ident, comp->_type, comp->_name);
1760 }
1761
1762 fprintf(fp," kill = ");
1763 fprintf(fp,"new (C) MachProjNode( %s, %d, (%s), Op_%s );\n",
1764 machNode, proj_no++, regmask, ideal_type);
1765 fprintf(fp," proj_list.push(kill);\n");
1766 }
1767 }
1768 }
1769
1770 if( !node->expands() && node->_matrule != NULL ) {
1771 // Remove duplicated operands and inputs which use the same name.
1772 // Seach through match operands for the same name usage.
1773 uint cur_num_opnds = node->num_opnds();
1774 if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) {
1775 Component *comp = NULL;
1776 // Build mapping from num_edges to local variables
1777 fprintf(fp," unsigned num0 = 0;\n");
1778 for( i = 1; i < cur_num_opnds; i++ ) {
1779 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();",i,i);
1780 fprintf(fp, " \t// %s\n", node->opnd_ident(i));
1781 }
1782 // Build a mapping from operand index to input edges
1783 fprintf(fp," unsigned idx0 = oper_input_base();\n");
2823 fprintf(fp, " case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index);
2824 } else {
2825 const char* reg_class_to_upper = toUpper(reg_class);
2826 fprintf(fp, " case %d: return &%s_mask();\n", index, reg_class_to_upper);
2827 delete[] reg_class_to_upper;
2828 }
2829 }
2830 fprintf(fp," }\n");
2831 fprintf(fp," ShouldNotReachHere();\n");
2832 fprintf(fp," return NULL;\n");
2833 }
2834
2835 // Method close
2836 fprintf(fp, "}\n\n");
2837 }
2838 }
2839
2840 // generate code to create a clone for a class derived from MachOper
2841 //
2842 // (0) MachOper *MachOperXOper::clone(Compile* C) const {
2843 // (1) return new (C) MachXOper( _ccode, _c0, _c1, ..., _cn);
2844 // (2) }
2845 //
2846 static void defineClone(FILE *fp, FormDict &globalNames, OperandForm &oper) {
2847 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper._ident);
2848 // Check for constants that need to be copied over
2849 const int num_consts = oper.num_consts(globalNames);
2850 const bool is_ideal_bool = oper.is_ideal_bool();
2851 if( (num_consts > 0) ) {
2852 fprintf(fp," return new (C) %sOper(", oper._ident);
2853 // generate parameters for constants
2854 int i = 0;
2855 fprintf(fp,"_c%d", i);
2856 for( i = 1; i < num_consts; ++i) {
2857 fprintf(fp,", _c%d", i);
2858 }
2859 // finish line (1)
2860 fprintf(fp,");\n");
2861 }
2862 else {
2863 assert( num_consts == 0, "Currently support zero or one constant per operand clone function");
2864 fprintf(fp," return new (C) %sOper();\n", oper._ident);
2865 }
2866 // finish method
2867 fprintf(fp,"}\n");
2868 }
2869
2870 // Helper functions for bug 4796752, abstracted with minimal modification
2871 // from define_oper_interface()
2872 OperandForm *rep_var_to_operand(const char *encoding, OperandForm &oper, FormDict &globals) {
2873 OperandForm *op = NULL;
2874 // Check for replacement variable
2875 if( *encoding == '$' ) {
2876 // Replacement variable
2877 const char *rep_var = encoding + 1;
2878 // Lookup replacement variable, rep_var, in operand's component list
2879 const Component *comp = oper._components.search(rep_var);
2880 assert( comp != NULL, "Replacement variable not found in components");
2881 // Lookup operand form for replacement variable's type
2882 const char *type = comp->_type;
2883 Form *form = (Form*)globals[type];
2884 assert( form != NULL, "Replacement variable's type not found");
3089 build_register_masks(_CPP_EXPAND_file._fp);
3090 // Define the pipe_classes
3091 build_pipe_classes(_CPP_PIPELINE_file._fp);
3092
3093 // Generate Machine Classes for each operand defined in AD file
3094 fprintf(fp,"\n");
3095 fprintf(fp,"\n");
3096 fprintf(fp,"//------------------Define classes derived from MachOper---------------------\n");
3097 // Iterate through all operands
3098 _operands.reset();
3099 OperandForm *oper;
3100 for( ; (oper = (OperandForm*)_operands.iter()) != NULL; ) {
3101 // Ensure this is a machine-world instruction
3102 if ( oper->ideal_only() ) continue;
3103 // !!!!!
3104 // The declaration of labelOper is in machine-independent file: machnode
3105 if ( strcmp(oper->_ident,"label") == 0 ) {
3106 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
3107
3108 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident);
3109 fprintf(fp," return new (C) %sOper(_label, _block_num);\n", oper->_ident);
3110 fprintf(fp,"}\n");
3111
3112 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
3113 oper->_ident, machOperEnum(oper->_ident));
3114 // // Currently all XXXOper::Hash() methods are identical (990820)
3115 // define_hash(fp, oper->_ident);
3116 // // Currently all XXXOper::Cmp() methods are identical (990820)
3117 // define_cmp(fp, oper->_ident);
3118 fprintf(fp,"\n");
3119
3120 continue;
3121 }
3122
3123 // The declaration of methodOper is in machine-independent file: machnode
3124 if ( strcmp(oper->_ident,"method") == 0 ) {
3125 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
3126
3127 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident);
3128 fprintf(fp," return new (C) %sOper(_method);\n", oper->_ident);
3129 fprintf(fp,"}\n");
3130
3131 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
3132 oper->_ident, machOperEnum(oper->_ident));
3133 // // Currently all XXXOper::Hash() methods are identical (990820)
3134 // define_hash(fp, oper->_ident);
3135 // // Currently all XXXOper::Cmp() methods are identical (990820)
3136 // define_cmp(fp, oper->_ident);
3137 fprintf(fp,"\n");
3138
3139 continue;
3140 }
3141
3142 defineIn_RegMask(fp, _globalNames, *oper);
3143 defineClone(_CPP_CLONE_file._fp, _globalNames, *oper);
3144 // // Currently all XXXOper::Hash() methods are identical (990820)
3145 // define_hash(fp, oper->_ident);
3146 // // Currently all XXXOper::Cmp() methods are identical (990820)
3147 // define_cmp(fp, oper->_ident);
3148
3798 }
3799 // If constant is in right child, build path and recurse
3800 if ( (mnode->_rChild) && (rConsts > (idx - lConsts) ) ) {
3801 idx = idx - lConsts;
3802 fprintf(fp, "_kids[1]->");
3803 path_to_constant(fp, globals, mnode->_rChild, idx);
3804 return;
3805 }
3806 assert( false, "ShouldNotReachHere()");
3807 }
3808
3809 // Generate code that is executed when generating a specific Machine Operand
3810 static void genMachOperCase(FILE *fp, FormDict &globalNames, ArchDesc &AD,
3811 OperandForm &op) {
3812 const char *opName = op._ident;
3813 const char *opEnumName = AD.machOperEnum(opName);
3814 uint num_consts = op.num_consts(globalNames);
3815
3816 // Generate the case statement for this opcode
3817 fprintf(fp, " case %s:", opEnumName);
3818 fprintf(fp, "\n return new (C) %sOper(", opName);
3819 // Access parameters for constructor from the stat object
3820 //
3821 // Build access to condition code value
3822 if ( (num_consts > 0) ) {
3823 uint i = 0;
3824 path_to_constant(fp, globalNames, op._matrule, i);
3825 for ( i = 1; i < num_consts; ++i ) {
3826 fprintf(fp, ", ");
3827 path_to_constant(fp, globalNames, op._matrule, i);
3828 }
3829 }
3830 fprintf(fp, " );\n");
3831 }
3832
3833
3834 // Build switch to invoke "new" MachNode or MachOper
3835 void ArchDesc::buildMachOperGenerator(FILE *fp_cpp) {
3836 int idx = 0;
3837
3838 // Build switch to invoke 'new' for a specific MachOper
3877 fprintf(fp_cpp, " \n");
3878 fprintf(fp_cpp, " default:\n");
3879 fprintf(fp_cpp, " fprintf(stderr, \"Default MachOper Generator invoked for: \\n\");\n");
3880 fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%');
3881 fprintf(fp_cpp, " break;\n");
3882 fprintf(fp_cpp, " }\n");
3883
3884 // Generate the closing for method Matcher::MachOperGenerator
3885 fprintf(fp_cpp, " return NULL;\n");
3886 fprintf(fp_cpp, "};\n");
3887 }
3888
3889
3890 //---------------------------buildMachNode-------------------------------------
3891 // Build a new MachNode, for MachNodeGenerator or cisc-spilling
3892 void ArchDesc::buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent) {
3893 const char *opType = NULL;
3894 const char *opClass = inst->_ident;
3895
3896 // Create the MachNode object
3897 fprintf(fp_cpp, "%s %sNode *node = new (C) %sNode();\n",indent, opClass,opClass);
3898
3899 if ( (inst->num_post_match_opnds() != 0) ) {
3900 // Instruction that contains operands which are not in match rule.
3901 //
3902 // Check if the first post-match component may be an interesting def
3903 bool dont_care = false;
3904 ComponentList &comp_list = inst->_components;
3905 Component *comp = NULL;
3906 comp_list.reset();
3907 if ( comp_list.match_iter() != NULL ) dont_care = true;
3908
3909 // Insert operands that are not in match-rule.
3910 // Only insert a DEF if the do_care flag is set
3911 comp_list.reset();
3912 while ( comp = comp_list.post_match_iter() ) {
3913 // Check if we don't care about DEFs or KILLs that are not USEs
3914 if ( dont_care && (! comp->isa(Component::USE)) ) {
3915 continue;
3916 }
3917 dont_care = true;
3919 // with the enum for the opcode that needs to be built.
3920 ComponentList clist = inst->_components;
3921 int index = clist.operand_position(comp->_name, comp->_usedef, inst);
3922 const char *opcode = machOperEnum(comp->_type);
3923 fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index);
3924 fprintf(fp_cpp, "MachOperGenerator(%s, C));\n", opcode);
3925 }
3926 }
3927 else if ( inst->is_chain_of_constant(_globalNames, opType) ) {
3928 // An instruction that chains from a constant!
3929 // In this case, we need to subsume the constant into the node
3930 // at operand position, oper_input_base().
3931 //
3932 // Fill in the constant
3933 fprintf(fp_cpp, "%s node->_opnd_array[%d] = ", indent,
3934 inst->oper_input_base(_globalNames));
3935 // #####
3936 // Check for multiple constants and then fill them in.
3937 // Just like MachOperGenerator
3938 const char *opName = inst->_matrule->_rChild->_opType;
3939 fprintf(fp_cpp, "new (C) %sOper(", opName);
3940 // Grab operand form
3941 OperandForm *op = (_globalNames[opName])->is_operand();
3942 // Look up the number of constants
3943 uint num_consts = op->num_consts(_globalNames);
3944 if ( (num_consts > 0) ) {
3945 uint i = 0;
3946 path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3947 for ( i = 1; i < num_consts; ++i ) {
3948 fprintf(fp_cpp, ", ");
3949 path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3950 }
3951 }
3952 fprintf(fp_cpp, " );\n");
3953 // #####
3954 }
3955
3956 // Fill in the bottom_type where requested
3957 if (inst->captures_bottom_type(_globalNames)) {
3958 if (strncmp("MachCall", inst->mach_base_class(_globalNames), strlen("MachCall"))) {
3959 fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
3993 const char *name = inst_cisc->_ident;
3994 assert( inst_cisc->num_opnds() == this->num_opnds(), "Must have same number of operands");
3995 OperandForm *cisc_oper = AD.cisc_spill_operand();
3996 assert( cisc_oper != NULL, "insanity check");
3997 const char *cisc_oper_name = cisc_oper->_ident;
3998 assert( cisc_oper_name != NULL, "insanity check");
3999 //
4000 // Set the correct reg_mask_or_stack for the cisc operand
4001 fprintf(fp_cpp, "\n");
4002 fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident);
4003 // Lookup the correct reg_mask_or_stack
4004 const char *reg_mask_name = cisc_reg_mask_name();
4005 fprintf(fp_cpp, " _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name);
4006 fprintf(fp_cpp, "}\n");
4007 //
4008 // Construct CISC version of this instruction
4009 fprintf(fp_cpp, "\n");
4010 fprintf(fp_cpp, "// Build CISC version of this instruction\n");
4011 fprintf(fp_cpp, "MachNode *%sNode::cisc_version( int offset, Compile* C ) {\n", this->_ident);
4012 // Create the MachNode object
4013 fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name);
4014 // Fill in the bottom_type where requested
4015 if ( this->captures_bottom_type(AD.globalNames()) ) {
4016 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n");
4017 }
4018
4019 uint cur_num_opnds = num_opnds();
4020 if (cur_num_opnds > 1 && cur_num_opnds != num_unique_opnds()) {
4021 fprintf(fp_cpp," node->_num_opnds = %d;\n", num_unique_opnds());
4022 }
4023
4024 fprintf(fp_cpp, "\n");
4025 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n");
4026 fprintf(fp_cpp, " fill_new_machnode(node, C);\n");
4027 // Construct operand to access [stack_pointer + offset]
4028 fprintf(fp_cpp, " // Construct operand to access [stack_pointer + offset]\n");
4029 fprintf(fp_cpp, " node->set_opnd_array(cisc_operand(), new (C) %sOper(offset));\n", cisc_oper_name);
4030 fprintf(fp_cpp, "\n");
4031
4032 // Return result and exit scope
4033 fprintf(fp_cpp, " return node;\n");
4034 fprintf(fp_cpp, "}\n");
4035 fprintf(fp_cpp, "\n");
4036 return true;
4037 }
4038 return false;
4039 }
4040
4041 //---------------------------declare_short_branch_methods----------------------
4042 // Build prototypes for short branch methods
4043 void InstructForm::declare_short_branch_methods(FILE *fp_hpp) {
4044 if (has_short_branch_form()) {
4045 fprintf(fp_hpp, " virtual MachNode *short_branch_version(Compile* C);\n");
4046 }
4047 }
4048
4049 //---------------------------define_short_branch_methods-----------------------
4050 // Build definitions for short branch methods
4051 bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) {
4052 if (has_short_branch_form()) {
4053 InstructForm *short_branch = short_branch_form();
4054 const char *name = short_branch->_ident;
4055
4056 // Construct short_branch_version() method.
4057 fprintf(fp_cpp, "// Build short branch version of this instruction\n");
4058 fprintf(fp_cpp, "MachNode *%sNode::short_branch_version(Compile* C) {\n", this->_ident);
4059 // Create the MachNode object
4060 fprintf(fp_cpp, " %sNode *node = new (C) %sNode();\n", name, name);
4061 if( is_ideal_if() ) {
4062 fprintf(fp_cpp, " node->_prob = _prob;\n");
4063 fprintf(fp_cpp, " node->_fcnt = _fcnt;\n");
4064 }
4065 // Fill in the bottom_type where requested
4066 if ( this->captures_bottom_type(AD.globalNames()) ) {
4067 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n");
4068 }
4069
4070 fprintf(fp_cpp, "\n");
4071 // Short branch version must use same node index for access
4072 // through allocator's tables
4073 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n");
4074 fprintf(fp_cpp, " fill_new_machnode(node, C);\n");
4075
4076 // Return result and exit scope
4077 fprintf(fp_cpp, " return node;\n");
4078 fprintf(fp_cpp, "}\n");
4079 fprintf(fp_cpp,"\n");
4080 return true;
|
983 fprintf(fp_cpp, " if (k < n)\n");
984 fprintf(fp_cpp, " delta = currpipe->operand_latency(k,predpipe);\n\n");
985 fprintf(fp_cpp, " return currpipe->functional_unit_latency(delta, predpipe);\n");
986 }
987 else {
988 fprintf(fp_cpp, " // assert(false, \"pipeline functionality is not defined\");\n");
989 fprintf(fp_cpp, " return %d;\n",
990 non_operand_latency);
991 }
992 fprintf(fp_cpp, "}\n\n");
993
994 // Output the list of nop nodes
995 fprintf(fp_cpp, "// Descriptions for emitting different functional unit nops\n");
996 const char *nop;
997 int nopcnt = 0;
998 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; nopcnt++ );
999
1000 fprintf(fp_cpp, "void Bundle::initialize_nops(MachNode * nop_list[%d], Compile *C) {\n", nopcnt);
1001 int i = 0;
1002 for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; i++ ) {
1003 fprintf(fp_cpp, " nop_list[%d] = (MachNode *) new %sNode();\n", i, nop);
1004 }
1005 fprintf(fp_cpp, "};\n\n");
1006 fprintf(fp_cpp, "#ifndef PRODUCT\n");
1007 fprintf(fp_cpp, "void Bundle::dump(outputStream *st) const {\n");
1008 fprintf(fp_cpp, " static const char * bundle_flags[] = {\n");
1009 fprintf(fp_cpp, " \"\",\n");
1010 fprintf(fp_cpp, " \"use nop delay\",\n");
1011 fprintf(fp_cpp, " \"use unconditional delay\",\n");
1012 fprintf(fp_cpp, " \"use conditional delay\",\n");
1013 fprintf(fp_cpp, " \"used in conditional delay\",\n");
1014 fprintf(fp_cpp, " \"used in unconditional delay\",\n");
1015 fprintf(fp_cpp, " \"used in all conditional delays\",\n");
1016 fprintf(fp_cpp, " };\n\n");
1017
1018 fprintf(fp_cpp, " static const char *resource_names[%d] = {", _pipeline->_rescount);
1019 for (i = 0; i < _pipeline->_rescount; i++)
1020 fprintf(fp_cpp, " \"%s\"%c", _pipeline->_reslist.name(i), i < _pipeline->_rescount-1 ? ',' : ' ');
1021 fprintf(fp_cpp, "};\n\n");
1022
1023 // See if the same string is in the table
1311 // ComponentList components_right = instr->_components;
1312 // char *right_comp_type = components_right.at(op_index)->_type;
1313 // OpClassForm *right_opclass = globals[right_comp_type]->is_opclass();
1314 // Form::InterfaceType right_interface_type = right_opclass->interface_type(globals);
1315 //
1316 // return;
1317 // }
1318
1319 // Construct the new sub-tree
1320 static void generate_peepreplace( FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint, PeepReplace *preplace, int max_position ) {
1321 fprintf(fp, " // IF instructions and constraints matched\n");
1322 fprintf(fp, " if( matches ) {\n");
1323 fprintf(fp, " // generate the new sub-tree\n");
1324 fprintf(fp, " assert( true, \"Debug stopping point\");\n");
1325 if( preplace != NULL ) {
1326 // Get the root of the new sub-tree
1327 const char *root_inst = NULL;
1328 preplace->next_instruction(root_inst);
1329 InstructForm *root_form = globals[root_inst]->is_instruction();
1330 assert( root_form != NULL, "Replacement instruction was not previously defined");
1331 fprintf(fp, " %sNode *root = new %sNode();\n", root_inst, root_inst);
1332
1333 int inst_num;
1334 const char *op_name;
1335 int opnds_index = 0; // define result operand
1336 // Then install the use-operands for the new sub-tree
1337 // preplace->reset(); // reset breaks iteration
1338 for( preplace->next_operand( inst_num, op_name );
1339 op_name != NULL;
1340 preplace->next_operand( inst_num, op_name ) ) {
1341 InstructForm *inst_form;
1342 inst_form = globals[pmatch->instruction_name(inst_num)]->is_instruction();
1343 assert( inst_form, "Parser should guaranty this is an instruction");
1344 int inst_op_num = inst_form->operand_position(op_name, Component::USE);
1345 if( inst_op_num == NameList::Not_in_list )
1346 inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF);
1347 assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE");
1348 // find the name of the OperandForm from the local name
1349 const Form *form = inst_form->_localNames[op_name];
1350 OperandForm *op_form = form->is_operand();
1351 if( opnds_index == 0 ) {
1480 // Generate expand code
1481 if( node->expands() ) {
1482 const char *opid;
1483 int new_pos, exp_pos;
1484 const char *new_id = NULL;
1485 const Form *frm = NULL;
1486 InstructForm *new_inst = NULL;
1487 OperandForm *new_oper = NULL;
1488 unsigned numo = node->num_opnds() +
1489 node->_exprule->_newopers.count();
1490
1491 // If necessary, generate any operands created in expand rule
1492 if (node->_exprule->_newopers.count()) {
1493 for(node->_exprule->_newopers.reset();
1494 (new_id = node->_exprule->_newopers.iter()) != NULL; cnt++) {
1495 frm = node->_localNames[new_id];
1496 assert(frm, "Invalid entry in new operands list of expand rule");
1497 new_oper = frm->is_operand();
1498 char *tmp = (char *)node->_exprule->_newopconst[new_id];
1499 if (tmp == NULL) {
1500 fprintf(fp," MachOper *op%d = new %sOper();\n",
1501 cnt, new_oper->_ident);
1502 }
1503 else {
1504 fprintf(fp," MachOper *op%d = new %sOper(%s);\n",
1505 cnt, new_oper->_ident, tmp);
1506 }
1507 }
1508 }
1509 cnt = 0;
1510 // Generate the temps to use for DAG building
1511 for(i = 0; i < numo; i++) {
1512 if (i < node->num_opnds()) {
1513 fprintf(fp," MachNode *tmp%d = this;\n", i);
1514 }
1515 else {
1516 fprintf(fp," MachNode *tmp%d = NULL;\n", i);
1517 }
1518 }
1519 // Build mapping from num_edges to local variables
1520 fprintf(fp," unsigned num0 = 0;\n");
1521 for( i = 1; i < node->num_opnds(); i++ ) {
1522 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();\n",i,i);
1523 }
1524
1549 ExpandRule *expand = node->_exprule;
1550 NameAndList *expand_instr = NULL;
1551 for(expand->reset_instructions();
1552 (expand_instr = expand->iter_instructions()) != NULL; cnt++) {
1553 new_id = expand_instr->name();
1554
1555 InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id];
1556
1557 if (!expand_instruction) {
1558 globalAD->syntax_err(node->_linenum, "In %s: instruction %s used in expand not declared\n",
1559 node->_ident, new_id);
1560 continue;
1561 }
1562
1563 if (expand_instruction->has_temps()) {
1564 globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s",
1565 node->_ident, new_id);
1566 }
1567
1568 // Build the node for the instruction
1569 fprintf(fp,"\n %sNode *n%d = new %sNode();\n", new_id, cnt, new_id);
1570 // Add control edge for this node
1571 fprintf(fp," n%d->add_req(_in[0]);\n", cnt);
1572 // Build the operand for the value this node defines.
1573 Form *form = (Form*)_globalNames[new_id];
1574 assert( form, "'new_id' must be a defined form name");
1575 // Grab the InstructForm for the new instruction
1576 new_inst = form->is_instruction();
1577 assert( new_inst, "'new_id' must be an instruction name");
1578 if( node->is_ideal_if() && new_inst->is_ideal_if() ) {
1579 fprintf(fp, " ((MachIfNode*)n%d)->_prob = _prob;\n",cnt);
1580 fprintf(fp, " ((MachIfNode*)n%d)->_fcnt = _fcnt;\n",cnt);
1581 }
1582
1583 if( node->is_ideal_fastlock() && new_inst->is_ideal_fastlock() ) {
1584 fprintf(fp, " ((MachFastLockNode*)n%d)->_counters = _counters;\n",cnt);
1585 fprintf(fp, " ((MachFastLockNode*)n%d)->_rtm_counters = _rtm_counters;\n",cnt);
1586 fprintf(fp, " ((MachFastLockNode*)n%d)->_stack_rtm_counters = _stack_rtm_counters;\n",cnt);
1587 }
1588
1589 // Fill in the bottom_type where requested
1712 Component *comp = NULL;
1713 // For kills, the choice of projection numbers is arbitrary
1714 int proj_no = 1;
1715 bool declared_def = false;
1716 bool declared_kill = false;
1717
1718 while( (comp = node->_components.iter()) != NULL ) {
1719 // Lookup register class associated with operand type
1720 Form *form = (Form*)_globalNames[comp->_type];
1721 assert( form, "component type must be a defined form");
1722 OperandForm *op = form->is_operand();
1723
1724 if (comp->is(Component::TEMP)) {
1725 fprintf(fp, " // TEMP %s\n", comp->_name);
1726 if (!declared_def) {
1727 // Define the variable "def" to hold new MachProjNodes
1728 fprintf(fp, " MachTempNode *def;\n");
1729 declared_def = true;
1730 }
1731 if (op && op->_interface && op->_interface->is_RegInterface()) {
1732 fprintf(fp," def = new MachTempNode(state->MachOperGenerator( %s, C ));\n",
1733 machOperEnum(op->_ident));
1734 fprintf(fp," add_req(def);\n");
1735 // The operand for TEMP is already constructed during
1736 // this mach node construction, see buildMachNode().
1737 //
1738 // int idx = node->operand_position_format(comp->_name);
1739 // fprintf(fp," set_opnd_array(%d, state->MachOperGenerator( %s, C ));\n",
1740 // idx, machOperEnum(op->_ident));
1741 } else {
1742 assert(false, "can't have temps which aren't registers");
1743 }
1744 } else if (comp->isa(Component::KILL)) {
1745 fprintf(fp, " // DEF/KILL %s\n", comp->_name);
1746
1747 if (!declared_kill) {
1748 // Define the variable "kill" to hold new MachProjNodes
1749 fprintf(fp, " MachProjNode *kill;\n");
1750 declared_kill = true;
1751 }
1752
1753 assert( op, "Support additional KILLS for base operands");
1754 const char *regmask = reg_mask(*op);
1755 const char *ideal_type = op->ideal_type(_globalNames, _register);
1756
1757 if (!op->is_bound_register()) {
1758 syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n",
1759 node->_ident, comp->_type, comp->_name);
1760 }
1761
1762 fprintf(fp," kill = ");
1763 fprintf(fp,"new MachProjNode( %s, %d, (%s), Op_%s );\n",
1764 machNode, proj_no++, regmask, ideal_type);
1765 fprintf(fp," proj_list.push(kill);\n");
1766 }
1767 }
1768 }
1769
1770 if( !node->expands() && node->_matrule != NULL ) {
1771 // Remove duplicated operands and inputs which use the same name.
1772 // Seach through match operands for the same name usage.
1773 uint cur_num_opnds = node->num_opnds();
1774 if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) {
1775 Component *comp = NULL;
1776 // Build mapping from num_edges to local variables
1777 fprintf(fp," unsigned num0 = 0;\n");
1778 for( i = 1; i < cur_num_opnds; i++ ) {
1779 fprintf(fp," unsigned num%d = opnd_array(%d)->num_edges();",i,i);
1780 fprintf(fp, " \t// %s\n", node->opnd_ident(i));
1781 }
1782 // Build a mapping from operand index to input edges
1783 fprintf(fp," unsigned idx0 = oper_input_base();\n");
2823 fprintf(fp, " case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index);
2824 } else {
2825 const char* reg_class_to_upper = toUpper(reg_class);
2826 fprintf(fp, " case %d: return &%s_mask();\n", index, reg_class_to_upper);
2827 delete[] reg_class_to_upper;
2828 }
2829 }
2830 fprintf(fp," }\n");
2831 fprintf(fp," ShouldNotReachHere();\n");
2832 fprintf(fp," return NULL;\n");
2833 }
2834
2835 // Method close
2836 fprintf(fp, "}\n\n");
2837 }
2838 }
2839
2840 // generate code to create a clone for a class derived from MachOper
2841 //
2842 // (0) MachOper *MachOperXOper::clone(Compile* C) const {
2843 // (1) return new MachXOper( _ccode, _c0, _c1, ..., _cn);
2844 // (2) }
2845 //
2846 static void defineClone(FILE *fp, FormDict &globalNames, OperandForm &oper) {
2847 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper._ident);
2848 // Check for constants that need to be copied over
2849 const int num_consts = oper.num_consts(globalNames);
2850 const bool is_ideal_bool = oper.is_ideal_bool();
2851 if( (num_consts > 0) ) {
2852 fprintf(fp," return new %sOper(", oper._ident);
2853 // generate parameters for constants
2854 int i = 0;
2855 fprintf(fp,"_c%d", i);
2856 for( i = 1; i < num_consts; ++i) {
2857 fprintf(fp,", _c%d", i);
2858 }
2859 // finish line (1)
2860 fprintf(fp,");\n");
2861 }
2862 else {
2863 assert( num_consts == 0, "Currently support zero or one constant per operand clone function");
2864 fprintf(fp," return new %sOper();\n", oper._ident);
2865 }
2866 // finish method
2867 fprintf(fp,"}\n");
2868 }
2869
2870 // Helper functions for bug 4796752, abstracted with minimal modification
2871 // from define_oper_interface()
2872 OperandForm *rep_var_to_operand(const char *encoding, OperandForm &oper, FormDict &globals) {
2873 OperandForm *op = NULL;
2874 // Check for replacement variable
2875 if( *encoding == '$' ) {
2876 // Replacement variable
2877 const char *rep_var = encoding + 1;
2878 // Lookup replacement variable, rep_var, in operand's component list
2879 const Component *comp = oper._components.search(rep_var);
2880 assert( comp != NULL, "Replacement variable not found in components");
2881 // Lookup operand form for replacement variable's type
2882 const char *type = comp->_type;
2883 Form *form = (Form*)globals[type];
2884 assert( form != NULL, "Replacement variable's type not found");
3089 build_register_masks(_CPP_EXPAND_file._fp);
3090 // Define the pipe_classes
3091 build_pipe_classes(_CPP_PIPELINE_file._fp);
3092
3093 // Generate Machine Classes for each operand defined in AD file
3094 fprintf(fp,"\n");
3095 fprintf(fp,"\n");
3096 fprintf(fp,"//------------------Define classes derived from MachOper---------------------\n");
3097 // Iterate through all operands
3098 _operands.reset();
3099 OperandForm *oper;
3100 for( ; (oper = (OperandForm*)_operands.iter()) != NULL; ) {
3101 // Ensure this is a machine-world instruction
3102 if ( oper->ideal_only() ) continue;
3103 // !!!!!
3104 // The declaration of labelOper is in machine-independent file: machnode
3105 if ( strcmp(oper->_ident,"label") == 0 ) {
3106 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
3107
3108 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident);
3109 fprintf(fp," return new %sOper(_label, _block_num);\n", oper->_ident);
3110 fprintf(fp,"}\n");
3111
3112 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
3113 oper->_ident, machOperEnum(oper->_ident));
3114 // // Currently all XXXOper::Hash() methods are identical (990820)
3115 // define_hash(fp, oper->_ident);
3116 // // Currently all XXXOper::Cmp() methods are identical (990820)
3117 // define_cmp(fp, oper->_ident);
3118 fprintf(fp,"\n");
3119
3120 continue;
3121 }
3122
3123 // The declaration of methodOper is in machine-independent file: machnode
3124 if ( strcmp(oper->_ident,"method") == 0 ) {
3125 defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
3126
3127 fprintf(fp,"MachOper *%sOper::clone(Compile* C) const {\n", oper->_ident);
3128 fprintf(fp," return new %sOper(_method);\n", oper->_ident);
3129 fprintf(fp,"}\n");
3130
3131 fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
3132 oper->_ident, machOperEnum(oper->_ident));
3133 // // Currently all XXXOper::Hash() methods are identical (990820)
3134 // define_hash(fp, oper->_ident);
3135 // // Currently all XXXOper::Cmp() methods are identical (990820)
3136 // define_cmp(fp, oper->_ident);
3137 fprintf(fp,"\n");
3138
3139 continue;
3140 }
3141
3142 defineIn_RegMask(fp, _globalNames, *oper);
3143 defineClone(_CPP_CLONE_file._fp, _globalNames, *oper);
3144 // // Currently all XXXOper::Hash() methods are identical (990820)
3145 // define_hash(fp, oper->_ident);
3146 // // Currently all XXXOper::Cmp() methods are identical (990820)
3147 // define_cmp(fp, oper->_ident);
3148
3798 }
3799 // If constant is in right child, build path and recurse
3800 if ( (mnode->_rChild) && (rConsts > (idx - lConsts) ) ) {
3801 idx = idx - lConsts;
3802 fprintf(fp, "_kids[1]->");
3803 path_to_constant(fp, globals, mnode->_rChild, idx);
3804 return;
3805 }
3806 assert( false, "ShouldNotReachHere()");
3807 }
3808
3809 // Generate code that is executed when generating a specific Machine Operand
3810 static void genMachOperCase(FILE *fp, FormDict &globalNames, ArchDesc &AD,
3811 OperandForm &op) {
3812 const char *opName = op._ident;
3813 const char *opEnumName = AD.machOperEnum(opName);
3814 uint num_consts = op.num_consts(globalNames);
3815
3816 // Generate the case statement for this opcode
3817 fprintf(fp, " case %s:", opEnumName);
3818 fprintf(fp, "\n return new %sOper(", opName);
3819 // Access parameters for constructor from the stat object
3820 //
3821 // Build access to condition code value
3822 if ( (num_consts > 0) ) {
3823 uint i = 0;
3824 path_to_constant(fp, globalNames, op._matrule, i);
3825 for ( i = 1; i < num_consts; ++i ) {
3826 fprintf(fp, ", ");
3827 path_to_constant(fp, globalNames, op._matrule, i);
3828 }
3829 }
3830 fprintf(fp, " );\n");
3831 }
3832
3833
3834 // Build switch to invoke "new" MachNode or MachOper
3835 void ArchDesc::buildMachOperGenerator(FILE *fp_cpp) {
3836 int idx = 0;
3837
3838 // Build switch to invoke 'new' for a specific MachOper
3877 fprintf(fp_cpp, " \n");
3878 fprintf(fp_cpp, " default:\n");
3879 fprintf(fp_cpp, " fprintf(stderr, \"Default MachOper Generator invoked for: \\n\");\n");
3880 fprintf(fp_cpp, " fprintf(stderr, \" opcode = %cd\\n\", opcode);\n", '%');
3881 fprintf(fp_cpp, " break;\n");
3882 fprintf(fp_cpp, " }\n");
3883
3884 // Generate the closing for method Matcher::MachOperGenerator
3885 fprintf(fp_cpp, " return NULL;\n");
3886 fprintf(fp_cpp, "};\n");
3887 }
3888
3889
3890 //---------------------------buildMachNode-------------------------------------
3891 // Build a new MachNode, for MachNodeGenerator or cisc-spilling
3892 void ArchDesc::buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent) {
3893 const char *opType = NULL;
3894 const char *opClass = inst->_ident;
3895
3896 // Create the MachNode object
3897 fprintf(fp_cpp, "%s %sNode *node = new %sNode();\n",indent, opClass,opClass);
3898
3899 if ( (inst->num_post_match_opnds() != 0) ) {
3900 // Instruction that contains operands which are not in match rule.
3901 //
3902 // Check if the first post-match component may be an interesting def
3903 bool dont_care = false;
3904 ComponentList &comp_list = inst->_components;
3905 Component *comp = NULL;
3906 comp_list.reset();
3907 if ( comp_list.match_iter() != NULL ) dont_care = true;
3908
3909 // Insert operands that are not in match-rule.
3910 // Only insert a DEF if the do_care flag is set
3911 comp_list.reset();
3912 while ( comp = comp_list.post_match_iter() ) {
3913 // Check if we don't care about DEFs or KILLs that are not USEs
3914 if ( dont_care && (! comp->isa(Component::USE)) ) {
3915 continue;
3916 }
3917 dont_care = true;
3919 // with the enum for the opcode that needs to be built.
3920 ComponentList clist = inst->_components;
3921 int index = clist.operand_position(comp->_name, comp->_usedef, inst);
3922 const char *opcode = machOperEnum(comp->_type);
3923 fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index);
3924 fprintf(fp_cpp, "MachOperGenerator(%s, C));\n", opcode);
3925 }
3926 }
3927 else if ( inst->is_chain_of_constant(_globalNames, opType) ) {
3928 // An instruction that chains from a constant!
3929 // In this case, we need to subsume the constant into the node
3930 // at operand position, oper_input_base().
3931 //
3932 // Fill in the constant
3933 fprintf(fp_cpp, "%s node->_opnd_array[%d] = ", indent,
3934 inst->oper_input_base(_globalNames));
3935 // #####
3936 // Check for multiple constants and then fill them in.
3937 // Just like MachOperGenerator
3938 const char *opName = inst->_matrule->_rChild->_opType;
3939 fprintf(fp_cpp, "new %sOper(", opName);
3940 // Grab operand form
3941 OperandForm *op = (_globalNames[opName])->is_operand();
3942 // Look up the number of constants
3943 uint num_consts = op->num_consts(_globalNames);
3944 if ( (num_consts > 0) ) {
3945 uint i = 0;
3946 path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3947 for ( i = 1; i < num_consts; ++i ) {
3948 fprintf(fp_cpp, ", ");
3949 path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3950 }
3951 }
3952 fprintf(fp_cpp, " );\n");
3953 // #####
3954 }
3955
3956 // Fill in the bottom_type where requested
3957 if (inst->captures_bottom_type(_globalNames)) {
3958 if (strncmp("MachCall", inst->mach_base_class(_globalNames), strlen("MachCall"))) {
3959 fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
3993 const char *name = inst_cisc->_ident;
3994 assert( inst_cisc->num_opnds() == this->num_opnds(), "Must have same number of operands");
3995 OperandForm *cisc_oper = AD.cisc_spill_operand();
3996 assert( cisc_oper != NULL, "insanity check");
3997 const char *cisc_oper_name = cisc_oper->_ident;
3998 assert( cisc_oper_name != NULL, "insanity check");
3999 //
4000 // Set the correct reg_mask_or_stack for the cisc operand
4001 fprintf(fp_cpp, "\n");
4002 fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident);
4003 // Lookup the correct reg_mask_or_stack
4004 const char *reg_mask_name = cisc_reg_mask_name();
4005 fprintf(fp_cpp, " _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name);
4006 fprintf(fp_cpp, "}\n");
4007 //
4008 // Construct CISC version of this instruction
4009 fprintf(fp_cpp, "\n");
4010 fprintf(fp_cpp, "// Build CISC version of this instruction\n");
4011 fprintf(fp_cpp, "MachNode *%sNode::cisc_version( int offset, Compile* C ) {\n", this->_ident);
4012 // Create the MachNode object
4013 fprintf(fp_cpp, " %sNode *node = new %sNode();\n", name, name);
4014 // Fill in the bottom_type where requested
4015 if ( this->captures_bottom_type(AD.globalNames()) ) {
4016 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n");
4017 }
4018
4019 uint cur_num_opnds = num_opnds();
4020 if (cur_num_opnds > 1 && cur_num_opnds != num_unique_opnds()) {
4021 fprintf(fp_cpp," node->_num_opnds = %d;\n", num_unique_opnds());
4022 }
4023
4024 fprintf(fp_cpp, "\n");
4025 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n");
4026 fprintf(fp_cpp, " fill_new_machnode(node, C);\n");
4027 // Construct operand to access [stack_pointer + offset]
4028 fprintf(fp_cpp, " // Construct operand to access [stack_pointer + offset]\n");
4029 fprintf(fp_cpp, " node->set_opnd_array(cisc_operand(), new %sOper(offset));\n", cisc_oper_name);
4030 fprintf(fp_cpp, "\n");
4031
4032 // Return result and exit scope
4033 fprintf(fp_cpp, " return node;\n");
4034 fprintf(fp_cpp, "}\n");
4035 fprintf(fp_cpp, "\n");
4036 return true;
4037 }
4038 return false;
4039 }
4040
4041 //---------------------------declare_short_branch_methods----------------------
4042 // Build prototypes for short branch methods
4043 void InstructForm::declare_short_branch_methods(FILE *fp_hpp) {
4044 if (has_short_branch_form()) {
4045 fprintf(fp_hpp, " virtual MachNode *short_branch_version(Compile* C);\n");
4046 }
4047 }
4048
4049 //---------------------------define_short_branch_methods-----------------------
4050 // Build definitions for short branch methods
4051 bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) {
4052 if (has_short_branch_form()) {
4053 InstructForm *short_branch = short_branch_form();
4054 const char *name = short_branch->_ident;
4055
4056 // Construct short_branch_version() method.
4057 fprintf(fp_cpp, "// Build short branch version of this instruction\n");
4058 fprintf(fp_cpp, "MachNode *%sNode::short_branch_version(Compile* C) {\n", this->_ident);
4059 // Create the MachNode object
4060 fprintf(fp_cpp, " %sNode *node = new %sNode();\n", name, name);
4061 if( is_ideal_if() ) {
4062 fprintf(fp_cpp, " node->_prob = _prob;\n");
4063 fprintf(fp_cpp, " node->_fcnt = _fcnt;\n");
4064 }
4065 // Fill in the bottom_type where requested
4066 if ( this->captures_bottom_type(AD.globalNames()) ) {
4067 fprintf(fp_cpp, " node->_bottom_type = bottom_type();\n");
4068 }
4069
4070 fprintf(fp_cpp, "\n");
4071 // Short branch version must use same node index for access
4072 // through allocator's tables
4073 fprintf(fp_cpp, " // Copy _idx, inputs and operands to new node\n");
4074 fprintf(fp_cpp, " fill_new_machnode(node, C);\n");
4075
4076 // Return result and exit scope
4077 fprintf(fp_cpp, " return node;\n");
4078 fprintf(fp_cpp, "}\n");
4079 fprintf(fp_cpp,"\n");
4080 return true;
|