src/share/vm/adlc/output_c.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6953576 Sdiff src/share/vm/adlc

src/share/vm/adlc/output_c.cpp

Print this page




1365       int inst_op_num = inst_form->operand_position(op_name, Component::USE);
1366       if( inst_op_num == NameList::Not_in_list )
1367         inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF);
1368       assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE");
1369       // find the name of the OperandForm from the local name
1370       const Form *form   = inst_form->_localNames[op_name];
1371       OperandForm  *op_form = form->is_operand();
1372       if( opnds_index == 0 ) {
1373         // Initial setup of new instruction
1374         fprintf(fp, "        // ----- Initial setup -----\n");
1375         //
1376         // Add control edge for this node
1377         fprintf(fp, "        root->add_req(_in[0]);                // control edge\n");
1378         // Add unmatched edges from root of match tree
1379         int op_base = root_form->oper_input_base(globals);
1380         for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) {
1381           fprintf(fp, "        root->add_req(inst%d->in(%d));        // unmatched ideal edge\n",
1382                                           inst_num, unmatched_edge);
1383         }
1384         // If new instruction captures bottom type
1385         if( root_form->captures_bottom_type() ) {
1386           // Get bottom type from instruction whose result we are replacing
1387           fprintf(fp, "        root->_bottom_type = inst%d->bottom_type();\n", inst_num);
1388         }
1389         // Define result register and result operand
1390         fprintf(fp, "        ra_->add_reference(root, inst%d);\n", inst_num);
1391         fprintf(fp, "        ra_->set_oop (root, ra_->is_oop(inst%d));\n", inst_num);
1392         fprintf(fp, "        ra_->set_pair(root->_idx, ra_->get_reg_second(inst%d), ra_->get_reg_first(inst%d));\n", inst_num, inst_num);
1393         fprintf(fp, "        root->_opnds[0] = inst%d->_opnds[0]->clone(C); // result\n", inst_num);
1394         fprintf(fp, "        // ----- Done with initial setup -----\n");
1395       } else {
1396         if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) {
1397           // Do not have ideal edges for constants after matching
1398           fprintf(fp, "        for( unsigned x%d = inst%d_idx%d; x%d < inst%d_idx%d; x%d++ )\n",
1399                   inst_op_num, inst_num, inst_op_num,
1400                   inst_op_num, inst_num, inst_op_num+1, inst_op_num );
1401           fprintf(fp, "          root->add_req( inst%d->in(x%d) );\n",
1402                   inst_num, inst_op_num );
1403         } else {
1404           fprintf(fp, "        // no ideal edge for constants after matching\n");
1405         }


2946   bool used = false;
2947   // Output the definitions for expand rules & peephole rules
2948   _instructions.reset();
2949   for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
2950     // Ensure this is a machine-world instruction
2951     if ( instr->ideal_only() ) continue;
2952     // If there are multiple defs/kills, or an explicit expand rule, build rule
2953     if( instr->expands() || instr->needs_projections() ||
2954         instr->has_temps() ||
2955         instr->_matrule != NULL &&
2956         instr->num_opnds() != instr->num_unique_opnds() )
2957       defineExpand(_CPP_EXPAND_file._fp, instr);
2958     // If there is an explicit peephole rule, build it
2959     if ( instr->peepholes() )
2960       definePeephole(_CPP_PEEPHOLE_file._fp, instr);
2961 
2962     // Output code to convert to the cisc version, if applicable
2963     used |= instr->define_cisc_version(*this, fp);
2964 
2965     // Output code to convert to the short branch version, if applicable
2966     used |= instr->define_short_branch_methods(fp);
2967   }
2968 
2969   // Construct the method called by cisc_version() to copy inputs and operands.
2970   define_fill_new_machnode(used, fp);
2971 
2972   // Output the definitions for labels
2973   _instructions.reset();
2974   while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
2975     // Ensure this is a machine-world instruction
2976     if ( instr->ideal_only() ) continue;
2977 
2978     // Access the fields for operand Label
2979     int label_position = instr->label_position();
2980     if( label_position != -1 ) {
2981       // Set the label
2982       fprintf(fp,"void %sNode::label_set( Label& label, uint block_num ) {\n", instr->_ident);
2983       fprintf(fp,"  labelOper* oper  = (labelOper*)(opnd_array(%d));\n",
2984               label_position );
2985       fprintf(fp,"  oper->_label     = &label;\n");
2986       fprintf(fp,"  oper->_block_num = block_num;\n");


3691     // Just like MachOperGenerator
3692     const char *opName = inst->_matrule->_rChild->_opType;
3693     fprintf(fp_cpp, "new (C) %sOper(", opName);
3694     // Grab operand form
3695     OperandForm *op = (_globalNames[opName])->is_operand();
3696     // Look up the number of constants
3697     uint num_consts = op->num_consts(_globalNames);
3698     if ( (num_consts > 0) ) {
3699       uint i = 0;
3700       path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3701       for ( i = 1; i < num_consts; ++i ) {
3702         fprintf(fp_cpp, ", ");
3703         path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3704       }
3705     }
3706     fprintf(fp_cpp, " );\n");
3707     // #####
3708   }
3709 
3710   // Fill in the bottom_type where requested
3711   if ( inst->captures_bottom_type() ) {
3712     fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
3713   }
3714   if( inst->is_ideal_if() ) {
3715     fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent);
3716     fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent);
3717   }
3718   if( inst->is_ideal_fastlock() ) {
3719     fprintf(fp_cpp, "%s node->_counters = _leaf->as_FastLock()->counters();\n", indent);
3720   }
3721 
3722 }
3723 
3724 //---------------------------declare_cisc_version------------------------------
3725 // Build CISC version of this instruction
3726 void InstructForm::declare_cisc_version(ArchDesc &AD, FILE *fp_hpp) {
3727   if( AD.can_cisc_spill() ) {
3728     InstructForm *inst_cisc = cisc_spill_alternate();
3729     if (inst_cisc != NULL) {
3730       fprintf(fp_hpp, "  virtual int            cisc_operand() const { return %d; }\n", cisc_spill_operand());
3731       fprintf(fp_hpp, "  virtual MachNode      *cisc_version(int offset, Compile* C);\n");


3745     OperandForm *cisc_oper = AD.cisc_spill_operand();
3746     assert( cisc_oper != NULL, "insanity check");
3747     const char *cisc_oper_name  = cisc_oper->_ident;
3748     assert( cisc_oper_name != NULL, "insanity check");
3749     //
3750     // Set the correct reg_mask_or_stack for the cisc operand
3751     fprintf(fp_cpp, "\n");
3752     fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident);
3753     // Lookup the correct reg_mask_or_stack
3754     const char *reg_mask_name = cisc_reg_mask_name();
3755     fprintf(fp_cpp, "  _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name);
3756     fprintf(fp_cpp, "}\n");
3757     //
3758     // Construct CISC version of this instruction
3759     fprintf(fp_cpp, "\n");
3760     fprintf(fp_cpp, "// Build CISC version of this instruction\n");
3761     fprintf(fp_cpp, "MachNode *%sNode::cisc_version( int offset, Compile* C ) {\n", this->_ident);
3762     // Create the MachNode object
3763     fprintf(fp_cpp, "  %sNode *node = new (C) %sNode();\n", name, name);
3764     // Fill in the bottom_type where requested
3765     if ( this->captures_bottom_type() ) {
3766       fprintf(fp_cpp, "  node->_bottom_type = bottom_type();\n");
3767     }
3768 
3769     uint cur_num_opnds = num_opnds();
3770     if (cur_num_opnds > 1 && cur_num_opnds != num_unique_opnds()) {
3771       fprintf(fp_cpp,"  node->_num_opnds = %d;\n", num_unique_opnds());
3772     }
3773 
3774     fprintf(fp_cpp, "\n");
3775     fprintf(fp_cpp, "  // Copy _idx, inputs and operands to new node\n");
3776     fprintf(fp_cpp, "  fill_new_machnode(node, C);\n");
3777     // Construct operand to access [stack_pointer + offset]
3778     fprintf(fp_cpp, "  // Construct operand to access [stack_pointer + offset]\n");
3779     fprintf(fp_cpp, "  node->set_opnd_array(cisc_operand(), new (C) %sOper(offset));\n", cisc_oper_name);
3780     fprintf(fp_cpp, "\n");
3781 
3782     // Return result and exit scope
3783     fprintf(fp_cpp, "  return node;\n");
3784     fprintf(fp_cpp, "}\n");
3785     fprintf(fp_cpp, "\n");
3786     return true;
3787   }
3788   return false;
3789 }
3790 
3791 //---------------------------declare_short_branch_methods----------------------
3792 // Build prototypes for short branch methods
3793 void InstructForm::declare_short_branch_methods(FILE *fp_hpp) {
3794   if (has_short_branch_form()) {
3795     fprintf(fp_hpp, "  virtual MachNode      *short_branch_version(Compile* C);\n");
3796   }
3797 }
3798 
3799 //---------------------------define_short_branch_methods-----------------------
3800 // Build definitions for short branch methods
3801 bool InstructForm::define_short_branch_methods(FILE *fp_cpp) {
3802   if (has_short_branch_form()) {
3803     InstructForm *short_branch = short_branch_form();
3804     const char   *name         = short_branch->_ident;
3805 
3806     // Construct short_branch_version() method.
3807     fprintf(fp_cpp, "// Build short branch version of this instruction\n");
3808     fprintf(fp_cpp, "MachNode *%sNode::short_branch_version(Compile* C) {\n", this->_ident);
3809     // Create the MachNode object
3810     fprintf(fp_cpp, "  %sNode *node = new (C) %sNode();\n", name, name);
3811     if( is_ideal_if() ) {
3812       fprintf(fp_cpp, "  node->_prob = _prob;\n");
3813       fprintf(fp_cpp, "  node->_fcnt = _fcnt;\n");
3814     }
3815     // Fill in the bottom_type where requested
3816     if ( this->captures_bottom_type() ) {
3817       fprintf(fp_cpp, "  node->_bottom_type = bottom_type();\n");
3818     }
3819 
3820     fprintf(fp_cpp, "\n");
3821     // Short branch version must use same node index for access
3822     // through allocator's tables
3823     fprintf(fp_cpp, "  // Copy _idx, inputs and operands to new node\n");
3824     fprintf(fp_cpp, "  fill_new_machnode(node, C);\n");
3825 
3826     // Return result and exit scope
3827     fprintf(fp_cpp, "  return node;\n");
3828     fprintf(fp_cpp, "}\n");
3829     fprintf(fp_cpp,"\n");
3830     return true;
3831   }
3832   return false;
3833 }
3834 
3835 
3836 //---------------------------buildMachNodeGenerator----------------------------




1365       int inst_op_num = inst_form->operand_position(op_name, Component::USE);
1366       if( inst_op_num == NameList::Not_in_list )
1367         inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF);
1368       assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE");
1369       // find the name of the OperandForm from the local name
1370       const Form *form   = inst_form->_localNames[op_name];
1371       OperandForm  *op_form = form->is_operand();
1372       if( opnds_index == 0 ) {
1373         // Initial setup of new instruction
1374         fprintf(fp, "        // ----- Initial setup -----\n");
1375         //
1376         // Add control edge for this node
1377         fprintf(fp, "        root->add_req(_in[0]);                // control edge\n");
1378         // Add unmatched edges from root of match tree
1379         int op_base = root_form->oper_input_base(globals);
1380         for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) {
1381           fprintf(fp, "        root->add_req(inst%d->in(%d));        // unmatched ideal edge\n",
1382                                           inst_num, unmatched_edge);
1383         }
1384         // If new instruction captures bottom type
1385         if( root_form->captures_bottom_type(globals) ) {
1386           // Get bottom type from instruction whose result we are replacing
1387           fprintf(fp, "        root->_bottom_type = inst%d->bottom_type();\n", inst_num);
1388         }
1389         // Define result register and result operand
1390         fprintf(fp, "        ra_->add_reference(root, inst%d);\n", inst_num);
1391         fprintf(fp, "        ra_->set_oop (root, ra_->is_oop(inst%d));\n", inst_num);
1392         fprintf(fp, "        ra_->set_pair(root->_idx, ra_->get_reg_second(inst%d), ra_->get_reg_first(inst%d));\n", inst_num, inst_num);
1393         fprintf(fp, "        root->_opnds[0] = inst%d->_opnds[0]->clone(C); // result\n", inst_num);
1394         fprintf(fp, "        // ----- Done with initial setup -----\n");
1395       } else {
1396         if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) {
1397           // Do not have ideal edges for constants after matching
1398           fprintf(fp, "        for( unsigned x%d = inst%d_idx%d; x%d < inst%d_idx%d; x%d++ )\n",
1399                   inst_op_num, inst_num, inst_op_num,
1400                   inst_op_num, inst_num, inst_op_num+1, inst_op_num );
1401           fprintf(fp, "          root->add_req( inst%d->in(x%d) );\n",
1402                   inst_num, inst_op_num );
1403         } else {
1404           fprintf(fp, "        // no ideal edge for constants after matching\n");
1405         }


2946   bool used = false;
2947   // Output the definitions for expand rules & peephole rules
2948   _instructions.reset();
2949   for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
2950     // Ensure this is a machine-world instruction
2951     if ( instr->ideal_only() ) continue;
2952     // If there are multiple defs/kills, or an explicit expand rule, build rule
2953     if( instr->expands() || instr->needs_projections() ||
2954         instr->has_temps() ||
2955         instr->_matrule != NULL &&
2956         instr->num_opnds() != instr->num_unique_opnds() )
2957       defineExpand(_CPP_EXPAND_file._fp, instr);
2958     // If there is an explicit peephole rule, build it
2959     if ( instr->peepholes() )
2960       definePeephole(_CPP_PEEPHOLE_file._fp, instr);
2961 
2962     // Output code to convert to the cisc version, if applicable
2963     used |= instr->define_cisc_version(*this, fp);
2964 
2965     // Output code to convert to the short branch version, if applicable
2966     used |= instr->define_short_branch_methods(*this, fp);
2967   }
2968 
2969   // Construct the method called by cisc_version() to copy inputs and operands.
2970   define_fill_new_machnode(used, fp);
2971 
2972   // Output the definitions for labels
2973   _instructions.reset();
2974   while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
2975     // Ensure this is a machine-world instruction
2976     if ( instr->ideal_only() ) continue;
2977 
2978     // Access the fields for operand Label
2979     int label_position = instr->label_position();
2980     if( label_position != -1 ) {
2981       // Set the label
2982       fprintf(fp,"void %sNode::label_set( Label& label, uint block_num ) {\n", instr->_ident);
2983       fprintf(fp,"  labelOper* oper  = (labelOper*)(opnd_array(%d));\n",
2984               label_position );
2985       fprintf(fp,"  oper->_label     = &label;\n");
2986       fprintf(fp,"  oper->_block_num = block_num;\n");


3691     // Just like MachOperGenerator
3692     const char *opName = inst->_matrule->_rChild->_opType;
3693     fprintf(fp_cpp, "new (C) %sOper(", opName);
3694     // Grab operand form
3695     OperandForm *op = (_globalNames[opName])->is_operand();
3696     // Look up the number of constants
3697     uint num_consts = op->num_consts(_globalNames);
3698     if ( (num_consts > 0) ) {
3699       uint i = 0;
3700       path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3701       for ( i = 1; i < num_consts; ++i ) {
3702         fprintf(fp_cpp, ", ");
3703         path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
3704       }
3705     }
3706     fprintf(fp_cpp, " );\n");
3707     // #####
3708   }
3709 
3710   // Fill in the bottom_type where requested
3711   if ( inst->captures_bottom_type(_globalNames) ) {
3712     fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
3713   }
3714   if( inst->is_ideal_if() ) {
3715     fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent);
3716     fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent);
3717   }
3718   if( inst->is_ideal_fastlock() ) {
3719     fprintf(fp_cpp, "%s node->_counters = _leaf->as_FastLock()->counters();\n", indent);
3720   }
3721 
3722 }
3723 
3724 //---------------------------declare_cisc_version------------------------------
3725 // Build CISC version of this instruction
3726 void InstructForm::declare_cisc_version(ArchDesc &AD, FILE *fp_hpp) {
3727   if( AD.can_cisc_spill() ) {
3728     InstructForm *inst_cisc = cisc_spill_alternate();
3729     if (inst_cisc != NULL) {
3730       fprintf(fp_hpp, "  virtual int            cisc_operand() const { return %d; }\n", cisc_spill_operand());
3731       fprintf(fp_hpp, "  virtual MachNode      *cisc_version(int offset, Compile* C);\n");


3745     OperandForm *cisc_oper = AD.cisc_spill_operand();
3746     assert( cisc_oper != NULL, "insanity check");
3747     const char *cisc_oper_name  = cisc_oper->_ident;
3748     assert( cisc_oper_name != NULL, "insanity check");
3749     //
3750     // Set the correct reg_mask_or_stack for the cisc operand
3751     fprintf(fp_cpp, "\n");
3752     fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident);
3753     // Lookup the correct reg_mask_or_stack
3754     const char *reg_mask_name = cisc_reg_mask_name();
3755     fprintf(fp_cpp, "  _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name);
3756     fprintf(fp_cpp, "}\n");
3757     //
3758     // Construct CISC version of this instruction
3759     fprintf(fp_cpp, "\n");
3760     fprintf(fp_cpp, "// Build CISC version of this instruction\n");
3761     fprintf(fp_cpp, "MachNode *%sNode::cisc_version( int offset, Compile* C ) {\n", this->_ident);
3762     // Create the MachNode object
3763     fprintf(fp_cpp, "  %sNode *node = new (C) %sNode();\n", name, name);
3764     // Fill in the bottom_type where requested
3765     if ( this->captures_bottom_type(AD.globalNames()) ) {
3766       fprintf(fp_cpp, "  node->_bottom_type = bottom_type();\n");
3767     }
3768 
3769     uint cur_num_opnds = num_opnds();
3770     if (cur_num_opnds > 1 && cur_num_opnds != num_unique_opnds()) {
3771       fprintf(fp_cpp,"  node->_num_opnds = %d;\n", num_unique_opnds());
3772     }
3773 
3774     fprintf(fp_cpp, "\n");
3775     fprintf(fp_cpp, "  // Copy _idx, inputs and operands to new node\n");
3776     fprintf(fp_cpp, "  fill_new_machnode(node, C);\n");
3777     // Construct operand to access [stack_pointer + offset]
3778     fprintf(fp_cpp, "  // Construct operand to access [stack_pointer + offset]\n");
3779     fprintf(fp_cpp, "  node->set_opnd_array(cisc_operand(), new (C) %sOper(offset));\n", cisc_oper_name);
3780     fprintf(fp_cpp, "\n");
3781 
3782     // Return result and exit scope
3783     fprintf(fp_cpp, "  return node;\n");
3784     fprintf(fp_cpp, "}\n");
3785     fprintf(fp_cpp, "\n");
3786     return true;
3787   }
3788   return false;
3789 }
3790 
3791 //---------------------------declare_short_branch_methods----------------------
3792 // Build prototypes for short branch methods
3793 void InstructForm::declare_short_branch_methods(FILE *fp_hpp) {
3794   if (has_short_branch_form()) {
3795     fprintf(fp_hpp, "  virtual MachNode      *short_branch_version(Compile* C);\n");
3796   }
3797 }
3798 
3799 //---------------------------define_short_branch_methods-----------------------
3800 // Build definitions for short branch methods
3801 bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) {
3802   if (has_short_branch_form()) {
3803     InstructForm *short_branch = short_branch_form();
3804     const char   *name         = short_branch->_ident;
3805 
3806     // Construct short_branch_version() method.
3807     fprintf(fp_cpp, "// Build short branch version of this instruction\n");
3808     fprintf(fp_cpp, "MachNode *%sNode::short_branch_version(Compile* C) {\n", this->_ident);
3809     // Create the MachNode object
3810     fprintf(fp_cpp, "  %sNode *node = new (C) %sNode();\n", name, name);
3811     if( is_ideal_if() ) {
3812       fprintf(fp_cpp, "  node->_prob = _prob;\n");
3813       fprintf(fp_cpp, "  node->_fcnt = _fcnt;\n");
3814     }
3815     // Fill in the bottom_type where requested
3816     if ( this->captures_bottom_type(AD.globalNames()) ) {
3817       fprintf(fp_cpp, "  node->_bottom_type = bottom_type();\n");
3818     }
3819 
3820     fprintf(fp_cpp, "\n");
3821     // Short branch version must use same node index for access
3822     // through allocator's tables
3823     fprintf(fp_cpp, "  // Copy _idx, inputs and operands to new node\n");
3824     fprintf(fp_cpp, "  fill_new_machnode(node, C);\n");
3825 
3826     // Return result and exit scope
3827     fprintf(fp_cpp, "  return node;\n");
3828     fprintf(fp_cpp, "}\n");
3829     fprintf(fp_cpp,"\n");
3830     return true;
3831   }
3832   return false;
3833 }
3834 
3835 
3836 //---------------------------buildMachNodeGenerator----------------------------


src/share/vm/adlc/output_c.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File