1 /* 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "memory/allocation.inline.hpp" 27 #include "opto/chaitin.hpp" 28 #include "opto/machnode.hpp" 29 30 // see if this register kind does not requires two registers 31 static bool is_single_register(uint x) { 32 #ifdef _LP64 33 return (x != Op_RegD && x != Op_RegL && x != Op_RegP); 34 #else 35 return (x != Op_RegD && x != Op_RegL); 36 #endif 37 } 38 39 //---------------------------may_be_copy_of_callee----------------------------- 40 // Check to see if we can possibly be a copy of a callee-save value. 41 bool PhaseChaitin::may_be_copy_of_callee( Node *def ) const { 42 // Short circuit if there are no callee save registers 43 if (_matcher.number_of_saved_registers() == 0) return false; 44 45 // Expect only a spill-down and reload on exit for callee-save spills. 46 // Chains of copies cannot be deep. 47 // 5008997 - This is wishful thinking. Register allocator seems to 48 // be splitting live ranges for callee save registers to such 49 // an extent that in large methods the chains can be very long 50 // (50+). The conservative answer is to return true if we don't 51 // know as this prevents optimizations from occurring. 52 53 const int limit = 60; 54 int i; 55 for( i=0; i < limit; i++ ) { 56 if( def->is_Proj() && def->in(0)->is_Start() && 150 } 151 152 //------------------------------use_prior_register----------------------------- 153 // Use the prior value instead of the current value, in an effort to make 154 // the current value go dead. Return block iterator adjustment, in case 155 // we yank some instructions from this block. 156 int PhaseChaitin::use_prior_register( Node *n, uint idx, Node *def, Block *current_block, Node_List &value, Node_List ®nd ) { 157 // No effect? 158 if( def == n->in(idx) ) return 0; 159 // Def is currently dead and can be removed? Do not resurrect 160 if( def->outcnt() == 0 ) return 0; 161 162 // Not every pair of physical registers are assignment compatible, 163 // e.g. on sparc floating point registers are not assignable to integer 164 // registers. 165 const LRG &def_lrg = lrgs(n2lidx(def)); 166 OptoReg::Name def_reg = def_lrg.reg(); 167 const RegMask &use_mask = n->in_RegMask(idx); 168 bool can_use = ( RegMask::can_represent(def_reg) ? (use_mask.Member(def_reg) != 0) 169 : (use_mask.is_AllStack() != 0)); 170 // Check for a copy to or from a misaligned pair. 171 can_use = can_use && !use_mask.is_misaligned_Pair() && !def_lrg.mask().is_misaligned_Pair(); 172 173 if (!can_use) 174 return 0; 175 176 // Capture the old def in case it goes dead... 177 Node *old = n->in(idx); 178 179 // Save-on-call copies can only be elided if the entire copy chain can go 180 // away, lest we get the same callee-save value alive in 2 locations at 181 // once. We check for the obvious trivial case here. Although it can 182 // sometimes be elided with cooperation outside our scope, here we will just 183 // miss the opportunity. :-( 184 if( may_be_copy_of_callee(def) ) { 185 if( old->outcnt() > 1 ) return 0; // We're the not last user 186 int idx = old->is_Copy(); 187 assert( idx, "chain of copies being removed" ); 188 Node *old2 = old->in(idx); // Chain of copies 189 if( old2->outcnt() > 1 ) return 0; // old is not the last user 190 int idx2 = old2->is_Copy(); 191 if( !idx2 ) return 0; // Not a chain of 2 copies 192 if( def != old2->in(idx2) ) return 0; // Chain of exactly 2 copies 246 247 // Skip through all copies to the _value_ being used. Do not change from 248 // int to pointer. This attempts to jump through a chain of copies, where 249 // intermediate copies might be illegal, i.e., value is stored down to stack 250 // then reloaded BUT survives in a register the whole way. 251 Node *val = skip_copies(n->in(k)); 252 253 if (val == x && nk_idx != 0 && 254 regnd[nk_reg] != NULL && regnd[nk_reg] != x && 255 n2lidx(x) == n2lidx(regnd[nk_reg])) { 256 // When rematerialzing nodes and stretching lifetimes, the 257 // allocator will reuse the original def for multidef LRG instead 258 // of the current reaching def because it can't know it's safe to 259 // do so. After allocation completes if they are in the same LRG 260 // then it should use the current reaching def instead. 261 n->set_req(k, regnd[nk_reg]); 262 blk_adjust += yank_if_dead(val, current_block, &value, ®nd); 263 val = skip_copies(n->in(k)); 264 } 265 266 if( val == x ) return blk_adjust; // No progress? 267 268 bool single = is_single_register(val->ideal_reg()); 269 uint val_idx = n2lidx(val); 270 OptoReg::Name val_reg = lrgs(val_idx).reg(); 271 272 // See if it happens to already be in the correct register! 273 // (either Phi's direct register, or the common case of the name 274 // never-clobbered original-def register) 275 if( value[val_reg] == val && 276 // Doubles check both halves 277 ( single || value[val_reg-1] == val ) ) { 278 blk_adjust += use_prior_register(n,k,regnd[val_reg],current_block,value,regnd); 279 if( n->in(k) == regnd[val_reg] ) // Success! Quit trying 280 return blk_adjust; 281 } 282 283 // See if we can skip the copy by changing registers. Don't change from 284 // using a register to using the stack unless we know we can remove a 285 // copy-load. Otherwise we might end up making a pile of Intel cisc-spill 286 // ops reading from memory instead of just loading once and using the 287 // register. 288 289 // Also handle duplicate copies here. 290 const Type *t = val->is_Con() ? val->bottom_type() : NULL; 291 292 // Scan all registers to see if this value is around already 293 for( uint reg = 0; reg < (uint)_max_reg; reg++ ) { 294 if (reg == (uint)nk_reg) { 295 // Found ourselves so check if there is only one user of this 296 // copy and keep on searching for a better copy if so. 297 bool ignore_self = true; 298 x = n->in(k); 299 DUIterator_Fast imax, i = x->fast_outs(imax); 300 Node* first = x->fast_out(i); i++; 301 while (i < imax && ignore_self) { 302 Node* use = x->fast_out(i); i++; 303 if (use != first) ignore_self = false; 304 } 305 if (ignore_self) continue; 306 } 307 308 Node *vv = value[reg]; 309 if( !single ) { // Doubles check for aligned-adjacent pair 310 if( (reg&1)==0 ) continue; // Wrong half of a pair 311 if( vv != value[reg-1] ) continue; // Not a complete pair 312 } 313 if( vv == val || // Got a direct hit? 314 (t && vv && vv->bottom_type() == t && vv->is_Mach() && 315 vv->as_Mach()->rule() == val->as_Mach()->rule()) ) { // Or same constant? 316 assert( !n->is_Phi(), "cannot change registers at a Phi so easily" ); 317 if( OptoReg::is_stack(nk_reg) || // CISC-loading from stack OR 318 OptoReg::is_reg(reg) || // turning into a register use OR 319 regnd[reg]->outcnt()==1 ) { // last use of a spill-load turns into a CISC use 320 blk_adjust += use_prior_register(n,k,regnd[reg],current_block,value,regnd); 321 if( n->in(k) == regnd[reg] ) // Success! Quit trying 322 return blk_adjust; 323 } // End of if not degrading to a stack 324 } // End of if found value in another register 325 } // End of scan all machine registers 326 return blk_adjust; 327 } 328 329 509 if( u != NodeSentinel ) { // Junk Phi. Remove 510 b->_nodes.remove(j--); phi_dex--; 511 _cfg._bbs.map(phi->_idx,NULL); 512 phi->replace_by(u); 513 phi->disconnect_inputs(NULL); 514 continue; 515 } 516 // Note that if value[pidx] exists, then we merged no new values here 517 // and the phi is useless. This can happen even with the above phi 518 // removal for complex flows. I cannot keep the better known value here 519 // because locally the phi appears to define a new merged value. If I 520 // keep the better value then a copy of the phi, being unable to use the 521 // global flow analysis, can't "peek through" the phi to the original 522 // reaching value and so will act like it's defining a new value. This 523 // can lead to situations where some uses are from the old and some from 524 // the new values. Not illegal by itself but throws the over-strong 525 // assert in scheduling. 526 if( pidx ) { 527 value.map(preg,phi); 528 regnd.map(preg,phi); 529 OptoReg::Name preg_lo = OptoReg::add(preg,-1); 530 if( !is_single_register(phi->ideal_reg()) ) { 531 value.map(preg_lo,phi); 532 regnd.map(preg_lo,phi); 533 } 534 } 535 } 536 537 // For all remaining instructions 538 for( j = phi_dex; j < b->_nodes.size(); j++ ) { 539 Node *n = b->_nodes[j]; 540 541 if( n->outcnt() == 0 && // Dead? 542 n != C->top() && // (ignore TOP, it has no du info) 543 !n->is_Proj() ) { // fat-proj kills 544 j -= yank_if_dead(n,b,&value,®nd); 545 continue; 546 } 547 548 // Improve reaching-def info. Occasionally post-alloc's liveness gives 549 // up (at loop backedges, because we aren't doing a full flow pass). 550 // The presence of a live use essentially asserts that the use's def is 551 // alive and well at the use (or else the allocator fubar'd). Take 552 // advantage of this info to set a reaching def for the use-reg. 553 uint k; 554 for( k = 1; k < n->req(); k++ ) { 555 Node *def = n->in(k); // n->in(k) is a USE; def is the DEF for this USE 556 guarantee(def != NULL, "no disconnected nodes at this point"); 557 uint useidx = n2lidx(def); // useidx is the live range index for this USE 558 559 if( useidx ) { 560 OptoReg::Name ureg = lrgs(useidx).reg(); 561 if( !value[ureg] ) { 562 int idx; // Skip occasional useless copy 563 while( (idx=def->is_Copy()) != 0 && 564 def->in(idx) != NULL && // NULL should not happen 565 ureg == lrgs(n2lidx(def->in(idx))).reg() ) 566 def = def->in(idx); 567 Node *valdef = skip_copies(def); // tighten up val through non-useless copies 568 value.map(ureg,valdef); // record improved reaching-def info 569 regnd.map(ureg, def); 570 // Record other half of doubles 571 OptoReg::Name ureg_lo = OptoReg::add(ureg,-1); 572 if( !is_single_register(def->ideal_reg()) && 573 ( !RegMask::can_represent(ureg_lo) || 574 lrgs(useidx).mask().Member(ureg_lo) ) && // Nearly always adjacent 575 !value[ureg_lo] ) { 576 value.map(ureg_lo,valdef); // record improved reaching-def info 577 regnd.map(ureg_lo, def); 578 } 579 } 580 } 581 } 582 583 const uint two_adr = n->is_Mach() ? n->as_Mach()->two_adr() : 0; 584 585 // Remove copies along input edges 586 for( k = 1; k < n->req(); k++ ) 587 j -= elide_copy( n, k, b, value, regnd, two_adr!=k ); 588 589 // Unallocated Nodes define no registers 590 uint lidx = n2lidx(n); 591 if( !lidx ) continue; 592 593 // Update the register defined by this instruction 594 OptoReg::Name nreg = lrgs(lidx).reg(); 595 // Skip through all copies to the _value_ being defined. 596 // Do not change from int to pointer 597 Node *val = skip_copies(n); 598 599 // Clear out a dead definition before starting so that the 600 // elimination code doesn't have to guard against it. The 601 // definition could in fact be a kill projection with a count of 602 // 0 which is safe but since those are uninteresting for copy 603 // elimination just delete them as well. 604 if (regnd[nreg] != NULL && regnd[nreg]->outcnt() == 0) { 605 regnd.map(nreg, NULL); 606 value.map(nreg, NULL); 607 } 608 609 uint n_ideal_reg = n->ideal_reg(); 610 if( is_single_register(n_ideal_reg) ) { 611 // If Node 'n' does not change the value mapped by the register, 612 // then 'n' is a useless copy. Do not update the register->node 613 // mapping so 'n' will go dead. 614 if( value[nreg] != val ) { 615 if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, OptoReg::Bad)) { 616 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd); 617 } else { 618 // Update the mapping: record new Node defined by the register 619 regnd.map(nreg,n); 620 // Update mapping for defined *value*, which is the defined 621 // Node after skipping all copies. 622 value.map(nreg,val); 623 } 624 } else if( !may_be_copy_of_callee(n) ) { 625 assert( n->is_Copy(), "" ); 626 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd); 627 } 628 } else { 629 // If the value occupies a register pair, record same info 630 // in both registers. 631 OptoReg::Name nreg_lo = OptoReg::add(nreg,-1); 632 if( RegMask::can_represent(nreg_lo) && // Either a spill slot, or 633 !lrgs(lidx).mask().Member(nreg_lo) ) { // Nearly always adjacent 634 // Sparc occasionally has non-adjacent pairs. 635 // Find the actual other value 636 RegMask tmp = lrgs(lidx).mask(); 637 tmp.Remove(nreg); 638 nreg_lo = tmp.find_first_elem(); 639 } 640 if( value[nreg] != val || value[nreg_lo] != val ) { 641 if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, nreg_lo)) { 642 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd); 643 } else { 644 regnd.map(nreg , n ); 645 regnd.map(nreg_lo, n ); 646 value.map(nreg ,val); 647 value.map(nreg_lo,val); | 1 /* 2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "memory/allocation.inline.hpp" 27 #include "opto/chaitin.hpp" 28 #include "opto/machnode.hpp" 29 30 // See if this register (or pairs, or vector) already contains the value. 31 static bool register_contains_value(Node* val, OptoReg::Name reg, int n_regs, 32 Node_List& value) { 33 for (int i = 0; i < n_regs; i++) { 34 OptoReg::Name nreg = OptoReg::add(reg,-i); 35 if (value[nreg] != val) 36 return false; 37 } 38 return true; 39 } 40 41 //---------------------------may_be_copy_of_callee----------------------------- 42 // Check to see if we can possibly be a copy of a callee-save value. 43 bool PhaseChaitin::may_be_copy_of_callee( Node *def ) const { 44 // Short circuit if there are no callee save registers 45 if (_matcher.number_of_saved_registers() == 0) return false; 46 47 // Expect only a spill-down and reload on exit for callee-save spills. 48 // Chains of copies cannot be deep. 49 // 5008997 - This is wishful thinking. Register allocator seems to 50 // be splitting live ranges for callee save registers to such 51 // an extent that in large methods the chains can be very long 52 // (50+). The conservative answer is to return true if we don't 53 // know as this prevents optimizations from occurring. 54 55 const int limit = 60; 56 int i; 57 for( i=0; i < limit; i++ ) { 58 if( def->is_Proj() && def->in(0)->is_Start() && 152 } 153 154 //------------------------------use_prior_register----------------------------- 155 // Use the prior value instead of the current value, in an effort to make 156 // the current value go dead. Return block iterator adjustment, in case 157 // we yank some instructions from this block. 158 int PhaseChaitin::use_prior_register( Node *n, uint idx, Node *def, Block *current_block, Node_List &value, Node_List ®nd ) { 159 // No effect? 160 if( def == n->in(idx) ) return 0; 161 // Def is currently dead and can be removed? Do not resurrect 162 if( def->outcnt() == 0 ) return 0; 163 164 // Not every pair of physical registers are assignment compatible, 165 // e.g. on sparc floating point registers are not assignable to integer 166 // registers. 167 const LRG &def_lrg = lrgs(n2lidx(def)); 168 OptoReg::Name def_reg = def_lrg.reg(); 169 const RegMask &use_mask = n->in_RegMask(idx); 170 bool can_use = ( RegMask::can_represent(def_reg) ? (use_mask.Member(def_reg) != 0) 171 : (use_mask.is_AllStack() != 0)); 172 if (!RegMask::is_vector(def->ideal_reg())) { 173 // Check for a copy to or from a misaligned pair. 174 // It is workaround for a sparc with misaligned pairs. 175 can_use = can_use && !use_mask.is_misaligned_pair() && !def_lrg.mask().is_misaligned_pair(); 176 } 177 if (!can_use) 178 return 0; 179 180 // Capture the old def in case it goes dead... 181 Node *old = n->in(idx); 182 183 // Save-on-call copies can only be elided if the entire copy chain can go 184 // away, lest we get the same callee-save value alive in 2 locations at 185 // once. We check for the obvious trivial case here. Although it can 186 // sometimes be elided with cooperation outside our scope, here we will just 187 // miss the opportunity. :-( 188 if( may_be_copy_of_callee(def) ) { 189 if( old->outcnt() > 1 ) return 0; // We're the not last user 190 int idx = old->is_Copy(); 191 assert( idx, "chain of copies being removed" ); 192 Node *old2 = old->in(idx); // Chain of copies 193 if( old2->outcnt() > 1 ) return 0; // old is not the last user 194 int idx2 = old2->is_Copy(); 195 if( !idx2 ) return 0; // Not a chain of 2 copies 196 if( def != old2->in(idx2) ) return 0; // Chain of exactly 2 copies 250 251 // Skip through all copies to the _value_ being used. Do not change from 252 // int to pointer. This attempts to jump through a chain of copies, where 253 // intermediate copies might be illegal, i.e., value is stored down to stack 254 // then reloaded BUT survives in a register the whole way. 255 Node *val = skip_copies(n->in(k)); 256 257 if (val == x && nk_idx != 0 && 258 regnd[nk_reg] != NULL && regnd[nk_reg] != x && 259 n2lidx(x) == n2lidx(regnd[nk_reg])) { 260 // When rematerialzing nodes and stretching lifetimes, the 261 // allocator will reuse the original def for multidef LRG instead 262 // of the current reaching def because it can't know it's safe to 263 // do so. After allocation completes if they are in the same LRG 264 // then it should use the current reaching def instead. 265 n->set_req(k, regnd[nk_reg]); 266 blk_adjust += yank_if_dead(val, current_block, &value, ®nd); 267 val = skip_copies(n->in(k)); 268 } 269 270 if (val == x) return blk_adjust; // No progress? 271 272 int n_regs = RegMask::num_registers(val->ideal_reg()); 273 uint val_idx = n2lidx(val); 274 OptoReg::Name val_reg = lrgs(val_idx).reg(); 275 276 // See if it happens to already be in the correct register! 277 // (either Phi's direct register, or the common case of the name 278 // never-clobbered original-def register) 279 if (register_contains_value(val, val_reg, n_regs, value)) { 280 blk_adjust += use_prior_register(n,k,regnd[val_reg],current_block,value,regnd); 281 if( n->in(k) == regnd[val_reg] ) // Success! Quit trying 282 return blk_adjust; 283 } 284 285 // See if we can skip the copy by changing registers. Don't change from 286 // using a register to using the stack unless we know we can remove a 287 // copy-load. Otherwise we might end up making a pile of Intel cisc-spill 288 // ops reading from memory instead of just loading once and using the 289 // register. 290 291 // Also handle duplicate copies here. 292 const Type *t = val->is_Con() ? val->bottom_type() : NULL; 293 294 // Scan all registers to see if this value is around already 295 for( uint reg = 0; reg < (uint)_max_reg; reg++ ) { 296 if (reg == (uint)nk_reg) { 297 // Found ourselves so check if there is only one user of this 298 // copy and keep on searching for a better copy if so. 299 bool ignore_self = true; 300 x = n->in(k); 301 DUIterator_Fast imax, i = x->fast_outs(imax); 302 Node* first = x->fast_out(i); i++; 303 while (i < imax && ignore_self) { 304 Node* use = x->fast_out(i); i++; 305 if (use != first) ignore_self = false; 306 } 307 if (ignore_self) continue; 308 } 309 310 Node *vv = value[reg]; 311 if (n_regs > 1) { // Doubles check for aligned-adjacent pair 312 if( (reg&1)==0 ) continue; // Wrong half of a pair 313 if( vv != value[reg-1] ) continue; // Not a complete pair 314 } 315 if( vv == val || // Got a direct hit? 316 (t && vv && vv->bottom_type() == t && vv->is_Mach() && 317 vv->as_Mach()->rule() == val->as_Mach()->rule()) ) { // Or same constant? 318 assert( !n->is_Phi(), "cannot change registers at a Phi so easily" ); 319 if( OptoReg::is_stack(nk_reg) || // CISC-loading from stack OR 320 OptoReg::is_reg(reg) || // turning into a register use OR 321 regnd[reg]->outcnt()==1 ) { // last use of a spill-load turns into a CISC use 322 blk_adjust += use_prior_register(n,k,regnd[reg],current_block,value,regnd); 323 if( n->in(k) == regnd[reg] ) // Success! Quit trying 324 return blk_adjust; 325 } // End of if not degrading to a stack 326 } // End of if found value in another register 327 } // End of scan all machine registers 328 return blk_adjust; 329 } 330 331 511 if( u != NodeSentinel ) { // Junk Phi. Remove 512 b->_nodes.remove(j--); phi_dex--; 513 _cfg._bbs.map(phi->_idx,NULL); 514 phi->replace_by(u); 515 phi->disconnect_inputs(NULL); 516 continue; 517 } 518 // Note that if value[pidx] exists, then we merged no new values here 519 // and the phi is useless. This can happen even with the above phi 520 // removal for complex flows. I cannot keep the better known value here 521 // because locally the phi appears to define a new merged value. If I 522 // keep the better value then a copy of the phi, being unable to use the 523 // global flow analysis, can't "peek through" the phi to the original 524 // reaching value and so will act like it's defining a new value. This 525 // can lead to situations where some uses are from the old and some from 526 // the new values. Not illegal by itself but throws the over-strong 527 // assert in scheduling. 528 if( pidx ) { 529 value.map(preg,phi); 530 regnd.map(preg,phi); 531 int n_regs = RegMask::num_registers(phi->ideal_reg()); 532 for (int l = 1; l < n_regs; l++) { 533 OptoReg::Name preg_lo = OptoReg::add(preg,-l); 534 value.map(preg_lo,phi); 535 regnd.map(preg_lo,phi); 536 } 537 } 538 } 539 540 // For all remaining instructions 541 for( j = phi_dex; j < b->_nodes.size(); j++ ) { 542 Node *n = b->_nodes[j]; 543 544 if( n->outcnt() == 0 && // Dead? 545 n != C->top() && // (ignore TOP, it has no du info) 546 !n->is_Proj() ) { // fat-proj kills 547 j -= yank_if_dead(n,b,&value,®nd); 548 continue; 549 } 550 551 // Improve reaching-def info. Occasionally post-alloc's liveness gives 552 // up (at loop backedges, because we aren't doing a full flow pass). 553 // The presence of a live use essentially asserts that the use's def is 554 // alive and well at the use (or else the allocator fubar'd). Take 555 // advantage of this info to set a reaching def for the use-reg. 556 uint k; 557 for( k = 1; k < n->req(); k++ ) { 558 Node *def = n->in(k); // n->in(k) is a USE; def is the DEF for this USE 559 guarantee(def != NULL, "no disconnected nodes at this point"); 560 uint useidx = n2lidx(def); // useidx is the live range index for this USE 561 562 if( useidx ) { 563 OptoReg::Name ureg = lrgs(useidx).reg(); 564 if( !value[ureg] ) { 565 int idx; // Skip occasional useless copy 566 while( (idx=def->is_Copy()) != 0 && 567 def->in(idx) != NULL && // NULL should not happen 568 ureg == lrgs(n2lidx(def->in(idx))).reg() ) 569 def = def->in(idx); 570 Node *valdef = skip_copies(def); // tighten up val through non-useless copies 571 value.map(ureg,valdef); // record improved reaching-def info 572 regnd.map(ureg, def); 573 // Record other half of doubles 574 uint def_ideal_reg = def->ideal_reg(); 575 int n_regs = RegMask::num_registers(def_ideal_reg); 576 bool is_vec = RegMask::is_vector(def_ideal_reg); 577 for (int l = 1; l < n_regs; l++) { 578 OptoReg::Name ureg_lo = OptoReg::add(ureg,-l); 579 if (!value[ureg_lo] && 580 (!RegMask::can_represent(ureg_lo) || 581 lrgs(useidx).mask().Member(ureg_lo))) { // Nearly always adjacent 582 value.map(ureg_lo,valdef); // record improved reaching-def info 583 regnd.map(ureg_lo, def); 584 } 585 } 586 } 587 } 588 } 589 590 const uint two_adr = n->is_Mach() ? n->as_Mach()->two_adr() : 0; 591 592 // Remove copies along input edges 593 for( k = 1; k < n->req(); k++ ) 594 j -= elide_copy( n, k, b, value, regnd, two_adr!=k ); 595 596 // Unallocated Nodes define no registers 597 uint lidx = n2lidx(n); 598 if( !lidx ) continue; 599 600 // Update the register defined by this instruction 601 OptoReg::Name nreg = lrgs(lidx).reg(); 602 // Skip through all copies to the _value_ being defined. 603 // Do not change from int to pointer 604 Node *val = skip_copies(n); 605 606 // Clear out a dead definition before starting so that the 607 // elimination code doesn't have to guard against it. The 608 // definition could in fact be a kill projection with a count of 609 // 0 which is safe but since those are uninteresting for copy 610 // elimination just delete them as well. 611 if (regnd[nreg] != NULL && regnd[nreg]->outcnt() == 0) { 612 regnd.map(nreg, NULL); 613 value.map(nreg, NULL); 614 } 615 616 uint n_ideal_reg = n->ideal_reg(); 617 int n_regs = RegMask::num_registers(n_ideal_reg); 618 if (n_regs == 1) { 619 // If Node 'n' does not change the value mapped by the register, 620 // then 'n' is a useless copy. Do not update the register->node 621 // mapping so 'n' will go dead. 622 if( value[nreg] != val ) { 623 if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, OptoReg::Bad)) { 624 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd); 625 } else { 626 // Update the mapping: record new Node defined by the register 627 regnd.map(nreg,n); 628 // Update mapping for defined *value*, which is the defined 629 // Node after skipping all copies. 630 value.map(nreg,val); 631 } 632 } else if( !may_be_copy_of_callee(n) ) { 633 assert( n->is_Copy(), "" ); 634 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd); 635 } 636 } else if (RegMask::is_vector(n_ideal_reg)) { 637 // If Node 'n' does not change the value mapped by the register, 638 // then 'n' is a useless copy. Do not update the register->node 639 // mapping so 'n' will go dead. 640 if (!register_contains_value(val, nreg, n_regs, value)) { 641 // Update the mapping: record new Node defined by the register 642 regnd.map(nreg,n); 643 // Update mapping for defined *value*, which is the defined 644 // Node after skipping all copies. 645 value.map(nreg,val); 646 for (int l = 1; l < n_regs; l++) { 647 OptoReg::Name nreg_lo = OptoReg::add(nreg,-l); 648 regnd.map(nreg_lo, n ); 649 value.map(nreg_lo,val); 650 } 651 } else if (n->is_Copy()) { 652 // Note: vector can't be constant and can't be copy of calee. 653 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd); 654 } 655 } else { 656 // If the value occupies a register pair, record same info 657 // in both registers. 658 OptoReg::Name nreg_lo = OptoReg::add(nreg,-1); 659 if( RegMask::can_represent(nreg_lo) && // Either a spill slot, or 660 !lrgs(lidx).mask().Member(nreg_lo) ) { // Nearly always adjacent 661 // Sparc occasionally has non-adjacent pairs. 662 // Find the actual other value 663 RegMask tmp = lrgs(lidx).mask(); 664 tmp.Remove(nreg); 665 nreg_lo = tmp.find_first_elem(); 666 } 667 if( value[nreg] != val || value[nreg_lo] != val ) { 668 if (eliminate_copy_of_constant(val, n, b, value, regnd, nreg, nreg_lo)) { 669 j -= replace_and_yank_if_dead(n, nreg, b, value, regnd); 670 } else { 671 regnd.map(nreg , n ); 672 regnd.map(nreg_lo, n ); 673 value.map(nreg ,val); 674 value.map(nreg_lo,val); |