src/share/vm/opto/chaitin.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6709742 Sdiff src/share/vm/opto

src/share/vm/opto/chaitin.cpp

Print this page




1406 
1407     } // End of for all instructions
1408 
1409   } // End of for all blocks
1410 }
1411 
1412 //------------------------------find_base_for_derived--------------------------
1413 // Helper to stretch above; recursively discover the base Node for a
1414 // given derived Node.  Easy for AddP-related machine nodes, but needs
1415 // to be recursive for derived Phis.
1416 Node *PhaseChaitin::find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ) {
1417   // See if already computed; if so return it
1418   if( derived_base_map[derived->_idx] )
1419     return derived_base_map[derived->_idx];
1420 
1421   // See if this happens to be a base.
1422   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1423   // pointers derived from NULL!  These are always along paths that
1424   // can't happen at run-time but the optimizer cannot deduce it so
1425   // we have to handle it gracefully.


1426   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1427   // If its an OOP with a non-zero offset, then it is derived.
1428   if( tj->_offset == 0 ) {
1429     derived_base_map[derived->_idx] = derived;
1430     return derived;
1431   }
1432   // Derived is NULL+offset?  Base is NULL!
1433   if( derived->is_Con() ) {
1434     Node *base = new (C, 1) ConPNode( TypePtr::NULL_PTR );
1435     uint no_lidx = 0;  // an unmatched constant in debug info has no LRG
1436     _names.extend(base->_idx, no_lidx);














1437     derived_base_map[derived->_idx] = base;
1438     return base;
1439   }
1440 
1441   // Check for AddP-related opcodes
1442   if( !derived->is_Phi() ) {
1443     assert( derived->as_Mach()->ideal_Opcode() == Op_AddP, "" );
1444     Node *base = derived->in(AddPNode::Base);
1445     derived_base_map[derived->_idx] = base;
1446     return base;
1447   }
1448 
1449   // Recursively find bases for Phis.
1450   // First check to see if we can avoid a base Phi here.
1451   Node *base = find_base_for_derived( derived_base_map, derived->in(1),maxlrg);
1452   uint i;
1453   for( i = 2; i < derived->req(); i++ )
1454     if( base != find_base_for_derived( derived_base_map,derived->in(i),maxlrg))
1455       break;
1456   // Went to the end without finding any different bases?
1457   if( i == derived->req() ) {   // No need for a base Phi here
1458     derived_base_map[derived->_idx] = base;
1459     return base;
1460   }
1461 
1462   // Now we see we need a base-Phi here to merge the bases
1463   base = new (C, derived->req()) PhiNode( derived->in(0), base->bottom_type() );
1464   for( i = 1; i < derived->req(); i++ )

1465     base->init_req(i, find_base_for_derived(derived_base_map, derived->in(i), maxlrg));



1466 
1467   // Search the current block for an existing base-Phi
1468   Block *b = _cfg._bbs[derived->_idx];
1469   for( i = 1; i <= b->end_idx(); i++ ) {// Search for matching Phi
1470     Node *phi = b->_nodes[i];
1471     if( !phi->is_Phi() ) {      // Found end of Phis with no match?
1472       b->_nodes.insert( i, base ); // Must insert created Phi here as base
1473       _cfg._bbs.map( base->_idx, b );
1474       new_lrg(base,maxlrg++);
1475       break;
1476     }
1477     // See if Phi matches.
1478     uint j;
1479     for( j = 1; j < base->req(); j++ )
1480       if( phi->in(j) != base->in(j) &&
1481           !(phi->in(j)->is_Con() && base->in(j)->is_Con()) ) // allow different NULLs
1482         break;
1483     if( j == base->req() ) {    // All inputs match?
1484       base = phi;               // Then use existing 'phi' and drop 'base'
1485       break;


1543         // Remove from live-out set
1544         liveout.remove(lidx);
1545 
1546         // Copies do not define a new value and so do not interfere.
1547         // Remove the copies source from the liveout set before interfering.
1548         uint idx = n->is_Copy();
1549         if( idx ) liveout.remove( n2lidx(n->in(idx)) );
1550       }
1551 
1552       // Found a safepoint?
1553       JVMState *jvms = n->jvms();
1554       if( jvms ) {
1555         // Now scan for a live derived pointer
1556         IndexSetIterator elements(&liveout);
1557         uint neighbor;
1558         while ((neighbor = elements.next()) != 0) {
1559           // Find reaching DEF for base and derived values
1560           // This works because we are still in SSA during this call.
1561           Node *derived = lrgs(neighbor)._def;
1562           const TypePtr *tj = derived->bottom_type()->isa_ptr();


1563           // If its an OOP with a non-zero offset, then it is derived.
1564           if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
1565             Node *base = find_base_for_derived( derived_base_map, derived, maxlrg );
1566             assert( base->_idx < _names.Size(), "" );
1567             // Add reaching DEFs of derived pointer and base pointer as a
1568             // pair of inputs
1569             n->add_req( derived );
1570             n->add_req( base );
1571 
1572             // See if the base pointer is already live to this point.
1573             // Since I'm working on the SSA form, live-ness amounts to
1574             // reaching def's.  So if I find the base's live range then
1575             // I know the base's def reaches here.
1576             if( (n2lidx(base) >= _maxlrg ||// (Brand new base (hence not live) or
1577                  !liveout.member( n2lidx(base) ) ) && // not live) AND
1578                  (n2lidx(base) > 0)                && // not a constant
1579                  _cfg._bbs[base->_idx] != b ) {     //  base not def'd in blk)
1580               // Base pointer is not currently live.  Since I stretched
1581               // the base pointer to here and it crosses basic-block
1582               // boundaries, the global live info is now incorrect.




1406 
1407     } // End of for all instructions
1408 
1409   } // End of for all blocks
1410 }
1411 
1412 //------------------------------find_base_for_derived--------------------------
1413 // Helper to stretch above; recursively discover the base Node for a
1414 // given derived Node.  Easy for AddP-related machine nodes, but needs
1415 // to be recursive for derived Phis.
1416 Node *PhaseChaitin::find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ) {
1417   // See if already computed; if so return it
1418   if( derived_base_map[derived->_idx] )
1419     return derived_base_map[derived->_idx];
1420 
1421   // See if this happens to be a base.
1422   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1423   // pointers derived from NULL!  These are always along paths that
1424   // can't happen at run-time but the optimizer cannot deduce it so
1425   // we have to handle it gracefully.
1426   assert(!derived->bottom_type()->isa_narrowoop() ||
1427           derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1428   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1429   // If its an OOP with a non-zero offset, then it is derived.
1430   if( tj == NULL || tj->_offset == 0 ) {
1431     derived_base_map[derived->_idx] = derived;
1432     return derived;
1433   }
1434   // Derived is NULL+offset?  Base is NULL!
1435   if( derived->is_Con() ) {
1436     Node *base = _matcher.mach_null();
1437     assert(base != NULL, "sanity");
1438     if (base->in(0) == NULL) {
1439       // Initialize it once and make it shared:
1440       // set control to _root and place it into Start block
1441       // (where top() node is placed).
1442       base->init_req(0, _cfg._root);
1443       Block *startb = _cfg._bbs[C->top()->_idx];
1444       startb->_nodes.insert(startb->find_node(C->top()), base );
1445       _cfg._bbs.map( base->_idx, startb );
1446       assert (n2lidx(base) == 0, "should not have LRG yet");
1447     }
1448     if (n2lidx(base) == 0) {
1449       new_lrg(base, maxlrg++);
1450     }
1451     assert(base->in(0) == _cfg._root &&
1452            _cfg._bbs[base->_idx] == _cfg._bbs[C->top()->_idx], "base NULL should be shared");
1453     derived_base_map[derived->_idx] = base;
1454     return base;
1455   }
1456 
1457   // Check for AddP-related opcodes
1458   if( !derived->is_Phi() ) {
1459     assert( derived->as_Mach()->ideal_Opcode() == Op_AddP, "" );
1460     Node *base = derived->in(AddPNode::Base);
1461     derived_base_map[derived->_idx] = base;
1462     return base;
1463   }
1464 
1465   // Recursively find bases for Phis.
1466   // First check to see if we can avoid a base Phi here.
1467   Node *base = find_base_for_derived( derived_base_map, derived->in(1),maxlrg);
1468   uint i;
1469   for( i = 2; i < derived->req(); i++ )
1470     if( base != find_base_for_derived( derived_base_map,derived->in(i),maxlrg))
1471       break;
1472   // Went to the end without finding any different bases?
1473   if( i == derived->req() ) {   // No need for a base Phi here
1474     derived_base_map[derived->_idx] = base;
1475     return base;
1476   }
1477 
1478   // Now we see we need a base-Phi here to merge the bases
1479   const Type *t = base->bottom_type();
1480   base = new (C, derived->req()) PhiNode( derived->in(0), t );
1481   for( i = 1; i < derived->req(); i++ ) {
1482     base->init_req(i, find_base_for_derived(derived_base_map, derived->in(i), maxlrg));
1483     t = t->meet(base->in(i)->bottom_type());
1484   }
1485   base->as_Phi()->set_type(t);
1486 
1487   // Search the current block for an existing base-Phi
1488   Block *b = _cfg._bbs[derived->_idx];
1489   for( i = 1; i <= b->end_idx(); i++ ) {// Search for matching Phi
1490     Node *phi = b->_nodes[i];
1491     if( !phi->is_Phi() ) {      // Found end of Phis with no match?
1492       b->_nodes.insert( i, base ); // Must insert created Phi here as base
1493       _cfg._bbs.map( base->_idx, b );
1494       new_lrg(base,maxlrg++);
1495       break;
1496     }
1497     // See if Phi matches.
1498     uint j;
1499     for( j = 1; j < base->req(); j++ )
1500       if( phi->in(j) != base->in(j) &&
1501           !(phi->in(j)->is_Con() && base->in(j)->is_Con()) ) // allow different NULLs
1502         break;
1503     if( j == base->req() ) {    // All inputs match?
1504       base = phi;               // Then use existing 'phi' and drop 'base'
1505       break;


1563         // Remove from live-out set
1564         liveout.remove(lidx);
1565 
1566         // Copies do not define a new value and so do not interfere.
1567         // Remove the copies source from the liveout set before interfering.
1568         uint idx = n->is_Copy();
1569         if( idx ) liveout.remove( n2lidx(n->in(idx)) );
1570       }
1571 
1572       // Found a safepoint?
1573       JVMState *jvms = n->jvms();
1574       if( jvms ) {
1575         // Now scan for a live derived pointer
1576         IndexSetIterator elements(&liveout);
1577         uint neighbor;
1578         while ((neighbor = elements.next()) != 0) {
1579           // Find reaching DEF for base and derived values
1580           // This works because we are still in SSA during this call.
1581           Node *derived = lrgs(neighbor)._def;
1582           const TypePtr *tj = derived->bottom_type()->isa_ptr();
1583           assert(!derived->bottom_type()->isa_narrowoop() ||
1584                   derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1585           // If its an OOP with a non-zero offset, then it is derived.
1586           if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
1587             Node *base = find_base_for_derived( derived_base_map, derived, maxlrg );
1588             assert( base->_idx < _names.Size(), "" );
1589             // Add reaching DEFs of derived pointer and base pointer as a
1590             // pair of inputs
1591             n->add_req( derived );
1592             n->add_req( base );
1593 
1594             // See if the base pointer is already live to this point.
1595             // Since I'm working on the SSA form, live-ness amounts to
1596             // reaching def's.  So if I find the base's live range then
1597             // I know the base's def reaches here.
1598             if( (n2lidx(base) >= _maxlrg ||// (Brand new base (hence not live) or
1599                  !liveout.member( n2lidx(base) ) ) && // not live) AND
1600                  (n2lidx(base) > 0)                && // not a constant
1601                  _cfg._bbs[base->_idx] != b ) {     //  base not def'd in blk)
1602               // Base pointer is not currently live.  Since I stretched
1603               // the base pointer to here and it crosses basic-block
1604               // boundaries, the global live info is now incorrect.


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