1476 }
1477
1478
1479 // Generate Machine Classes for each instruction defined in AD file
1480 fprintf(fp,"\n");
1481 fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");
1482 declare_pipe_classes(fp);
1483
1484 // Generate Machine Classes for each instruction defined in AD file
1485 fprintf(fp,"\n");
1486 fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");
1487 _instructions.reset();
1488 InstructForm *instr;
1489 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
1490 // Ensure this is a machine-world instruction
1491 if ( instr->ideal_only() ) continue;
1492
1493 // Build class definition for this instruction
1494 fprintf(fp,"\n");
1495 fprintf(fp,"class %sNode : public %s { \n",
1496 instr->_ident, instr->mach_base_class() );
1497 fprintf(fp,"private:\n");
1498 fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() );
1499 if ( instr->is_ideal_jump() ) {
1500 fprintf(fp, " GrowableArray<Label*> _index2label;\n");
1501 }
1502 fprintf(fp,"public:\n");
1503 fprintf(fp," MachOper *opnd_array(uint operand_index) const { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); return _opnd_array[operand_index]; }\n");
1504 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");
1505 fprintf(fp,"private:\n");
1506 if ( instr->is_ideal_jump() ) {
1507 fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n");
1508 fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);}\n");
1509 }
1510 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
1511 fprintf(fp," const RegMask *_cisc_RegMask;\n");
1512 }
1513
1514 out_RegMask(fp); // output register mask
1515 fprintf(fp," virtual uint rule() const { return %s_rule; }\n",
1516 instr->_ident);
1549 attr = (Attribute *)attr->_next;
1550 }
1551
1552 // virtual functions for encode and format
1553 //
1554 // Output the opcode function and the encode function here using the
1555 // encoding class information in the _insencode slot.
1556 if ( instr->_insencode ) {
1557 fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n");
1558 }
1559
1560 // virtual function for getting the size of an instruction
1561 if ( instr->_size ) {
1562 fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n");
1563 }
1564
1565 // Return the top-level ideal opcode.
1566 // Use MachNode::ideal_Opcode() for nodes based on MachNode class
1567 // if the ideal_Opcode == Op_Node.
1568 if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||
1569 strcmp("MachNode", instr->mach_base_class()) != 0 ) {
1570 fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n",
1571 instr->ideal_Opcode(_globalNames) );
1572 }
1573
1574 // Allow machine-independent optimization, invert the sense of the IF test
1575 if( instr->is_ideal_if() ) {
1576 fprintf(fp," virtual void negate() { \n");
1577 // Identify which operand contains the negate(able) ideal condition code
1578 int idx = 0;
1579 instr->_components.reset();
1580 for( Component *comp; (comp = instr->_components.iter()) != NULL; ) {
1581 // Check that component is an operand
1582 Form *form = (Form*)_globalNames[comp->_type];
1583 OperandForm *opForm = form ? form->is_operand() : NULL;
1584 if( opForm == NULL ) continue;
1585
1586 // Lookup the position of the operand in the instruction.
1587 if( opForm->is_ideal_bool() ) {
1588 idx = instr->operand_position(comp->_name, comp->_usedef);
1589 assert( idx != NameList::Not_in_list, "Did not find component in list that contained it.");
1614
1615 // If there is an explicit peephole rule, build it
1616 if ( instr->peepholes() != NULL ) {
1617 fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile *C);\n");
1618 }
1619
1620 // Output the declaration for number of relocation entries
1621 if ( instr->reloc(_globalNames) != 0 ) {
1622 fprintf(fp," virtual int reloc() const;\n");
1623 }
1624
1625 if (instr->alignment() != 1) {
1626 fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment());
1627 fprintf(fp," virtual int compute_padding(int current_offset) const;\n");
1628 }
1629
1630 // Starting point for inputs matcher wants.
1631 // Use MachNode::oper_input_base() for nodes based on MachNode class
1632 // if the base == 1.
1633 if ( instr->oper_input_base(_globalNames) != 1 ||
1634 strcmp("MachNode", instr->mach_base_class()) != 0 ) {
1635 fprintf(fp," virtual uint oper_input_base() const { return %d; }\n",
1636 instr->oper_input_base(_globalNames));
1637 }
1638
1639 // Make the constructor and following methods 'public:'
1640 fprintf(fp,"public:\n");
1641
1642 // Constructor
1643 if ( instr->is_ideal_jump() ) {
1644 fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);
1645 } else {
1646 fprintf(fp," %sNode() { ", instr->_ident);
1647 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
1648 fprintf(fp,"_cisc_RegMask = NULL; ");
1649 }
1650 }
1651
1652 fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());
1653
1654 bool node_flags_set = false;
1889 if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
1890 offset = 2;
1891 }
1892 // Special hack for ideal CMoveP; ideal type depends on inputs
1893 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",
1894 offset, offset+1, offset+1);
1895 }
1896 else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) {
1897 int offset = 1;
1898 // Special special hack to see if the Cmp? has been incorporated in the conditional move
1899 MatchNode *rl = instr->_matrule->_rChild->_lChild;
1900 if( rl && !strcmp(rl->_opType, "Binary") ) {
1901 MatchNode *rlr = rl->_rChild;
1902 if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
1903 offset = 2;
1904 }
1905 // Special hack for ideal CMoveN; ideal type depends on inputs
1906 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",
1907 offset, offset+1, offset+1);
1908 }
1909 else if( instr->needs_base_oop_edge(_globalNames) ) {
1910 // Special hack for ideal AddP. Bottom type is an oop IFF it has a
1911 // legal base-pointer input. Otherwise it is NOT an oop.
1912 fprintf(fp," const Type *bottom_type() const { return AddPNode::mach_bottom_type(this); } // AddP\n");
1913 }
1914 else if (instr->is_tls_instruction()) {
1915 // Special hack for tlsLoadP
1916 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");
1917 }
1918 else if ( instr->is_ideal_if() ) {
1919 fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");
1920 }
1921 else if ( instr->is_ideal_membar() ) {
1922 fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");
1923 }
1924
1925 // Check where 'ideal_type' must be customized
1926 /*
1927 if ( instr->_matrule && instr->_matrule->_rChild &&
1928 ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
1929 || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
1930 fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");
1931 }*/
1932
1933 // Analyze machine instructions that either USE or DEF memory.
|
1476 }
1477
1478
1479 // Generate Machine Classes for each instruction defined in AD file
1480 fprintf(fp,"\n");
1481 fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");
1482 declare_pipe_classes(fp);
1483
1484 // Generate Machine Classes for each instruction defined in AD file
1485 fprintf(fp,"\n");
1486 fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");
1487 _instructions.reset();
1488 InstructForm *instr;
1489 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
1490 // Ensure this is a machine-world instruction
1491 if ( instr->ideal_only() ) continue;
1492
1493 // Build class definition for this instruction
1494 fprintf(fp,"\n");
1495 fprintf(fp,"class %sNode : public %s { \n",
1496 instr->_ident, instr->mach_base_class(_globalNames) );
1497 fprintf(fp,"private:\n");
1498 fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() );
1499 if ( instr->is_ideal_jump() ) {
1500 fprintf(fp, " GrowableArray<Label*> _index2label;\n");
1501 }
1502 fprintf(fp,"public:\n");
1503 fprintf(fp," MachOper *opnd_array(uint operand_index) const { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); return _opnd_array[operand_index]; }\n");
1504 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");
1505 fprintf(fp,"private:\n");
1506 if ( instr->is_ideal_jump() ) {
1507 fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n");
1508 fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);}\n");
1509 }
1510 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
1511 fprintf(fp," const RegMask *_cisc_RegMask;\n");
1512 }
1513
1514 out_RegMask(fp); // output register mask
1515 fprintf(fp," virtual uint rule() const { return %s_rule; }\n",
1516 instr->_ident);
1549 attr = (Attribute *)attr->_next;
1550 }
1551
1552 // virtual functions for encode and format
1553 //
1554 // Output the opcode function and the encode function here using the
1555 // encoding class information in the _insencode slot.
1556 if ( instr->_insencode ) {
1557 fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n");
1558 }
1559
1560 // virtual function for getting the size of an instruction
1561 if ( instr->_size ) {
1562 fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n");
1563 }
1564
1565 // Return the top-level ideal opcode.
1566 // Use MachNode::ideal_Opcode() for nodes based on MachNode class
1567 // if the ideal_Opcode == Op_Node.
1568 if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||
1569 strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {
1570 fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n",
1571 instr->ideal_Opcode(_globalNames) );
1572 }
1573
1574 // Allow machine-independent optimization, invert the sense of the IF test
1575 if( instr->is_ideal_if() ) {
1576 fprintf(fp," virtual void negate() { \n");
1577 // Identify which operand contains the negate(able) ideal condition code
1578 int idx = 0;
1579 instr->_components.reset();
1580 for( Component *comp; (comp = instr->_components.iter()) != NULL; ) {
1581 // Check that component is an operand
1582 Form *form = (Form*)_globalNames[comp->_type];
1583 OperandForm *opForm = form ? form->is_operand() : NULL;
1584 if( opForm == NULL ) continue;
1585
1586 // Lookup the position of the operand in the instruction.
1587 if( opForm->is_ideal_bool() ) {
1588 idx = instr->operand_position(comp->_name, comp->_usedef);
1589 assert( idx != NameList::Not_in_list, "Did not find component in list that contained it.");
1614
1615 // If there is an explicit peephole rule, build it
1616 if ( instr->peepholes() != NULL ) {
1617 fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile *C);\n");
1618 }
1619
1620 // Output the declaration for number of relocation entries
1621 if ( instr->reloc(_globalNames) != 0 ) {
1622 fprintf(fp," virtual int reloc() const;\n");
1623 }
1624
1625 if (instr->alignment() != 1) {
1626 fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment());
1627 fprintf(fp," virtual int compute_padding(int current_offset) const;\n");
1628 }
1629
1630 // Starting point for inputs matcher wants.
1631 // Use MachNode::oper_input_base() for nodes based on MachNode class
1632 // if the base == 1.
1633 if ( instr->oper_input_base(_globalNames) != 1 ||
1634 strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {
1635 fprintf(fp," virtual uint oper_input_base() const { return %d; }\n",
1636 instr->oper_input_base(_globalNames));
1637 }
1638
1639 // Make the constructor and following methods 'public:'
1640 fprintf(fp,"public:\n");
1641
1642 // Constructor
1643 if ( instr->is_ideal_jump() ) {
1644 fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);
1645 } else {
1646 fprintf(fp," %sNode() { ", instr->_ident);
1647 if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
1648 fprintf(fp,"_cisc_RegMask = NULL; ");
1649 }
1650 }
1651
1652 fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());
1653
1654 bool node_flags_set = false;
1889 if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
1890 offset = 2;
1891 }
1892 // Special hack for ideal CMoveP; ideal type depends on inputs
1893 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",
1894 offset, offset+1, offset+1);
1895 }
1896 else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) {
1897 int offset = 1;
1898 // Special special hack to see if the Cmp? has been incorporated in the conditional move
1899 MatchNode *rl = instr->_matrule->_rChild->_lChild;
1900 if( rl && !strcmp(rl->_opType, "Binary") ) {
1901 MatchNode *rlr = rl->_rChild;
1902 if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
1903 offset = 2;
1904 }
1905 // Special hack for ideal CMoveN; ideal type depends on inputs
1906 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",
1907 offset, offset+1, offset+1);
1908 }
1909 else if (instr->is_tls_instruction()) {
1910 // Special hack for tlsLoadP
1911 fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");
1912 }
1913 else if ( instr->is_ideal_if() ) {
1914 fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");
1915 }
1916 else if ( instr->is_ideal_membar() ) {
1917 fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");
1918 }
1919
1920 // Check where 'ideal_type' must be customized
1921 /*
1922 if ( instr->_matrule && instr->_matrule->_rChild &&
1923 ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
1924 || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
1925 fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");
1926 }*/
1927
1928 // Analyze machine instructions that either USE or DEF memory.
|