1783
1784 } // End of for all instructions
1785
1786 } // End of for all blocks
1787 }
1788
1789 // Helper to stretch above; recursively discover the base Node for a
1790 // given derived Node. Easy for AddP-related machine nodes, but needs
1791 // to be recursive for derived Phis.
1792 Node *PhaseChaitin::find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ) {
1793 // See if already computed; if so return it
1794 if( derived_base_map[derived->_idx] )
1795 return derived_base_map[derived->_idx];
1796
1797 // See if this happens to be a base.
1798 // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1799 // pointers derived from null! These are always along paths that
1800 // can't happen at run-time but the optimizer cannot deduce it so
1801 // we have to handle it gracefully.
1802 assert(!derived->bottom_type()->isa_narrowoop() ||
1803 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1804 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1805 // If its an OOP with a non-zero offset, then it is derived.
1806 if( tj == nullptr || tj->_offset == 0 ) {
1807 derived_base_map[derived->_idx] = derived;
1808 return derived;
1809 }
1810 // Derived is null+offset? Base is null!
1811 if( derived->is_Con() ) {
1812 Node *base = _matcher.mach_null();
1813 assert(base != nullptr, "sanity");
1814 if (base->in(0) == nullptr) {
1815 // Initialize it once and make it shared:
1816 // set control to _root and place it into Start block
1817 // (where top() node is placed).
1818 base->init_req(0, _cfg.get_root_node());
1819 Block *startb = _cfg.get_block_for_node(C->top());
1820 uint node_pos = startb->find_node(C->top());
1821 startb->insert_node(base, node_pos);
1822 _cfg.map_node_to_block(base, startb);
1823 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1824
1825 // The loadConP0 might have projection nodes depending on architecture
1826 // Add the projection nodes to the CFG
1952 // Copies do not define a new value and so do not interfere.
1953 // Remove the copies source from the liveout set before interfering.
1954 uint idx = n->is_Copy();
1955 if (idx) {
1956 liveout.remove(_lrg_map.live_range_id(n->in(idx)));
1957 }
1958 }
1959
1960 // Found a safepoint?
1961 JVMState *jvms = n->jvms();
1962 if (jvms && !liveout.is_empty()) {
1963 // Now scan for a live derived pointer
1964 IndexSetIterator elements(&liveout);
1965 uint neighbor;
1966 while ((neighbor = elements.next()) != 0) {
1967 // Find reaching DEF for base and derived values
1968 // This works because we are still in SSA during this call.
1969 Node *derived = lrgs(neighbor)._def;
1970 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1971 assert(!derived->bottom_type()->isa_narrowoop() ||
1972 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1973 // If its an OOP with a non-zero offset, then it is derived.
1974 if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
1975 Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
1976 assert(base->_idx < _lrg_map.size(), "");
1977 // Add reaching DEFs of derived pointer and base pointer as a
1978 // pair of inputs
1979 n->add_req(derived);
1980 n->add_req(base);
1981
1982 // See if the base pointer is already live to this point.
1983 // Since I'm working on the SSA form, live-ness amounts to
1984 // reaching def's. So if I find the base's live range then
1985 // I know the base's def reaches here.
1986 if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
1987 !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
1988 (_lrg_map.live_range_id(base) > 0) && // not a constant
1989 _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
1990 // Base pointer is not currently live. Since I stretched
1991 // the base pointer to here and it crosses basic-block
1992 // boundaries, the global live info is now incorrect.
1993 // Recompute live.
1994 must_recompute_live = true;
2244 return buf+strlen(buf);
2245 }
2246
2247 void PhaseChaitin::dump_for_spill_split_recycle() const {
2248 if( WizardMode && (PrintCompilation || PrintOpto) ) {
2249 // Display which live ranges need to be split and the allocator's state
2250 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2251 for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2252 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2253 tty->print("L%d: ", bidx);
2254 lrgs(bidx).dump();
2255 }
2256 }
2257 tty->cr();
2258 dump();
2259 }
2260 }
2261
2262 void PhaseChaitin::dump_frame() const {
2263 const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2264 const TypeTuple *domain = C->tf()->domain();
2265 const int argcnt = domain->cnt() - TypeFunc::Parms;
2266
2267 // Incoming arguments in registers dump
2268 for( int k = 0; k < argcnt; k++ ) {
2269 OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2270 if( OptoReg::is_reg(parmreg)) {
2271 const char *reg_name = OptoReg::regname(parmreg);
2272 tty->print("#r%3.3d %s", parmreg, reg_name);
2273 parmreg = _matcher._parm_regs[k].second();
2274 if( OptoReg::is_reg(parmreg)) {
2275 tty->print(":%s", OptoReg::regname(parmreg));
2276 }
2277 tty->print(" : parm %d: ", k);
2278 domain->field_at(k + TypeFunc::Parms)->dump();
2279 tty->cr();
2280 }
2281 }
2282
2283 // Check for un-owned padding above incoming args
2284 OptoReg::Name reg = _matcher._new_SP;
2453 // Check each derived/base pair
2454 for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2455 Node* check = sfpt->in(idx);
2456 bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2457 // search upwards through spills and spill phis for AddP
2458 worklist.clear();
2459 worklist.push(check);
2460 uint k = 0;
2461 while (k < worklist.size()) {
2462 check = worklist.at(k);
2463 assert(check, "Bad base or derived pointer");
2464 // See PhaseChaitin::find_base_for_derived() for all cases.
2465 int isc = check->is_Copy();
2466 if (isc) {
2467 worklist.push(check->in(isc));
2468 } else if (check->is_Phi()) {
2469 for (uint m = 1; m < check->req(); m++) {
2470 worklist.push(check->in(m));
2471 }
2472 } else if (check->is_Con()) {
2473 if (is_derived && check->bottom_type()->is_ptr()->_offset != 0) {
2474 // Derived is null+non-zero offset, base must be null.
2475 assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2476 } else {
2477 assert(check->bottom_type()->is_ptr()->_offset == 0, "Bad base pointer");
2478 // Base either ConP(nullptr) or loadConP
2479 if (check->is_Mach()) {
2480 assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2481 } else {
2482 assert(check->Opcode() == Op_ConP &&
2483 check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2484 }
2485 }
2486 } else if (check->bottom_type()->is_ptr()->_offset == 0) {
2487 if (check->is_Proj() || (check->is_Mach() &&
2488 (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2489 check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2490 check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2491 check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2492 #ifdef _LP64
2493 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2494 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2495 (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2496 #endif // _LP64
2497 check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2498 check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2499 // Valid nodes
2500 } else {
2501 check->dump();
2502 assert(false, "Bad base or derived pointer");
2503 }
2504 } else {
2505 assert(is_derived, "Bad base pointer");
2506 assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
|
1783
1784 } // End of for all instructions
1785
1786 } // End of for all blocks
1787 }
1788
1789 // Helper to stretch above; recursively discover the base Node for a
1790 // given derived Node. Easy for AddP-related machine nodes, but needs
1791 // to be recursive for derived Phis.
1792 Node *PhaseChaitin::find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ) {
1793 // See if already computed; if so return it
1794 if( derived_base_map[derived->_idx] )
1795 return derived_base_map[derived->_idx];
1796
1797 // See if this happens to be a base.
1798 // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1799 // pointers derived from null! These are always along paths that
1800 // can't happen at run-time but the optimizer cannot deduce it so
1801 // we have to handle it gracefully.
1802 assert(!derived->bottom_type()->isa_narrowoop() ||
1803 derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1804 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1805 // If its an OOP with a non-zero offset, then it is derived.
1806 if (tj == nullptr || tj->offset() == 0) {
1807 derived_base_map[derived->_idx] = derived;
1808 return derived;
1809 }
1810 // Derived is null+offset? Base is null!
1811 if( derived->is_Con() ) {
1812 Node *base = _matcher.mach_null();
1813 assert(base != nullptr, "sanity");
1814 if (base->in(0) == nullptr) {
1815 // Initialize it once and make it shared:
1816 // set control to _root and place it into Start block
1817 // (where top() node is placed).
1818 base->init_req(0, _cfg.get_root_node());
1819 Block *startb = _cfg.get_block_for_node(C->top());
1820 uint node_pos = startb->find_node(C->top());
1821 startb->insert_node(base, node_pos);
1822 _cfg.map_node_to_block(base, startb);
1823 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1824
1825 // The loadConP0 might have projection nodes depending on architecture
1826 // Add the projection nodes to the CFG
1952 // Copies do not define a new value and so do not interfere.
1953 // Remove the copies source from the liveout set before interfering.
1954 uint idx = n->is_Copy();
1955 if (idx) {
1956 liveout.remove(_lrg_map.live_range_id(n->in(idx)));
1957 }
1958 }
1959
1960 // Found a safepoint?
1961 JVMState *jvms = n->jvms();
1962 if (jvms && !liveout.is_empty()) {
1963 // Now scan for a live derived pointer
1964 IndexSetIterator elements(&liveout);
1965 uint neighbor;
1966 while ((neighbor = elements.next()) != 0) {
1967 // Find reaching DEF for base and derived values
1968 // This works because we are still in SSA during this call.
1969 Node *derived = lrgs(neighbor)._def;
1970 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1971 assert(!derived->bottom_type()->isa_narrowoop() ||
1972 derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1973 // If its an OOP with a non-zero offset, then it is derived.
1974 if (tj && tj->offset() != 0 && tj->isa_oop_ptr()) {
1975 Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
1976 assert(base->_idx < _lrg_map.size(), "");
1977 // Add reaching DEFs of derived pointer and base pointer as a
1978 // pair of inputs
1979 n->add_req(derived);
1980 n->add_req(base);
1981
1982 // See if the base pointer is already live to this point.
1983 // Since I'm working on the SSA form, live-ness amounts to
1984 // reaching def's. So if I find the base's live range then
1985 // I know the base's def reaches here.
1986 if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
1987 !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
1988 (_lrg_map.live_range_id(base) > 0) && // not a constant
1989 _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
1990 // Base pointer is not currently live. Since I stretched
1991 // the base pointer to here and it crosses basic-block
1992 // boundaries, the global live info is now incorrect.
1993 // Recompute live.
1994 must_recompute_live = true;
2244 return buf+strlen(buf);
2245 }
2246
2247 void PhaseChaitin::dump_for_spill_split_recycle() const {
2248 if( WizardMode && (PrintCompilation || PrintOpto) ) {
2249 // Display which live ranges need to be split and the allocator's state
2250 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2251 for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2252 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2253 tty->print("L%d: ", bidx);
2254 lrgs(bidx).dump();
2255 }
2256 }
2257 tty->cr();
2258 dump();
2259 }
2260 }
2261
2262 void PhaseChaitin::dump_frame() const {
2263 const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2264 const TypeTuple *domain = C->tf()->domain_cc();
2265 const int argcnt = domain->cnt() - TypeFunc::Parms;
2266
2267 // Incoming arguments in registers dump
2268 for( int k = 0; k < argcnt; k++ ) {
2269 OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2270 if( OptoReg::is_reg(parmreg)) {
2271 const char *reg_name = OptoReg::regname(parmreg);
2272 tty->print("#r%3.3d %s", parmreg, reg_name);
2273 parmreg = _matcher._parm_regs[k].second();
2274 if( OptoReg::is_reg(parmreg)) {
2275 tty->print(":%s", OptoReg::regname(parmreg));
2276 }
2277 tty->print(" : parm %d: ", k);
2278 domain->field_at(k + TypeFunc::Parms)->dump();
2279 tty->cr();
2280 }
2281 }
2282
2283 // Check for un-owned padding above incoming args
2284 OptoReg::Name reg = _matcher._new_SP;
2453 // Check each derived/base pair
2454 for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2455 Node* check = sfpt->in(idx);
2456 bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2457 // search upwards through spills and spill phis for AddP
2458 worklist.clear();
2459 worklist.push(check);
2460 uint k = 0;
2461 while (k < worklist.size()) {
2462 check = worklist.at(k);
2463 assert(check, "Bad base or derived pointer");
2464 // See PhaseChaitin::find_base_for_derived() for all cases.
2465 int isc = check->is_Copy();
2466 if (isc) {
2467 worklist.push(check->in(isc));
2468 } else if (check->is_Phi()) {
2469 for (uint m = 1; m < check->req(); m++) {
2470 worklist.push(check->in(m));
2471 }
2472 } else if (check->is_Con()) {
2473 if (is_derived && check->bottom_type()->is_ptr()->offset() != 0) {
2474 // Derived is null+non-zero offset, base must be null.
2475 assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2476 } else {
2477 assert(check->bottom_type()->is_ptr()->offset() == 0, "Bad base pointer");
2478 // Base either ConP(nullptr) or loadConP
2479 if (check->is_Mach()) {
2480 assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2481 } else {
2482 assert(check->Opcode() == Op_ConP &&
2483 check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2484 }
2485 }
2486 } else if (check->bottom_type()->is_ptr()->offset() == 0) {
2487 if (check->is_Proj() || (check->is_Mach() &&
2488 (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2489 check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2490 check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2491 check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2492 #ifdef _LP64
2493 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2494 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2495 (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2496 #endif // _LP64
2497 check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2498 check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2499 // Valid nodes
2500 } else {
2501 check->dump();
2502 assert(false, "Bad base or derived pointer");
2503 }
2504 } else {
2505 assert(is_derived, "Bad base pointer");
2506 assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
|