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