comparison src/share/vm/opto/postaloc.cpp @ 10111:8373c19be854

8011621: live_ranges_in_separate_class.patch Reviewed-by: kvn, roland Contributed-by: niclas.adlertz@oracle.com
author neliasso
date Tue, 16 Apr 2013 10:08:41 +0200
parents 2aff40cb4703
children d1034bd8cefc
comparison
equal deleted inserted replaced
10109:1c6887c9afaa 10111:8373c19be854
54 54
55 const int limit = 60; 55 const int limit = 60;
56 int i; 56 int i;
57 for( i=0; i < limit; i++ ) { 57 for( i=0; i < limit; i++ ) {
58 if( def->is_Proj() && def->in(0)->is_Start() && 58 if( def->is_Proj() && def->in(0)->is_Start() &&
59 _matcher.is_save_on_entry(lrgs(n2lidx(def)).reg()) ) 59 _matcher.is_save_on_entry(lrgs(_lrg_map.live_range_id(def)).reg()))
60 return true; // Direct use of callee-save proj 60 return true; // Direct use of callee-save proj
61 if( def->is_Copy() ) // Copies carry value through 61 if( def->is_Copy() ) // Copies carry value through
62 def = def->in(def->is_Copy()); 62 def = def->in(def->is_Copy());
63 else if( def->is_Phi() ) // Phis can merge it from any direction 63 else if( def->is_Phi() ) // Phis can merge it from any direction
64 def = def->in(1); 64 def = def->in(1);
81 Block *oldb = _cfg._bbs[old->_idx]; 81 Block *oldb = _cfg._bbs[old->_idx];
82 oldb->find_remove(old); 82 oldb->find_remove(old);
83 // Count 1 if deleting an instruction from the current block 83 // Count 1 if deleting an instruction from the current block
84 if( oldb == current_block ) blk_adjust++; 84 if( oldb == current_block ) blk_adjust++;
85 _cfg._bbs.map(old->_idx,NULL); 85 _cfg._bbs.map(old->_idx,NULL);
86 OptoReg::Name old_reg = lrgs(n2lidx(old)).reg(); 86 OptoReg::Name old_reg = lrgs(_lrg_map.live_range_id(old)).reg();
87 if( regnd && (*regnd)[old_reg]==old ) { // Instruction is currently available? 87 if( regnd && (*regnd)[old_reg]==old ) { // Instruction is currently available?
88 value->map(old_reg,NULL); // Yank from value/regnd maps 88 value->map(old_reg,NULL); // Yank from value/regnd maps
89 regnd->map(old_reg,NULL); // This register's value is now unknown 89 regnd->map(old_reg,NULL); // This register's value is now unknown
90 } 90 }
91 return blk_adjust; 91 return blk_adjust;
162 if( def->outcnt() == 0 ) return 0; 162 if( def->outcnt() == 0 ) return 0;
163 163
164 // Not every pair of physical registers are assignment compatible, 164 // Not every pair of physical registers are assignment compatible,
165 // e.g. on sparc floating point registers are not assignable to integer 165 // e.g. on sparc floating point registers are not assignable to integer
166 // registers. 166 // registers.
167 const LRG &def_lrg = lrgs(n2lidx(def)); 167 const LRG &def_lrg = lrgs(_lrg_map.live_range_id(def));
168 OptoReg::Name def_reg = def_lrg.reg(); 168 OptoReg::Name def_reg = def_lrg.reg();
169 const RegMask &use_mask = n->in_RegMask(idx); 169 const RegMask &use_mask = n->in_RegMask(idx);
170 bool can_use = ( RegMask::can_represent(def_reg) ? (use_mask.Member(def_reg) != 0) 170 bool can_use = ( RegMask::can_represent(def_reg) ? (use_mask.Member(def_reg) != 0)
171 : (use_mask.is_AllStack() != 0)); 171 : (use_mask.is_AllStack() != 0));
172 if (!RegMask::is_vector(def->ideal_reg())) { 172 if (!RegMask::is_vector(def->ideal_reg())) {
207 207
208 //------------------------------skip_copies------------------------------------ 208 //------------------------------skip_copies------------------------------------
209 // Skip through any number of copies (that don't mod oop-i-ness) 209 // Skip through any number of copies (that don't mod oop-i-ness)
210 Node *PhaseChaitin::skip_copies( Node *c ) { 210 Node *PhaseChaitin::skip_copies( Node *c ) {
211 int idx = c->is_Copy(); 211 int idx = c->is_Copy();
212 uint is_oop = lrgs(n2lidx(c))._is_oop; 212 uint is_oop = lrgs(_lrg_map.live_range_id(c))._is_oop;
213 while (idx != 0) { 213 while (idx != 0) {
214 guarantee(c->in(idx) != NULL, "must not resurrect dead copy"); 214 guarantee(c->in(idx) != NULL, "must not resurrect dead copy");
215 if (lrgs(n2lidx(c->in(idx)))._is_oop != is_oop) 215 if (lrgs(_lrg_map.live_range_id(c->in(idx)))._is_oop != is_oop) {
216 break; // casting copy, not the same value 216 break; // casting copy, not the same value
217 }
217 c = c->in(idx); 218 c = c->in(idx);
218 idx = c->is_Copy(); 219 idx = c->is_Copy();
219 } 220 }
220 return c; 221 return c;
221 } 222 }
223 //------------------------------elide_copy------------------------------------- 224 //------------------------------elide_copy-------------------------------------
224 // Remove (bypass) copies along Node n, edge k. 225 // Remove (bypass) copies along Node n, edge k.
225 int PhaseChaitin::elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List &regnd, bool can_change_regs ) { 226 int PhaseChaitin::elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List &regnd, bool can_change_regs ) {
226 int blk_adjust = 0; 227 int blk_adjust = 0;
227 228
228 uint nk_idx = n2lidx(n->in(k)); 229 uint nk_idx = _lrg_map.live_range_id(n->in(k));
229 OptoReg::Name nk_reg = lrgs(nk_idx ).reg(); 230 OptoReg::Name nk_reg = lrgs(nk_idx).reg();
230 231
231 // Remove obvious same-register copies 232 // Remove obvious same-register copies
232 Node *x = n->in(k); 233 Node *x = n->in(k);
233 int idx; 234 int idx;
234 while( (idx=x->is_Copy()) != 0 ) { 235 while( (idx=x->is_Copy()) != 0 ) {
235 Node *copy = x->in(idx); 236 Node *copy = x->in(idx);
236 guarantee(copy != NULL, "must not resurrect dead copy"); 237 guarantee(copy != NULL, "must not resurrect dead copy");
237 if( lrgs(n2lidx(copy)).reg() != nk_reg ) break; 238 if(lrgs(_lrg_map.live_range_id(copy)).reg() != nk_reg) {
239 break;
240 }
238 blk_adjust += use_prior_register(n,k,copy,current_block,value,regnd); 241 blk_adjust += use_prior_register(n,k,copy,current_block,value,regnd);
239 if( n->in(k) != copy ) break; // Failed for some cutout? 242 if (n->in(k) != copy) {
243 break; // Failed for some cutout?
244 }
240 x = copy; // Progress, try again 245 x = copy; // Progress, try again
241 } 246 }
242 247
243 // Phis and 2-address instructions cannot change registers so easily - their 248 // Phis and 2-address instructions cannot change registers so easily - their
244 // outputs must match their input. 249 // outputs must match their input.
254 // then reloaded BUT survives in a register the whole way. 259 // then reloaded BUT survives in a register the whole way.
255 Node *val = skip_copies(n->in(k)); 260 Node *val = skip_copies(n->in(k));
256 261
257 if (val == x && nk_idx != 0 && 262 if (val == x && nk_idx != 0 &&
258 regnd[nk_reg] != NULL && regnd[nk_reg] != x && 263 regnd[nk_reg] != NULL && regnd[nk_reg] != x &&
259 n2lidx(x) == n2lidx(regnd[nk_reg])) { 264 _lrg_map.live_range_id(x) == _lrg_map.live_range_id(regnd[nk_reg])) {
260 // When rematerialzing nodes and stretching lifetimes, the 265 // When rematerialzing nodes and stretching lifetimes, the
261 // allocator will reuse the original def for multidef LRG instead 266 // 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 267 // 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 268 // do so. After allocation completes if they are in the same LRG
264 // then it should use the current reaching def instead. 269 // then it should use the current reaching def instead.
268 } 273 }
269 274
270 if (val == x) return blk_adjust; // No progress? 275 if (val == x) return blk_adjust; // No progress?
271 276
272 int n_regs = RegMask::num_registers(val->ideal_reg()); 277 int n_regs = RegMask::num_registers(val->ideal_reg());
273 uint val_idx = n2lidx(val); 278 uint val_idx = _lrg_map.live_range_id(val);
274 OptoReg::Name val_reg = lrgs(val_idx).reg(); 279 OptoReg::Name val_reg = lrgs(val_idx).reg();
275 280
276 // See if it happens to already be in the correct register! 281 // See if it happens to already be in the correct register!
277 // (either Phi's direct register, or the common case of the name 282 // (either Phi's direct register, or the common case of the name
278 // never-clobbered original-def register) 283 // never-clobbered original-def register)
497 502
498 // For all Phi's 503 // For all Phi's
499 for( j = 1; j < phi_dex; j++ ) { 504 for( j = 1; j < phi_dex; j++ ) {
500 uint k; 505 uint k;
501 Node *phi = b->_nodes[j]; 506 Node *phi = b->_nodes[j];
502 uint pidx = n2lidx(phi); 507 uint pidx = _lrg_map.live_range_id(phi);
503 OptoReg::Name preg = lrgs(n2lidx(phi)).reg(); 508 OptoReg::Name preg = lrgs(_lrg_map.live_range_id(phi)).reg();
504 509
505 // Remove copies remaining on edges. Check for junk phi. 510 // Remove copies remaining on edges. Check for junk phi.
506 Node *u = NULL; 511 Node *u = NULL;
507 for( k=1; k<phi->req(); k++ ) { 512 for (k = 1; k < phi->req(); k++) {
508 Node *x = phi->in(k); 513 Node *x = phi->in(k);
509 if( phi != x && u != x ) // Found a different input 514 if( phi != x && u != x ) // Found a different input
510 u = u ? NodeSentinel : x; // Capture unique input, or NodeSentinel for 2nd input 515 u = u ? NodeSentinel : x; // Capture unique input, or NodeSentinel for 2nd input
511 } 516 }
512 if( u != NodeSentinel ) { // Junk Phi. Remove 517 if( u != NodeSentinel ) { // Junk Phi. Remove
553 // up (at loop backedges, because we aren't doing a full flow pass). 558 // up (at loop backedges, because we aren't doing a full flow pass).
554 // The presence of a live use essentially asserts that the use's def is 559 // The presence of a live use essentially asserts that the use's def is
555 // alive and well at the use (or else the allocator fubar'd). Take 560 // alive and well at the use (or else the allocator fubar'd). Take
556 // advantage of this info to set a reaching def for the use-reg. 561 // advantage of this info to set a reaching def for the use-reg.
557 uint k; 562 uint k;
558 for( k = 1; k < n->req(); k++ ) { 563 for (k = 1; k < n->req(); k++) {
559 Node *def = n->in(k); // n->in(k) is a USE; def is the DEF for this USE 564 Node *def = n->in(k); // n->in(k) is a USE; def is the DEF for this USE
560 guarantee(def != NULL, "no disconnected nodes at this point"); 565 guarantee(def != NULL, "no disconnected nodes at this point");
561 uint useidx = n2lidx(def); // useidx is the live range index for this USE 566 uint useidx = _lrg_map.live_range_id(def); // useidx is the live range index for this USE
562 567
563 if( useidx ) { 568 if( useidx ) {
564 OptoReg::Name ureg = lrgs(useidx).reg(); 569 OptoReg::Name ureg = lrgs(useidx).reg();
565 if( !value[ureg] ) { 570 if( !value[ureg] ) {
566 int idx; // Skip occasional useless copy 571 int idx; // Skip occasional useless copy
567 while( (idx=def->is_Copy()) != 0 && 572 while( (idx=def->is_Copy()) != 0 &&
568 def->in(idx) != NULL && // NULL should not happen 573 def->in(idx) != NULL && // NULL should not happen
569 ureg == lrgs(n2lidx(def->in(idx))).reg() ) 574 ureg == lrgs(_lrg_map.live_range_id(def->in(idx))).reg())
570 def = def->in(idx); 575 def = def->in(idx);
571 Node *valdef = skip_copies(def); // tighten up val through non-useless copies 576 Node *valdef = skip_copies(def); // tighten up val through non-useless copies
572 value.map(ureg,valdef); // record improved reaching-def info 577 value.map(ureg,valdef); // record improved reaching-def info
573 regnd.map(ureg, def); 578 regnd.map(ureg, def);
574 // Record other half of doubles 579 // Record other half of doubles
592 // Remove copies along input edges 597 // Remove copies along input edges
593 for( k = 1; k < n->req(); k++ ) 598 for( k = 1; k < n->req(); k++ )
594 j -= elide_copy( n, k, b, value, regnd, two_adr!=k ); 599 j -= elide_copy( n, k, b, value, regnd, two_adr!=k );
595 600
596 // Unallocated Nodes define no registers 601 // Unallocated Nodes define no registers
597 uint lidx = n2lidx(n); 602 uint lidx = _lrg_map.live_range_id(n);
598 if( !lidx ) continue; 603 if (!lidx) {
604 continue;
605 }
599 606
600 // Update the register defined by this instruction 607 // Update the register defined by this instruction
601 OptoReg::Name nreg = lrgs(lidx).reg(); 608 OptoReg::Name nreg = lrgs(lidx).reg();
602 // Skip through all copies to the _value_ being defined. 609 // Skip through all copies to the _value_ being defined.
603 // Do not change from int to pointer 610 // Do not change from int to pointer