598
599 //------------------------------makecon----------------------------------------
600 ConNode* PhaseTransform::makecon(const Type *t) {
601 assert(t->singleton(), "must be a constant");
602 assert(!t->empty() || t == Type::TOP, "must not be vacuous range");
603 switch (t->base()) { // fast paths
604 case Type::Half:
605 case Type::Top: return (ConNode*) C->top();
606 case Type::Int: return intcon( t->is_int()->get_con() );
607 case Type::Long: return longcon( t->is_long()->get_con() );
608 }
609 if (t->is_zero_type())
610 return zerocon(t->basic_type());
611 return uncached_makecon(t);
612 }
613
614 //--------------------------uncached_makecon-----------------------------------
615 // Make an idealized constant - one of ConINode, ConPNode, etc.
616 ConNode* PhaseValues::uncached_makecon(const Type *t) {
617 assert(t->singleton(), "must be a constant");
618 ConNode* x = ConNode::make(C, t);
619 ConNode* k = (ConNode*)hash_find_insert(x); // Value numbering
620 if (k == NULL) {
621 set_type(x, t); // Missed, provide type mapping
622 GrowableArray<Node_Notes*>* nna = C->node_note_array();
623 if (nna != NULL) {
624 Node_Notes* loc = C->locate_node_notes(nna, x->_idx, true);
625 loc->clear(); // do not put debug info on constants
626 }
627 } else {
628 x->destruct(); // Hit, destroy duplicate constant
629 x = k; // use existing constant
630 }
631 return x;
632 }
633
634 //------------------------------intcon-----------------------------------------
635 // Fast integer constant. Same as "transform(new ConINode(TypeInt::make(i)))"
636 ConINode* PhaseTransform::intcon(int i) {
637 // Small integer? Check cache! Check that cached node is not dead
638 if (i >= _icon_min && i <= _icon_max) {
1611 trstack.push(new_input);
1612 }
1613 assert( new_input == clone->in(i), "insanity check");
1614 }
1615 }
1616 }
1617 return new_node;
1618 }
1619
1620
1621 //------------------------------transform_once---------------------------------
1622 // For PhaseCCP, transformation is IDENTITY unless Node computed a constant.
1623 Node *PhaseCCP::transform_once( Node *n ) {
1624 const Type *t = type(n);
1625 // Constant? Use constant Node instead
1626 if( t->singleton() ) {
1627 Node *nn = n; // Default is to return the original constant
1628 if( t == Type::TOP ) {
1629 // cache my top node on the Compile instance
1630 if( C->cached_top_node() == NULL || C->cached_top_node()->in(0) == NULL ) {
1631 C->set_cached_top_node( ConNode::make(C, Type::TOP) );
1632 set_type(C->top(), Type::TOP);
1633 }
1634 nn = C->top();
1635 }
1636 if( !n->is_Con() ) {
1637 if( t != Type::TOP ) {
1638 nn = makecon(t); // ConNode::make(t);
1639 NOT_PRODUCT( inc_constants(); )
1640 } else if( n->is_Region() ) { // Unreachable region
1641 // Note: nn == C->top()
1642 n->set_req(0, NULL); // Cut selfreference
1643 // Eagerly remove dead phis to avoid phis copies creation.
1644 for (DUIterator i = n->outs(); n->has_out(i); i++) {
1645 Node* m = n->out(i);
1646 if( m->is_Phi() ) {
1647 assert(type(m) == Type::TOP, "Unreachable region should not have live phis.");
1648 replace_node(m, nn);
1649 --i; // deleted this phi; rescan starting with next position
1650 }
1651 }
1737 }
1738
1739 //------------------------------do_transform-----------------------------------
1740 void PhasePeephole::do_transform() {
1741 bool method_name_not_printed = true;
1742
1743 // Examine each basic block
1744 for (uint block_number = 1; block_number < _cfg.number_of_blocks(); ++block_number) {
1745 Block* block = _cfg.get_block(block_number);
1746 bool block_not_printed = true;
1747
1748 // and each instruction within a block
1749 uint end_index = block->number_of_nodes();
1750 // block->end_idx() not valid after PhaseRegAlloc
1751 for( uint instruction_index = 1; instruction_index < end_index; ++instruction_index ) {
1752 Node *n = block->get_node(instruction_index);
1753 if( n->is_Mach() ) {
1754 MachNode *m = n->as_Mach();
1755 int deleted_count = 0;
1756 // check for peephole opportunities
1757 MachNode *m2 = m->peephole( block, instruction_index, _regalloc, deleted_count, C );
1758 if( m2 != NULL ) {
1759 #ifndef PRODUCT
1760 if( PrintOptoPeephole ) {
1761 // Print method, first time only
1762 if( C->method() && method_name_not_printed ) {
1763 C->method()->print_short_name(); tty->cr();
1764 method_name_not_printed = false;
1765 }
1766 // Print this block
1767 if( Verbose && block_not_printed) {
1768 tty->print_cr("in block");
1769 block->dump();
1770 block_not_printed = false;
1771 }
1772 // Print instructions being deleted
1773 for( int i = (deleted_count - 1); i >= 0; --i ) {
1774 block->get_node(instruction_index-i)->as_Mach()->format(_regalloc); tty->cr();
1775 }
1776 tty->print_cr("replaced with");
1777 // Print new instruction
|
598
599 //------------------------------makecon----------------------------------------
600 ConNode* PhaseTransform::makecon(const Type *t) {
601 assert(t->singleton(), "must be a constant");
602 assert(!t->empty() || t == Type::TOP, "must not be vacuous range");
603 switch (t->base()) { // fast paths
604 case Type::Half:
605 case Type::Top: return (ConNode*) C->top();
606 case Type::Int: return intcon( t->is_int()->get_con() );
607 case Type::Long: return longcon( t->is_long()->get_con() );
608 }
609 if (t->is_zero_type())
610 return zerocon(t->basic_type());
611 return uncached_makecon(t);
612 }
613
614 //--------------------------uncached_makecon-----------------------------------
615 // Make an idealized constant - one of ConINode, ConPNode, etc.
616 ConNode* PhaseValues::uncached_makecon(const Type *t) {
617 assert(t->singleton(), "must be a constant");
618 ConNode* x = ConNode::make(t);
619 ConNode* k = (ConNode*)hash_find_insert(x); // Value numbering
620 if (k == NULL) {
621 set_type(x, t); // Missed, provide type mapping
622 GrowableArray<Node_Notes*>* nna = C->node_note_array();
623 if (nna != NULL) {
624 Node_Notes* loc = C->locate_node_notes(nna, x->_idx, true);
625 loc->clear(); // do not put debug info on constants
626 }
627 } else {
628 x->destruct(); // Hit, destroy duplicate constant
629 x = k; // use existing constant
630 }
631 return x;
632 }
633
634 //------------------------------intcon-----------------------------------------
635 // Fast integer constant. Same as "transform(new ConINode(TypeInt::make(i)))"
636 ConINode* PhaseTransform::intcon(int i) {
637 // Small integer? Check cache! Check that cached node is not dead
638 if (i >= _icon_min && i <= _icon_max) {
1611 trstack.push(new_input);
1612 }
1613 assert( new_input == clone->in(i), "insanity check");
1614 }
1615 }
1616 }
1617 return new_node;
1618 }
1619
1620
1621 //------------------------------transform_once---------------------------------
1622 // For PhaseCCP, transformation is IDENTITY unless Node computed a constant.
1623 Node *PhaseCCP::transform_once( Node *n ) {
1624 const Type *t = type(n);
1625 // Constant? Use constant Node instead
1626 if( t->singleton() ) {
1627 Node *nn = n; // Default is to return the original constant
1628 if( t == Type::TOP ) {
1629 // cache my top node on the Compile instance
1630 if( C->cached_top_node() == NULL || C->cached_top_node()->in(0) == NULL ) {
1631 C->set_cached_top_node( ConNode::make(Type::TOP) );
1632 set_type(C->top(), Type::TOP);
1633 }
1634 nn = C->top();
1635 }
1636 if( !n->is_Con() ) {
1637 if( t != Type::TOP ) {
1638 nn = makecon(t); // ConNode::make(t);
1639 NOT_PRODUCT( inc_constants(); )
1640 } else if( n->is_Region() ) { // Unreachable region
1641 // Note: nn == C->top()
1642 n->set_req(0, NULL); // Cut selfreference
1643 // Eagerly remove dead phis to avoid phis copies creation.
1644 for (DUIterator i = n->outs(); n->has_out(i); i++) {
1645 Node* m = n->out(i);
1646 if( m->is_Phi() ) {
1647 assert(type(m) == Type::TOP, "Unreachable region should not have live phis.");
1648 replace_node(m, nn);
1649 --i; // deleted this phi; rescan starting with next position
1650 }
1651 }
1737 }
1738
1739 //------------------------------do_transform-----------------------------------
1740 void PhasePeephole::do_transform() {
1741 bool method_name_not_printed = true;
1742
1743 // Examine each basic block
1744 for (uint block_number = 1; block_number < _cfg.number_of_blocks(); ++block_number) {
1745 Block* block = _cfg.get_block(block_number);
1746 bool block_not_printed = true;
1747
1748 // and each instruction within a block
1749 uint end_index = block->number_of_nodes();
1750 // block->end_idx() not valid after PhaseRegAlloc
1751 for( uint instruction_index = 1; instruction_index < end_index; ++instruction_index ) {
1752 Node *n = block->get_node(instruction_index);
1753 if( n->is_Mach() ) {
1754 MachNode *m = n->as_Mach();
1755 int deleted_count = 0;
1756 // check for peephole opportunities
1757 MachNode *m2 = m->peephole( block, instruction_index, _regalloc, deleted_count );
1758 if( m2 != NULL ) {
1759 #ifndef PRODUCT
1760 if( PrintOptoPeephole ) {
1761 // Print method, first time only
1762 if( C->method() && method_name_not_printed ) {
1763 C->method()->print_short_name(); tty->cr();
1764 method_name_not_printed = false;
1765 }
1766 // Print this block
1767 if( Verbose && block_not_printed) {
1768 tty->print_cr("in block");
1769 block->dump();
1770 block_not_printed = false;
1771 }
1772 // Print instructions being deleted
1773 for( int i = (deleted_count - 1); i >= 0; --i ) {
1774 block->get_node(instruction_index-i)->as_Mach()->format(_regalloc); tty->cr();
1775 }
1776 tty->print_cr("replaced with");
1777 // Print new instruction
|