comparison src/share/vm/adlc/output_c.cpp @ 2254:ab42c7e1cf83

7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early() Summary: Add TEMP edges (and KILL projections) before duplicated operands are removed in Expand() methods. Reviewed-by: never
author kvn
date Thu, 10 Feb 2011 14:25:59 -0800
parents 2f644f85485d
children 1d1603768966
comparison
equal deleted inserted replaced
2253:62a8557e8f36 2254:ab42c7e1cf83
1696 assert( !new_inst->expands(), "Do not have complete support for recursive expansion"); 1696 assert( !new_inst->expands(), "Do not have complete support for recursive expansion");
1697 } // done iterating over new instructions 1697 } // done iterating over new instructions
1698 fprintf(fp,"\n"); 1698 fprintf(fp,"\n");
1699 } // done generating expand rule 1699 } // done generating expand rule
1700 1700
1701 else if( node->_matrule != NULL ) { 1701 // Generate projections for instruction's additional DEFs and KILLs
1702 if( ! node->expands() && (node->needs_projections() || node->has_temps())) {
1703 // Get string representing the MachNode that projections point at
1704 const char *machNode = "this";
1705 // Generate the projections
1706 fprintf(fp," // Add projection edges for additional defs or kills\n");
1707
1708 // Examine each component to see if it is a DEF or KILL
1709 node->_components.reset();
1710 // Skip the first component, if already handled as (SET dst (...))
1711 Component *comp = NULL;
1712 // For kills, the choice of projection numbers is arbitrary
1713 int proj_no = 1;
1714 bool declared_def = false;
1715 bool declared_kill = false;
1716
1717 while( (comp = node->_components.iter()) != NULL ) {
1718 // Lookup register class associated with operand type
1719 Form *form = (Form*)_globalNames[comp->_type];
1720 assert( form, "component type must be a defined form");
1721 OperandForm *op = form->is_operand();
1722
1723 if (comp->is(Component::TEMP)) {
1724 fprintf(fp, " // TEMP %s\n", comp->_name);
1725 if (!declared_def) {
1726 // Define the variable "def" to hold new MachProjNodes
1727 fprintf(fp, " MachTempNode *def;\n");
1728 declared_def = true;
1729 }
1730 if (op && op->_interface && op->_interface->is_RegInterface()) {
1731 fprintf(fp," def = new (C) MachTempNode(state->MachOperGenerator( %s, C ));\n",
1732 machOperEnum(op->_ident));
1733 fprintf(fp," add_req(def);\n");
1734 // The operand for TEMP is already constructed during
1735 // this mach node construction, see buildMachNode().
1736 //
1737 // int idx = node->operand_position_format(comp->_name);
1738 // fprintf(fp," set_opnd_array(%d, state->MachOperGenerator( %s, C ));\n",
1739 // idx, machOperEnum(op->_ident));
1740 } else {
1741 assert(false, "can't have temps which aren't registers");
1742 }
1743 } else if (comp->isa(Component::KILL)) {
1744 fprintf(fp, " // DEF/KILL %s\n", comp->_name);
1745
1746 if (!declared_kill) {
1747 // Define the variable "kill" to hold new MachProjNodes
1748 fprintf(fp, " MachProjNode *kill;\n");
1749 declared_kill = true;
1750 }
1751
1752 assert( op, "Support additional KILLS for base operands");
1753 const char *regmask = reg_mask(*op);
1754 const char *ideal_type = op->ideal_type(_globalNames, _register);
1755
1756 if (!op->is_bound_register()) {
1757 syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n",
1758 node->_ident, comp->_type, comp->_name);
1759 }
1760
1761 fprintf(fp," kill = ");
1762 fprintf(fp,"new (C, 1) MachProjNode( %s, %d, (%s), Op_%s );\n",
1763 machNode, proj_no++, regmask, ideal_type);
1764 fprintf(fp," proj_list.push(kill);\n");
1765 }
1766 }
1767 }
1768
1769 if( !node->expands() && node->_matrule != NULL ) {
1702 // Remove duplicated operands and inputs which use the same name. 1770 // Remove duplicated operands and inputs which use the same name.
1703 // Seach through match operands for the same name usage. 1771 // Seach through match operands for the same name usage.
1704 uint cur_num_opnds = node->num_opnds(); 1772 uint cur_num_opnds = node->num_opnds();
1705 if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) { 1773 if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) {
1706 Component *comp = NULL; 1774 Component *comp = NULL;
1747 fprintf(fp," for(int i = idx%d - 1; i >= (int)idx%d; i--) {\n", cur_num_opnds, new_num_opnds); 1815 fprintf(fp," for(int i = idx%d - 1; i >= (int)idx%d; i--) {\n", cur_num_opnds, new_num_opnds);
1748 fprintf(fp," del_req(i);\n"); 1816 fprintf(fp," del_req(i);\n");
1749 fprintf(fp," }\n"); 1817 fprintf(fp," }\n");
1750 fprintf(fp," _num_opnds = %d;\n", new_num_opnds); 1818 fprintf(fp," _num_opnds = %d;\n", new_num_opnds);
1751 assert(new_num_opnds == node->num_unique_opnds(), "what?"); 1819 assert(new_num_opnds == node->num_unique_opnds(), "what?");
1752 }
1753 }
1754
1755
1756 // Generate projections for instruction's additional DEFs and KILLs
1757 if( ! node->expands() && (node->needs_projections() || node->has_temps())) {
1758 // Get string representing the MachNode that projections point at
1759 const char *machNode = "this";
1760 // Generate the projections
1761 fprintf(fp," // Add projection edges for additional defs or kills\n");
1762
1763 // Examine each component to see if it is a DEF or KILL
1764 node->_components.reset();
1765 // Skip the first component, if already handled as (SET dst (...))
1766 Component *comp = NULL;
1767 // For kills, the choice of projection numbers is arbitrary
1768 int proj_no = 1;
1769 bool declared_def = false;
1770 bool declared_kill = false;
1771
1772 while( (comp = node->_components.iter()) != NULL ) {
1773 // Lookup register class associated with operand type
1774 Form *form = (Form*)_globalNames[comp->_type];
1775 assert( form, "component type must be a defined form");
1776 OperandForm *op = form->is_operand();
1777
1778 if (comp->is(Component::TEMP)) {
1779 fprintf(fp, " // TEMP %s\n", comp->_name);
1780 if (!declared_def) {
1781 // Define the variable "def" to hold new MachProjNodes
1782 fprintf(fp, " MachTempNode *def;\n");
1783 declared_def = true;
1784 }
1785 if (op && op->_interface && op->_interface->is_RegInterface()) {
1786 fprintf(fp," def = new (C) MachTempNode(state->MachOperGenerator( %s, C ));\n",
1787 machOperEnum(op->_ident));
1788 fprintf(fp," add_req(def);\n");
1789 int idx = node->operand_position_format(comp->_name);
1790 fprintf(fp," set_opnd_array(%d, state->MachOperGenerator( %s, C ));\n",
1791 idx, machOperEnum(op->_ident));
1792 } else {
1793 assert(false, "can't have temps which aren't registers");
1794 }
1795 } else if (comp->isa(Component::KILL)) {
1796 fprintf(fp, " // DEF/KILL %s\n", comp->_name);
1797
1798 if (!declared_kill) {
1799 // Define the variable "kill" to hold new MachProjNodes
1800 fprintf(fp, " MachProjNode *kill;\n");
1801 declared_kill = true;
1802 }
1803
1804 assert( op, "Support additional KILLS for base operands");
1805 const char *regmask = reg_mask(*op);
1806 const char *ideal_type = op->ideal_type(_globalNames, _register);
1807
1808 if (!op->is_bound_register()) {
1809 syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n",
1810 node->_ident, comp->_type, comp->_name);
1811 }
1812
1813 fprintf(fp," kill = ");
1814 fprintf(fp,"new (C, 1) MachProjNode( %s, %d, (%s), Op_%s );\n",
1815 machNode, proj_no++, regmask, ideal_type);
1816 fprintf(fp," proj_list.push(kill);\n");
1817 }
1818 } 1820 }
1819 } 1821 }
1820 1822
1821 // If the node is a MachConstantNode, insert the MachConstantBaseNode edge. 1823 // If the node is a MachConstantNode, insert the MachConstantBaseNode edge.
1822 // NOTE: this edge must be the last input (see MachConstantNode::mach_constant_base_node_input). 1824 // NOTE: this edge must be the last input (see MachConstantNode::mach_constant_base_node_input).
3774 if ( dont_care && (! comp->isa(Component::USE)) ) { 3776 if ( dont_care && (! comp->isa(Component::USE)) ) {
3775 continue; 3777 continue;
3776 } 3778 }
3777 dont_care = true; 3779 dont_care = true;
3778 // For each operand not in the match rule, call MachOperGenerator 3780 // For each operand not in the match rule, call MachOperGenerator
3779 // with the enum for the opcode that needs to be built 3781 // with the enum for the opcode that needs to be built.
3780 // and the node just built, the parent of the operand.
3781 ComponentList clist = inst->_components; 3782 ComponentList clist = inst->_components;
3782 int index = clist.operand_position(comp->_name, comp->_usedef); 3783 int index = clist.operand_position(comp->_name, comp->_usedef);
3783 const char *opcode = machOperEnum(comp->_type); 3784 const char *opcode = machOperEnum(comp->_type);
3784 const char *parent = "node";
3785 fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index); 3785 fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index);
3786 fprintf(fp_cpp, "MachOperGenerator(%s, C));\n", opcode); 3786 fprintf(fp_cpp, "MachOperGenerator(%s, C));\n", opcode);
3787 } 3787 }
3788 } 3788 }
3789 else if ( inst->is_chain_of_constant(_globalNames, opType) ) { 3789 else if ( inst->is_chain_of_constant(_globalNames, opType) ) {