1826 // See if already computed; if so return it
1827 if (derived_base_map[derived->_idx]) {
1828 return derived_base_map[derived->_idx];
1829 }
1830
1831 #ifdef ASSERT
1832 if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1833 // Bypass the verification node
1834 Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1835 derived_base_map[derived->_idx] = base;
1836 return base;
1837 }
1838 #endif
1839
1840 // See if this happens to be a base.
1841 // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1842 // pointers derived from null! These are always along paths that
1843 // can't happen at run-time but the optimizer cannot deduce it so
1844 // we have to handle it gracefully.
1845 assert(!derived->bottom_type()->isa_narrowoop() ||
1846 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1847 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1848 // If its an OOP with a non-zero offset, then it is derived.
1849 if( tj == nullptr || tj->_offset == 0 ) {
1850 derived_base_map[derived->_idx] = derived;
1851 return derived;
1852 }
1853 // Derived is null+offset? Base is null!
1854 if( derived->is_Con() ) {
1855 Node *base = _matcher.mach_null();
1856 assert(base != nullptr, "sanity");
1857 if (base->in(0) == nullptr) {
1858 // Initialize it once and make it shared:
1859 // set control to _root and place it into Start block
1860 // (where top() node is placed).
1861 base->init_req(0, _cfg.get_root_node());
1862 Block *startb = _cfg.get_block_for_node(C->top());
1863 uint node_pos = startb->find_node(C->top());
1864 startb->insert_node(base, node_pos);
1865 _cfg.map_node_to_block(base, startb);
1866 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1867
1868 // The loadConP0 might have projection nodes depending on architecture
1869 // Add the projection nodes to the CFG
1995 // Copies do not define a new value and so do not interfere.
1996 // Remove the copies source from the liveout set before interfering.
1997 uint idx = n->is_Copy();
1998 if (idx) {
1999 liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2000 }
2001 }
2002
2003 // Found a safepoint?
2004 JVMState *jvms = n->jvms();
2005 if (jvms && !liveout.is_empty()) {
2006 // Now scan for a live derived pointer
2007 IndexSetIterator elements(&liveout);
2008 uint neighbor;
2009 while ((neighbor = elements.next()) != 0) {
2010 // Find reaching DEF for base and derived values
2011 // This works because we are still in SSA during this call.
2012 Node *derived = lrgs(neighbor)._def;
2013 const TypePtr *tj = derived->bottom_type()->isa_ptr();
2014 assert(!derived->bottom_type()->isa_narrowoop() ||
2015 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
2016 // If its an OOP with a non-zero offset, then it is derived.
2017 if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
2018 Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2019 assert(base->_idx < _lrg_map.size(), "");
2020 // Add reaching DEFs of derived pointer and base pointer as a
2021 // pair of inputs
2022 n->add_req(derived);
2023 n->add_req(base);
2024
2025 // See if the base pointer is already live to this point.
2026 // Since I'm working on the SSA form, live-ness amounts to
2027 // reaching def's. So if I find the base's live range then
2028 // I know the base's def reaches here.
2029 if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2030 !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2031 (_lrg_map.live_range_id(base) > 0) && // not a constant
2032 _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2033 // Base pointer is not currently live. Since I stretched
2034 // the base pointer to here and it crosses basic-block
2035 // boundaries, the global live info is now incorrect.
2036 // Recompute live.
2037 must_recompute_live = true;
2287 return buf+strlen(buf);
2288 }
2289
2290 void PhaseChaitin::dump_for_spill_split_recycle() const {
2291 if( WizardMode && (PrintCompilation || PrintOpto) ) {
2292 // Display which live ranges need to be split and the allocator's state
2293 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2294 for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2295 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2296 tty->print("L%d: ", bidx);
2297 lrgs(bidx).dump();
2298 }
2299 }
2300 tty->cr();
2301 dump();
2302 }
2303 }
2304
2305 void PhaseChaitin::dump_frame() const {
2306 const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2307 const TypeTuple *domain = C->tf()->domain();
2308 const int argcnt = domain->cnt() - TypeFunc::Parms;
2309
2310 // Incoming arguments in registers dump
2311 for( int k = 0; k < argcnt; k++ ) {
2312 OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2313 if( OptoReg::is_reg(parmreg)) {
2314 const char *reg_name = OptoReg::regname(parmreg);
2315 tty->print("#r%3.3d %s", parmreg, reg_name);
2316 parmreg = _matcher._parm_regs[k].second();
2317 if( OptoReg::is_reg(parmreg)) {
2318 tty->print(":%s", OptoReg::regname(parmreg));
2319 }
2320 tty->print(" : parm %d: ", k);
2321 domain->field_at(k + TypeFunc::Parms)->dump();
2322 tty->cr();
2323 }
2324 }
2325
2326 // Check for un-owned padding above incoming args
2327 OptoReg::Name reg = _matcher._new_SP;
2496 // Check each derived/base pair
2497 for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2498 Node* check = sfpt->in(idx);
2499 bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2500 // search upwards through spills and spill phis for AddP
2501 worklist.clear();
2502 worklist.push(check);
2503 uint k = 0;
2504 while (k < worklist.size()) {
2505 check = worklist.at(k);
2506 assert(check, "Bad base or derived pointer");
2507 // See PhaseChaitin::find_base_for_derived() for all cases.
2508 int isc = check->is_Copy();
2509 if (isc) {
2510 worklist.push(check->in(isc));
2511 } else if (check->is_Phi()) {
2512 for (uint m = 1; m < check->req(); m++) {
2513 worklist.push(check->in(m));
2514 }
2515 } else if (check->is_Con()) {
2516 if (is_derived && check->bottom_type()->is_ptr()->_offset != 0) {
2517 // Derived is null+non-zero offset, base must be null.
2518 assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2519 } else {
2520 assert(check->bottom_type()->is_ptr()->_offset == 0, "Bad base pointer");
2521 // Base either ConP(nullptr) or loadConP
2522 if (check->is_Mach()) {
2523 assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2524 } else {
2525 assert(check->Opcode() == Op_ConP &&
2526 check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2527 }
2528 }
2529 } else if (check->bottom_type()->is_ptr()->_offset == 0) {
2530 if (check->is_Proj() || (check->is_Mach() &&
2531 (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2532 check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2533 check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2534 check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2535 #ifdef _LP64
2536 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2537 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2538 (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2539 #endif // _LP64
2540 check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2541 check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2542 // Valid nodes
2543 } else {
2544 check->dump();
2545 assert(false, "Bad base or derived pointer");
2546 }
2547 } else {
2548 assert(is_derived, "Bad base pointer");
2549 assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
|
1826 // See if already computed; if so return it
1827 if (derived_base_map[derived->_idx]) {
1828 return derived_base_map[derived->_idx];
1829 }
1830
1831 #ifdef ASSERT
1832 if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1833 // Bypass the verification node
1834 Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1835 derived_base_map[derived->_idx] = base;
1836 return base;
1837 }
1838 #endif
1839
1840 // See if this happens to be a base.
1841 // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1842 // pointers derived from null! These are always along paths that
1843 // can't happen at run-time but the optimizer cannot deduce it so
1844 // we have to handle it gracefully.
1845 assert(!derived->bottom_type()->isa_narrowoop() ||
1846 derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1847 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1848 // If its an OOP with a non-zero offset, then it is derived.
1849 if (tj == nullptr || tj->offset() == 0) {
1850 derived_base_map[derived->_idx] = derived;
1851 return derived;
1852 }
1853 // Derived is null+offset? Base is null!
1854 if( derived->is_Con() ) {
1855 Node *base = _matcher.mach_null();
1856 assert(base != nullptr, "sanity");
1857 if (base->in(0) == nullptr) {
1858 // Initialize it once and make it shared:
1859 // set control to _root and place it into Start block
1860 // (where top() node is placed).
1861 base->init_req(0, _cfg.get_root_node());
1862 Block *startb = _cfg.get_block_for_node(C->top());
1863 uint node_pos = startb->find_node(C->top());
1864 startb->insert_node(base, node_pos);
1865 _cfg.map_node_to_block(base, startb);
1866 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1867
1868 // The loadConP0 might have projection nodes depending on architecture
1869 // Add the projection nodes to the CFG
1995 // Copies do not define a new value and so do not interfere.
1996 // Remove the copies source from the liveout set before interfering.
1997 uint idx = n->is_Copy();
1998 if (idx) {
1999 liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2000 }
2001 }
2002
2003 // Found a safepoint?
2004 JVMState *jvms = n->jvms();
2005 if (jvms && !liveout.is_empty()) {
2006 // Now scan for a live derived pointer
2007 IndexSetIterator elements(&liveout);
2008 uint neighbor;
2009 while ((neighbor = elements.next()) != 0) {
2010 // Find reaching DEF for base and derived values
2011 // This works because we are still in SSA during this call.
2012 Node *derived = lrgs(neighbor)._def;
2013 const TypePtr *tj = derived->bottom_type()->isa_ptr();
2014 assert(!derived->bottom_type()->isa_narrowoop() ||
2015 derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
2016 // If its an OOP with a non-zero offset, then it is derived.
2017 if (tj && tj->offset() != 0 && tj->isa_oop_ptr()) {
2018 Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2019 assert(base->_idx < _lrg_map.size(), "");
2020 // Add reaching DEFs of derived pointer and base pointer as a
2021 // pair of inputs
2022 n->add_req(derived);
2023 n->add_req(base);
2024
2025 // See if the base pointer is already live to this point.
2026 // Since I'm working on the SSA form, live-ness amounts to
2027 // reaching def's. So if I find the base's live range then
2028 // I know the base's def reaches here.
2029 if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2030 !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2031 (_lrg_map.live_range_id(base) > 0) && // not a constant
2032 _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2033 // Base pointer is not currently live. Since I stretched
2034 // the base pointer to here and it crosses basic-block
2035 // boundaries, the global live info is now incorrect.
2036 // Recompute live.
2037 must_recompute_live = true;
2287 return buf+strlen(buf);
2288 }
2289
2290 void PhaseChaitin::dump_for_spill_split_recycle() const {
2291 if( WizardMode && (PrintCompilation || PrintOpto) ) {
2292 // Display which live ranges need to be split and the allocator's state
2293 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2294 for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2295 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2296 tty->print("L%d: ", bidx);
2297 lrgs(bidx).dump();
2298 }
2299 }
2300 tty->cr();
2301 dump();
2302 }
2303 }
2304
2305 void PhaseChaitin::dump_frame() const {
2306 const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2307 const TypeTuple *domain = C->tf()->domain_cc();
2308 const int argcnt = domain->cnt() - TypeFunc::Parms;
2309
2310 // Incoming arguments in registers dump
2311 for( int k = 0; k < argcnt; k++ ) {
2312 OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2313 if( OptoReg::is_reg(parmreg)) {
2314 const char *reg_name = OptoReg::regname(parmreg);
2315 tty->print("#r%3.3d %s", parmreg, reg_name);
2316 parmreg = _matcher._parm_regs[k].second();
2317 if( OptoReg::is_reg(parmreg)) {
2318 tty->print(":%s", OptoReg::regname(parmreg));
2319 }
2320 tty->print(" : parm %d: ", k);
2321 domain->field_at(k + TypeFunc::Parms)->dump();
2322 tty->cr();
2323 }
2324 }
2325
2326 // Check for un-owned padding above incoming args
2327 OptoReg::Name reg = _matcher._new_SP;
2496 // Check each derived/base pair
2497 for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2498 Node* check = sfpt->in(idx);
2499 bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2500 // search upwards through spills and spill phis for AddP
2501 worklist.clear();
2502 worklist.push(check);
2503 uint k = 0;
2504 while (k < worklist.size()) {
2505 check = worklist.at(k);
2506 assert(check, "Bad base or derived pointer");
2507 // See PhaseChaitin::find_base_for_derived() for all cases.
2508 int isc = check->is_Copy();
2509 if (isc) {
2510 worklist.push(check->in(isc));
2511 } else if (check->is_Phi()) {
2512 for (uint m = 1; m < check->req(); m++) {
2513 worklist.push(check->in(m));
2514 }
2515 } else if (check->is_Con()) {
2516 if (is_derived && check->bottom_type()->is_ptr()->offset() != 0) {
2517 // Derived is null+non-zero offset, base must be null.
2518 assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2519 } else {
2520 assert(check->bottom_type()->is_ptr()->offset() == 0, "Bad base pointer");
2521 // Base either ConP(nullptr) or loadConP
2522 if (check->is_Mach()) {
2523 assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2524 } else {
2525 assert(check->Opcode() == Op_ConP &&
2526 check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2527 }
2528 }
2529 } else if (check->bottom_type()->is_ptr()->offset() == 0) {
2530 if (check->is_Proj() || (check->is_Mach() &&
2531 (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2532 check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2533 check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2534 check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2535 #ifdef _LP64
2536 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2537 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2538 (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2539 #endif // _LP64
2540 check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2541 check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2542 // Valid nodes
2543 } else {
2544 check->dump();
2545 assert(false, "Bad base or derived pointer");
2546 }
2547 } else {
2548 assert(is_derived, "Bad base pointer");
2549 assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
|