annotate src/share/vm/opto/coalesce.cpp @ 216:8d191a7697e2

6715633: when matching a memory node the adr_type should not change Summary: verify the adr_type of a mach node was not changed Reviewed-by: rasbold, never
author kvn
date Fri, 20 Jun 2008 11:10:05 -0700
parents
children ea18057223c4
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 #include "incls/_precompiled.incl"
duke@0 26 #include "incls/_coalesce.cpp.incl"
duke@0 27
duke@0 28 //=============================================================================
duke@0 29 //------------------------------reset_uf_map-----------------------------------
duke@0 30 void PhaseChaitin::reset_uf_map( uint maxlrg ) {
duke@0 31 _maxlrg = maxlrg;
duke@0 32 // Force the Union-Find mapping to be at least this large
duke@0 33 _uf_map.extend(_maxlrg,0);
duke@0 34 // Initialize it to be the ID mapping.
duke@0 35 for( uint i=0; i<_maxlrg; i++ )
duke@0 36 _uf_map.map(i,i);
duke@0 37 }
duke@0 38
duke@0 39 //------------------------------compress_uf_map--------------------------------
duke@0 40 // Make all Nodes map directly to their final live range; no need for
duke@0 41 // the Union-Find mapping after this call.
duke@0 42 void PhaseChaitin::compress_uf_map_for_nodes( ) {
duke@0 43 // For all Nodes, compress mapping
duke@0 44 uint unique = _names.Size();
duke@0 45 for( uint i=0; i<unique; i++ ) {
duke@0 46 uint lrg = _names[i];
duke@0 47 uint compressed_lrg = Find(lrg);
duke@0 48 if( lrg != compressed_lrg )
duke@0 49 _names.map(i,compressed_lrg);
duke@0 50 }
duke@0 51 }
duke@0 52
duke@0 53 //------------------------------Find-------------------------------------------
duke@0 54 // Straight out of Tarjan's union-find algorithm
duke@0 55 uint PhaseChaitin::Find_compress( uint lrg ) {
duke@0 56 uint cur = lrg;
duke@0 57 uint next = _uf_map[cur];
duke@0 58 while( next != cur ) { // Scan chain of equivalences
duke@0 59 assert( next < cur, "always union smaller" );
duke@0 60 cur = next; // until find a fixed-point
duke@0 61 next = _uf_map[cur];
duke@0 62 }
duke@0 63 // Core of union-find algorithm: update chain of
duke@0 64 // equivalences to be equal to the root.
duke@0 65 while( lrg != next ) {
duke@0 66 uint tmp = _uf_map[lrg];
duke@0 67 _uf_map.map(lrg, next);
duke@0 68 lrg = tmp;
duke@0 69 }
duke@0 70 return lrg;
duke@0 71 }
duke@0 72
duke@0 73 //------------------------------Find-------------------------------------------
duke@0 74 // Straight out of Tarjan's union-find algorithm
duke@0 75 uint PhaseChaitin::Find_compress( const Node *n ) {
duke@0 76 uint lrg = Find_compress(_names[n->_idx]);
duke@0 77 _names.map(n->_idx,lrg);
duke@0 78 return lrg;
duke@0 79 }
duke@0 80
duke@0 81 //------------------------------Find_const-------------------------------------
duke@0 82 // Like Find above, but no path compress, so bad asymptotic behavior
duke@0 83 uint PhaseChaitin::Find_const( uint lrg ) const {
duke@0 84 if( !lrg ) return lrg; // Ignore the zero LRG
duke@0 85 // Off the end? This happens during debugging dumps when you got
duke@0 86 // brand new live ranges but have not told the allocator yet.
duke@0 87 if( lrg >= _maxlrg ) return lrg;
duke@0 88 uint next = _uf_map[lrg];
duke@0 89 while( next != lrg ) { // Scan chain of equivalences
duke@0 90 assert( next < lrg, "always union smaller" );
duke@0 91 lrg = next; // until find a fixed-point
duke@0 92 next = _uf_map[lrg];
duke@0 93 }
duke@0 94 return next;
duke@0 95 }
duke@0 96
duke@0 97 //------------------------------Find-------------------------------------------
duke@0 98 // Like Find above, but no path compress, so bad asymptotic behavior
duke@0 99 uint PhaseChaitin::Find_const( const Node *n ) const {
duke@0 100 if( n->_idx >= _names.Size() ) return 0; // not mapped, usual for debug dump
duke@0 101 return Find_const( _names[n->_idx] );
duke@0 102 }
duke@0 103
duke@0 104 //------------------------------Union------------------------------------------
duke@0 105 // union 2 sets together.
duke@0 106 void PhaseChaitin::Union( const Node *src_n, const Node *dst_n ) {
duke@0 107 uint src = Find(src_n);
duke@0 108 uint dst = Find(dst_n);
duke@0 109 assert( src, "" );
duke@0 110 assert( dst, "" );
duke@0 111 assert( src < _maxlrg, "oob" );
duke@0 112 assert( dst < _maxlrg, "oob" );
duke@0 113 assert( src < dst, "always union smaller" );
duke@0 114 _uf_map.map(dst,src);
duke@0 115 }
duke@0 116
duke@0 117 //------------------------------new_lrg----------------------------------------
duke@0 118 void PhaseChaitin::new_lrg( const Node *x, uint lrg ) {
duke@0 119 // Make the Node->LRG mapping
duke@0 120 _names.extend(x->_idx,lrg);
duke@0 121 // Make the Union-Find mapping an identity function
duke@0 122 _uf_map.extend(lrg,lrg);
duke@0 123 }
duke@0 124
duke@0 125 //------------------------------clone_projs------------------------------------
duke@0 126 // After cloning some rematierialized instruction, clone any MachProj's that
duke@0 127 // follow it. Example: Intel zero is XOR, kills flags. Sparc FP constants
duke@0 128 // use G3 as an address temp.
duke@0 129 int PhaseChaitin::clone_projs( Block *b, uint idx, Node *con, Node *copy, uint &maxlrg ) {
duke@0 130 Block *bcon = _cfg._bbs[con->_idx];
duke@0 131 uint cindex = bcon->find_node(con);
duke@0 132 Node *con_next = bcon->_nodes[cindex+1];
duke@0 133 if( con_next->in(0) != con || con_next->Opcode() != Op_MachProj )
duke@0 134 return false; // No MachProj's follow
duke@0 135
duke@0 136 // Copy kills after the cloned constant
duke@0 137 Node *kills = con_next->clone();
duke@0 138 kills->set_req( 0, copy );
duke@0 139 b->_nodes.insert( idx, kills );
duke@0 140 _cfg._bbs.map( kills->_idx, b );
duke@0 141 new_lrg( kills, maxlrg++ );
duke@0 142 return true;
duke@0 143 }
duke@0 144
duke@0 145 //------------------------------compact----------------------------------------
duke@0 146 // Renumber the live ranges to compact them. Makes the IFG smaller.
duke@0 147 void PhaseChaitin::compact() {
duke@0 148 // Current the _uf_map contains a series of short chains which are headed
duke@0 149 // by a self-cycle. All the chains run from big numbers to little numbers.
duke@0 150 // The Find() call chases the chains & shortens them for the next Find call.
duke@0 151 // We are going to change this structure slightly. Numbers above a moving
duke@0 152 // wave 'i' are unchanged. Numbers below 'j' point directly to their
duke@0 153 // compacted live range with no further chaining. There are no chains or
duke@0 154 // cycles below 'i', so the Find call no longer works.
duke@0 155 uint j=1;
duke@0 156 uint i;
duke@0 157 for( i=1; i < _maxlrg; i++ ) {
duke@0 158 uint lr = _uf_map[i];
duke@0 159 // Ignore unallocated live ranges
duke@0 160 if( !lr ) continue;
duke@0 161 assert( lr <= i, "" );
duke@0 162 _uf_map.map(i, ( lr == i ) ? j++ : _uf_map[lr]);
duke@0 163 }
duke@0 164 if( false ) // PrintOptoCompactLiveRanges
duke@0 165 printf("Compacted %d LRs from %d\n",i-j,i);
duke@0 166 // Now change the Node->LR mapping to reflect the compacted names
duke@0 167 uint unique = _names.Size();
duke@0 168 for( i=0; i<unique; i++ )
duke@0 169 _names.map(i,_uf_map[_names[i]]);
duke@0 170
duke@0 171 // Reset the Union-Find mapping
duke@0 172 reset_uf_map(j);
duke@0 173
duke@0 174 }
duke@0 175
duke@0 176 //=============================================================================
duke@0 177 //------------------------------Dump-------------------------------------------
duke@0 178 #ifndef PRODUCT
duke@0 179 void PhaseCoalesce::dump( Node *n ) const {
duke@0 180 // Being a const function means I cannot use 'Find'
duke@0 181 uint r = _phc.Find(n);
duke@0 182 tty->print("L%d/N%d ",r,n->_idx);
duke@0 183 }
duke@0 184
duke@0 185 //------------------------------dump-------------------------------------------
duke@0 186 void PhaseCoalesce::dump() const {
duke@0 187 // I know I have a block layout now, so I can print blocks in a loop
duke@0 188 for( uint i=0; i<_phc._cfg._num_blocks; i++ ) {
duke@0 189 uint j;
duke@0 190 Block *b = _phc._cfg._blocks[i];
duke@0 191 // Print a nice block header
duke@0 192 tty->print("B%d: ",b->_pre_order);
duke@0 193 for( j=1; j<b->num_preds(); j++ )
duke@0 194 tty->print("B%d ", _phc._cfg._bbs[b->pred(j)->_idx]->_pre_order);
duke@0 195 tty->print("-> ");
duke@0 196 for( j=0; j<b->_num_succs; j++ )
duke@0 197 tty->print("B%d ",b->_succs[j]->_pre_order);
duke@0 198 tty->print(" IDom: B%d/#%d\n", b->_idom ? b->_idom->_pre_order : 0, b->_dom_depth);
duke@0 199 uint cnt = b->_nodes.size();
duke@0 200 for( j=0; j<cnt; j++ ) {
duke@0 201 Node *n = b->_nodes[j];
duke@0 202 dump( n );
duke@0 203 tty->print("\t%s\t",n->Name());
duke@0 204
duke@0 205 // Dump the inputs
duke@0 206 uint k; // Exit value of loop
duke@0 207 for( k=0; k<n->req(); k++ ) // For all required inputs
duke@0 208 if( n->in(k) ) dump( n->in(k) );
duke@0 209 else tty->print("_ ");
duke@0 210 int any_prec = 0;
duke@0 211 for( ; k<n->len(); k++ ) // For all precedence inputs
duke@0 212 if( n->in(k) ) {
duke@0 213 if( !any_prec++ ) tty->print(" |");
duke@0 214 dump( n->in(k) );
duke@0 215 }
duke@0 216
duke@0 217 // Dump node-specific info
duke@0 218 n->dump_spec(tty);
duke@0 219 tty->print("\n");
duke@0 220
duke@0 221 }
duke@0 222 tty->print("\n");
duke@0 223 }
duke@0 224 }
duke@0 225 #endif
duke@0 226
duke@0 227 //------------------------------combine_these_two------------------------------
duke@0 228 // Combine the live ranges def'd by these 2 Nodes. N2 is an input to N1.
duke@0 229 void PhaseCoalesce::combine_these_two( Node *n1, Node *n2 ) {
duke@0 230 uint lr1 = _phc.Find(n1);
duke@0 231 uint lr2 = _phc.Find(n2);
duke@0 232 if( lr1 != lr2 && // Different live ranges already AND
duke@0 233 !_phc._ifg->test_edge_sq( lr1, lr2 ) ) { // Do not interfere
duke@0 234 LRG *lrg1 = &_phc.lrgs(lr1);
duke@0 235 LRG *lrg2 = &_phc.lrgs(lr2);
duke@0 236 // Not an oop->int cast; oop->oop, int->int, AND int->oop are OK.
duke@0 237
duke@0 238 // Now, why is int->oop OK? We end up declaring a raw-pointer as an oop
duke@0 239 // and in general that's a bad thing. However, int->oop conversions only
duke@0 240 // happen at GC points, so the lifetime of the misclassified raw-pointer
duke@0 241 // is from the CheckCastPP (that converts it to an oop) backwards up
duke@0 242 // through a merge point and into the slow-path call, and around the
duke@0 243 // diamond up to the heap-top check and back down into the slow-path call.
duke@0 244 // The misclassified raw pointer is NOT live across the slow-path call,
duke@0 245 // and so does not appear in any GC info, so the fact that it is
duke@0 246 // misclassified is OK.
duke@0 247
duke@0 248 if( (lrg1->_is_oop || !lrg2->_is_oop) && // not an oop->int cast AND
duke@0 249 // Compatible final mask
duke@0 250 lrg1->mask().overlap( lrg2->mask() ) ) {
duke@0 251 // Merge larger into smaller.
duke@0 252 if( lr1 > lr2 ) {
duke@0 253 uint tmp = lr1; lr1 = lr2; lr2 = tmp;
duke@0 254 Node *n = n1; n1 = n2; n2 = n;
duke@0 255 LRG *ltmp = lrg1; lrg1 = lrg2; lrg2 = ltmp;
duke@0 256 }
duke@0 257 // Union lr2 into lr1
duke@0 258 _phc.Union( n1, n2 );
duke@0 259 if (lrg1->_maxfreq < lrg2->_maxfreq)
duke@0 260 lrg1->_maxfreq = lrg2->_maxfreq;
duke@0 261 // Merge in the IFG
duke@0 262 _phc._ifg->Union( lr1, lr2 );
duke@0 263 // Combine register restrictions
duke@0 264 lrg1->AND(lrg2->mask());
duke@0 265 }
duke@0 266 }
duke@0 267 }
duke@0 268
duke@0 269 //------------------------------coalesce_driver--------------------------------
duke@0 270 // Copy coalescing
duke@0 271 void PhaseCoalesce::coalesce_driver( ) {
duke@0 272
duke@0 273 verify();
duke@0 274 // Coalesce from high frequency to low
duke@0 275 for( uint i=0; i<_phc._cfg._num_blocks; i++ )
duke@0 276 coalesce( _phc._blks[i] );
duke@0 277
duke@0 278 }
duke@0 279
duke@0 280 //------------------------------insert_copy_with_overlap-----------------------
duke@0 281 // I am inserting copies to come out of SSA form. In the general case, I am
duke@0 282 // doing a parallel renaming. I'm in the Named world now, so I can't do a
duke@0 283 // general parallel renaming. All the copies now use "names" (live-ranges)
duke@0 284 // to carry values instead of the explicit use-def chains. Suppose I need to
duke@0 285 // insert 2 copies into the same block. They copy L161->L128 and L128->L132.
duke@0 286 // If I insert them in the wrong order then L128 will get clobbered before it
duke@0 287 // can get used by the second copy. This cannot happen in the SSA model;
duke@0 288 // direct use-def chains get me the right value. It DOES happen in the named
duke@0 289 // model so I have to handle the reordering of copies.
duke@0 290 //
duke@0 291 // In general, I need to topo-sort the placed copies to avoid conflicts.
duke@0 292 // Its possible to have a closed cycle of copies (e.g., recirculating the same
duke@0 293 // values around a loop). In this case I need a temp to break the cycle.
duke@0 294 void PhaseAggressiveCoalesce::insert_copy_with_overlap( Block *b, Node *copy, uint dst_name, uint src_name ) {
duke@0 295
duke@0 296 // Scan backwards for the locations of the last use of the dst_name.
duke@0 297 // I am about to clobber the dst_name, so the copy must be inserted
duke@0 298 // after the last use. Last use is really first-use on a backwards scan.
duke@0 299 uint i = b->end_idx()-1;
duke@0 300 while( 1 ) {
duke@0 301 Node *n = b->_nodes[i];
duke@0 302 // Check for end of virtual copies; this is also the end of the
duke@0 303 // parallel renaming effort.
duke@0 304 if( n->_idx < _unique ) break;
duke@0 305 uint idx = n->is_Copy();
duke@0 306 assert( idx || n->is_Con() || n->Opcode() == Op_MachProj, "Only copies during parallel renaming" );
duke@0 307 if( idx && _phc.Find(n->in(idx)) == dst_name ) break;
duke@0 308 i--;
duke@0 309 }
duke@0 310 uint last_use_idx = i;
duke@0 311
duke@0 312 // Also search for any kill of src_name that exits the block.
duke@0 313 // Since the copy uses src_name, I have to come before any kill.
duke@0 314 uint kill_src_idx = b->end_idx();
duke@0 315 // There can be only 1 kill that exits any block and that is
duke@0 316 // the last kill. Thus it is the first kill on a backwards scan.
duke@0 317 i = b->end_idx()-1;
duke@0 318 while( 1 ) {
duke@0 319 Node *n = b->_nodes[i];
duke@0 320 // Check for end of virtual copies; this is also the end of the
duke@0 321 // parallel renaming effort.
duke@0 322 if( n->_idx < _unique ) break;
duke@0 323 assert( n->is_Copy() || n->is_Con() || n->Opcode() == Op_MachProj, "Only copies during parallel renaming" );
duke@0 324 if( _phc.Find(n) == src_name ) {
duke@0 325 kill_src_idx = i;
duke@0 326 break;
duke@0 327 }
duke@0 328 i--;
duke@0 329 }
duke@0 330 // Need a temp? Last use of dst comes after the kill of src?
duke@0 331 if( last_use_idx >= kill_src_idx ) {
duke@0 332 // Need to break a cycle with a temp
duke@0 333 uint idx = copy->is_Copy();
duke@0 334 Node *tmp = copy->clone();
duke@0 335 _phc.new_lrg(tmp,_phc._maxlrg++);
duke@0 336 // Insert new temp between copy and source
duke@0 337 tmp ->set_req(idx,copy->in(idx));
duke@0 338 copy->set_req(idx,tmp);
duke@0 339 // Save source in temp early, before source is killed
duke@0 340 b->_nodes.insert(kill_src_idx,tmp);
duke@0 341 _phc._cfg._bbs.map( tmp->_idx, b );
duke@0 342 last_use_idx++;
duke@0 343 }
duke@0 344
duke@0 345 // Insert just after last use
duke@0 346 b->_nodes.insert(last_use_idx+1,copy);
duke@0 347 }
duke@0 348
duke@0 349 //------------------------------insert_copies----------------------------------
duke@0 350 void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) {
duke@0 351 // We do LRGs compressing and fix a liveout data only here since the other
duke@0 352 // place in Split() is guarded by the assert which we never hit.
duke@0 353 _phc.compress_uf_map_for_nodes();
duke@0 354 // Fix block's liveout data for compressed live ranges.
duke@0 355 for(uint lrg = 1; lrg < _phc._maxlrg; lrg++ ) {
duke@0 356 uint compressed_lrg = _phc.Find(lrg);
duke@0 357 if( lrg != compressed_lrg ) {
duke@0 358 for( uint bidx = 0; bidx < _phc._cfg._num_blocks; bidx++ ) {
duke@0 359 IndexSet *liveout = _phc._live->live(_phc._cfg._blocks[bidx]);
duke@0 360 if( liveout->member(lrg) ) {
duke@0 361 liveout->remove(lrg);
duke@0 362 liveout->insert(compressed_lrg);
duke@0 363 }
duke@0 364 }
duke@0 365 }
duke@0 366 }
duke@0 367
duke@0 368 // All new nodes added are actual copies to replace virtual copies.
duke@0 369 // Nodes with index less than '_unique' are original, non-virtual Nodes.
duke@0 370 _unique = C->unique();
duke@0 371
duke@0 372 for( uint i=0; i<_phc._cfg._num_blocks; i++ ) {
duke@0 373 Block *b = _phc._cfg._blocks[i];
duke@0 374 uint cnt = b->num_preds(); // Number of inputs to the Phi
duke@0 375
duke@0 376 for( uint l = 1; l<b->_nodes.size(); l++ ) {
duke@0 377 Node *n = b->_nodes[l];
duke@0 378
duke@0 379 // Do not use removed-copies, use copied value instead
duke@0 380 uint ncnt = n->req();
duke@0 381 for( uint k = 1; k<ncnt; k++ ) {
duke@0 382 Node *copy = n->in(k);
duke@0 383 uint cidx = copy->is_Copy();
duke@0 384 if( cidx ) {
duke@0 385 Node *def = copy->in(cidx);
duke@0 386 if( _phc.Find(copy) == _phc.Find(def) )
duke@0 387 n->set_req(k,def);
duke@0 388 }
duke@0 389 }
duke@0 390
duke@0 391 // Remove any explicit copies that get coalesced.
duke@0 392 uint cidx = n->is_Copy();
duke@0 393 if( cidx ) {
duke@0 394 Node *def = n->in(cidx);
duke@0 395 if( _phc.Find(n) == _phc.Find(def) ) {
duke@0 396 n->replace_by(def);
duke@0 397 n->set_req(cidx,NULL);
duke@0 398 b->_nodes.remove(l);
duke@0 399 l--;
duke@0 400 continue;
duke@0 401 }
duke@0 402 }
duke@0 403
duke@0 404 if( n->is_Phi() ) {
duke@0 405 // Get the chosen name for the Phi
duke@0 406 uint phi_name = _phc.Find( n );
duke@0 407 // Ignore the pre-allocated specials
duke@0 408 if( !phi_name ) continue;
duke@0 409 // Check for mismatch inputs to Phi
duke@0 410 for( uint j = 1; j<cnt; j++ ) {
duke@0 411 Node *m = n->in(j);
duke@0 412 uint src_name = _phc.Find(m);
duke@0 413 if( src_name != phi_name ) {
duke@0 414 Block *pred = _phc._cfg._bbs[b->pred(j)->_idx];
duke@0 415 Node *copy;
duke@0 416 assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach");
duke@0 417 // Rematerialize constants instead of copying them
duke@0 418 if( m->is_Mach() && m->as_Mach()->is_Con() &&
duke@0 419 m->as_Mach()->rematerialize() ) {
duke@0 420 copy = m->clone();
duke@0 421 // Insert the copy in the predecessor basic block
duke@0 422 pred->add_inst(copy);
duke@0 423 // Copy any flags as well
duke@0 424 _phc.clone_projs( pred, pred->end_idx(), m, copy, _phc._maxlrg );
duke@0 425 } else {
duke@0 426 const RegMask *rm = C->matcher()->idealreg2spillmask[m->ideal_reg()];
duke@0 427 copy = new (C) MachSpillCopyNode(m,*rm,*rm);
duke@0 428 // Find a good place to insert. Kinda tricky, use a subroutine
duke@0 429 insert_copy_with_overlap(pred,copy,phi_name,src_name);
duke@0 430 }
duke@0 431 // Insert the copy in the use-def chain
duke@0 432 n->set_req( j, copy );
duke@0 433 _phc._cfg._bbs.map( copy->_idx, pred );
duke@0 434 // Extend ("register allocate") the names array for the copy.
duke@0 435 _phc._names.extend( copy->_idx, phi_name );
duke@0 436 } // End of if Phi names do not match
duke@0 437 } // End of for all inputs to Phi
duke@0 438 } else { // End of if Phi
duke@0 439
duke@0 440 // Now check for 2-address instructions
duke@0 441 uint idx;
duke@0 442 if( n->is_Mach() && (idx=n->as_Mach()->two_adr()) ) {
duke@0 443 // Get the chosen name for the Node
duke@0 444 uint name = _phc.Find( n );
duke@0 445 assert( name, "no 2-address specials" );
duke@0 446 // Check for name mis-match on the 2-address input
duke@0 447 Node *m = n->in(idx);
duke@0 448 if( _phc.Find(m) != name ) {
duke@0 449 Node *copy;
duke@0 450 assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach");
duke@0 451 // At this point it is unsafe to extend live ranges (6550579).
duke@0 452 // Rematerialize only constants as we do for Phi above.
duke@0 453 if( m->is_Mach() && m->as_Mach()->is_Con() &&
duke@0 454 m->as_Mach()->rematerialize() ) {
duke@0 455 copy = m->clone();
duke@0 456 // Insert the copy in the basic block, just before us
duke@0 457 b->_nodes.insert( l++, copy );
duke@0 458 if( _phc.clone_projs( b, l, m, copy, _phc._maxlrg ) )
duke@0 459 l++;
duke@0 460 } else {
duke@0 461 const RegMask *rm = C->matcher()->idealreg2spillmask[m->ideal_reg()];
duke@0 462 copy = new (C) MachSpillCopyNode( m, *rm, *rm );
duke@0 463 // Insert the copy in the basic block, just before us
duke@0 464 b->_nodes.insert( l++, copy );
duke@0 465 }
duke@0 466 // Insert the copy in the use-def chain
duke@0 467 n->set_req(idx, copy );
duke@0 468 // Extend ("register allocate") the names array for the copy.
duke@0 469 _phc._names.extend( copy->_idx, name );
duke@0 470 _phc._cfg._bbs.map( copy->_idx, b );
duke@0 471 }
duke@0 472
duke@0 473 } // End of is two-adr
duke@0 474
duke@0 475 // Insert a copy at a debug use for a lrg which has high frequency
duke@0 476 if( (b->_freq < OPTO_DEBUG_SPLIT_FREQ) && n->is_MachSafePoint() ) {
duke@0 477 // Walk the debug inputs to the node and check for lrg freq
duke@0 478 JVMState* jvms = n->jvms();
duke@0 479 uint debug_start = jvms ? jvms->debug_start() : 999999;
duke@0 480 uint debug_end = jvms ? jvms->debug_end() : 999999;
duke@0 481 for(uint inpidx = debug_start; inpidx < debug_end; inpidx++) {
duke@0 482 // Do not split monitors; they are only needed for debug table
duke@0 483 // entries and need no code.
duke@0 484 if( jvms->is_monitor_use(inpidx) ) continue;
duke@0 485 Node *inp = n->in(inpidx);
duke@0 486 uint nidx = _phc.n2lidx(inp);
duke@0 487 LRG &lrg = lrgs(nidx);
duke@0 488
duke@0 489 // If this lrg has a high frequency use/def
duke@0 490 if( lrg._maxfreq >= OPTO_LRG_HIGH_FREQ ) {
duke@0 491 // If the live range is also live out of this block (like it
duke@0 492 // would be for a fast/slow idiom), the normal spill mechanism
duke@0 493 // does an excellent job. If it is not live out of this block
duke@0 494 // (like it would be for debug info to uncommon trap) splitting
duke@0 495 // the live range now allows a better allocation in the high
duke@0 496 // frequency blocks.
duke@0 497 // Build_IFG_virtual has converted the live sets to
duke@0 498 // live-IN info, not live-OUT info.
duke@0 499 uint k;
duke@0 500 for( k=0; k < b->_num_succs; k++ )
duke@0 501 if( _phc._live->live(b->_succs[k])->member( nidx ) )
duke@0 502 break; // Live in to some successor block?
duke@0 503 if( k < b->_num_succs )
duke@0 504 continue; // Live out; do not pre-split
duke@0 505 // Split the lrg at this use
duke@0 506 const RegMask *rm = C->matcher()->idealreg2spillmask[inp->ideal_reg()];
duke@0 507 Node *copy = new (C) MachSpillCopyNode( inp, *rm, *rm );
duke@0 508 // Insert the copy in the use-def chain
duke@0 509 n->set_req(inpidx, copy );
duke@0 510 // Insert the copy in the basic block, just before us
duke@0 511 b->_nodes.insert( l++, copy );
duke@0 512 // Extend ("register allocate") the names array for the copy.
duke@0 513 _phc.new_lrg( copy, _phc._maxlrg++ );
duke@0 514 _phc._cfg._bbs.map( copy->_idx, b );
duke@0 515 //tty->print_cr("Split a debug use in Aggressive Coalesce");
duke@0 516 } // End of if high frequency use/def
duke@0 517 } // End of for all debug inputs
duke@0 518 } // End of if low frequency safepoint
duke@0 519
duke@0 520 } // End of if Phi
duke@0 521
duke@0 522 } // End of for all instructions
duke@0 523 } // End of for all blocks
duke@0 524 }
duke@0 525
duke@0 526 //=============================================================================
duke@0 527 //------------------------------coalesce---------------------------------------
duke@0 528 // Aggressive (but pessimistic) copy coalescing of a single block
duke@0 529
duke@0 530 // The following coalesce pass represents a single round of aggressive
duke@0 531 // pessimistic coalesce. "Aggressive" means no attempt to preserve
duke@0 532 // colorability when coalescing. This occasionally means more spills, but
duke@0 533 // it also means fewer rounds of coalescing for better code - and that means
duke@0 534 // faster compiles.
duke@0 535
duke@0 536 // "Pessimistic" means we do not hit the fixed point in one pass (and we are
duke@0 537 // reaching for the least fixed point to boot). This is typically solved
duke@0 538 // with a few more rounds of coalescing, but the compiler must run fast. We
duke@0 539 // could optimistically coalescing everything touching PhiNodes together
duke@0 540 // into one big live range, then check for self-interference. Everywhere
duke@0 541 // the live range interferes with self it would have to be split. Finding
duke@0 542 // the right split points can be done with some heuristics (based on
duke@0 543 // expected frequency of edges in the live range). In short, it's a real
duke@0 544 // research problem and the timeline is too short to allow such research.
duke@0 545 // Further thoughts: (1) build the LR in a pass, (2) find self-interference
duke@0 546 // in another pass, (3) per each self-conflict, split, (4) split by finding
duke@0 547 // the low-cost cut (min-cut) of the LR, (5) edges in the LR are weighted
duke@0 548 // according to the GCM algorithm (or just exec freq on CFG edges).
duke@0 549
duke@0 550 void PhaseAggressiveCoalesce::coalesce( Block *b ) {
duke@0 551 // Copies are still "virtual" - meaning we have not made them explicitly
duke@0 552 // copies. Instead, Phi functions of successor blocks have mis-matched
duke@0 553 // live-ranges. If I fail to coalesce, I'll have to insert a copy to line
duke@0 554 // up the live-ranges. Check for Phis in successor blocks.
duke@0 555 uint i;
duke@0 556 for( i=0; i<b->_num_succs; i++ ) {
duke@0 557 Block *bs = b->_succs[i];
duke@0 558 // Find index of 'b' in 'bs' predecessors
duke@0 559 uint j=1;
duke@0 560 while( _phc._cfg._bbs[bs->pred(j)->_idx] != b ) j++;
duke@0 561 // Visit all the Phis in successor block
duke@0 562 for( uint k = 1; k<bs->_nodes.size(); k++ ) {
duke@0 563 Node *n = bs->_nodes[k];
duke@0 564 if( !n->is_Phi() ) break;
duke@0 565 combine_these_two( n, n->in(j) );
duke@0 566 }
duke@0 567 } // End of for all successor blocks
duke@0 568
duke@0 569
duke@0 570 // Check _this_ block for 2-address instructions and copies.
duke@0 571 uint cnt = b->end_idx();
duke@0 572 for( i = 1; i<cnt; i++ ) {
duke@0 573 Node *n = b->_nodes[i];
duke@0 574 uint idx;
duke@0 575 // 2-address instructions have a virtual Copy matching their input
duke@0 576 // to their output
duke@0 577 if( n->is_Mach() && (idx = n->as_Mach()->two_adr()) ) {
duke@0 578 MachNode *mach = n->as_Mach();
duke@0 579 combine_these_two( mach, mach->in(idx) );
duke@0 580 }
duke@0 581 } // End of for all instructions in block
duke@0 582 }
duke@0 583
duke@0 584 //=============================================================================
duke@0 585 //------------------------------PhaseConservativeCoalesce----------------------
duke@0 586 PhaseConservativeCoalesce::PhaseConservativeCoalesce( PhaseChaitin &chaitin ) : PhaseCoalesce(chaitin) {
duke@0 587 _ulr.initialize(_phc._maxlrg);
duke@0 588 }
duke@0 589
duke@0 590 //------------------------------verify-----------------------------------------
duke@0 591 void PhaseConservativeCoalesce::verify() {
duke@0 592 #ifdef ASSERT
duke@0 593 _phc.set_was_low();
duke@0 594 #endif
duke@0 595 }
duke@0 596
duke@0 597 //------------------------------union_helper-----------------------------------
duke@0 598 void PhaseConservativeCoalesce::union_helper( Node *lr1_node, Node *lr2_node, uint lr1, uint lr2, Node *src_def, Node *dst_copy, Node *src_copy, Block *b, uint bindex ) {
duke@0 599 // Join live ranges. Merge larger into smaller. Union lr2 into lr1 in the
duke@0 600 // union-find tree
duke@0 601 _phc.Union( lr1_node, lr2_node );
duke@0 602
duke@0 603 // Single-def live range ONLY if both live ranges are single-def.
duke@0 604 // If both are single def, then src_def powers one live range
duke@0 605 // and def_copy powers the other. After merging, src_def powers
duke@0 606 // the combined live range.
duke@0 607 lrgs(lr1)._def = (lrgs(lr1)._def == NodeSentinel ||
duke@0 608 lrgs(lr2)._def == NodeSentinel )
duke@0 609 ? NodeSentinel : src_def;
duke@0 610 lrgs(lr2)._def = NULL; // No def for lrg 2
duke@0 611 lrgs(lr2).Clear(); // Force empty mask for LRG 2
duke@0 612 //lrgs(lr2)._size = 0; // Live-range 2 goes dead
duke@0 613 lrgs(lr1)._is_oop |= lrgs(lr2)._is_oop;
duke@0 614 lrgs(lr2)._is_oop = 0; // In particular, not an oop for GC info
duke@0 615
duke@0 616 if (lrgs(lr1)._maxfreq < lrgs(lr2)._maxfreq)
duke@0 617 lrgs(lr1)._maxfreq = lrgs(lr2)._maxfreq;
duke@0 618
duke@0 619 // Copy original value instead. Intermediate copies go dead, and
duke@0 620 // the dst_copy becomes useless.
duke@0 621 int didx = dst_copy->is_Copy();
duke@0 622 dst_copy->set_req( didx, src_def );
duke@0 623 // Add copy to free list
duke@0 624 // _phc.free_spillcopy(b->_nodes[bindex]);
duke@0 625 assert( b->_nodes[bindex] == dst_copy, "" );
duke@0 626 dst_copy->replace_by( dst_copy->in(didx) );
duke@0 627 dst_copy->set_req( didx, NULL);
duke@0 628 b->_nodes.remove(bindex);
duke@0 629 if( bindex < b->_ihrp_index ) b->_ihrp_index--;
duke@0 630 if( bindex < b->_fhrp_index ) b->_fhrp_index--;
duke@0 631
duke@0 632 // Stretched lr1; add it to liveness of intermediate blocks
duke@0 633 Block *b2 = _phc._cfg._bbs[src_copy->_idx];
duke@0 634 while( b != b2 ) {
duke@0 635 b = _phc._cfg._bbs[b->pred(1)->_idx];
duke@0 636 _phc._live->live(b)->insert(lr1);
duke@0 637 }
duke@0 638 }
duke@0 639
duke@0 640 //------------------------------compute_separating_interferences---------------
duke@0 641 // Factored code from copy_copy that computes extra interferences from
duke@0 642 // lengthening a live range by double-coalescing.
duke@0 643 uint PhaseConservativeCoalesce::compute_separating_interferences(Node *dst_copy, Node *src_copy, Block *b, uint bindex, RegMask &rm, uint reg_degree, uint rm_size, uint lr1, uint lr2 ) {
duke@0 644
duke@0 645 assert(!lrgs(lr1)._fat_proj, "cannot coalesce fat_proj");
duke@0 646 assert(!lrgs(lr2)._fat_proj, "cannot coalesce fat_proj");
duke@0 647 Node *prev_copy = dst_copy->in(dst_copy->is_Copy());
duke@0 648 Block *b2 = b;
duke@0 649 uint bindex2 = bindex;
duke@0 650 while( 1 ) {
duke@0 651 // Find previous instruction
duke@0 652 bindex2--; // Chain backwards 1 instruction
duke@0 653 while( bindex2 == 0 ) { // At block start, find prior block
duke@0 654 assert( b2->num_preds() == 2, "cannot double coalesce across c-flow" );
duke@0 655 b2 = _phc._cfg._bbs[b2->pred(1)->_idx];
duke@0 656 bindex2 = b2->end_idx()-1;
duke@0 657 }
duke@0 658 // Get prior instruction
duke@0 659 assert(bindex2 < b2->_nodes.size(), "index out of bounds");
duke@0 660 Node *x = b2->_nodes[bindex2];
duke@0 661 if( x == prev_copy ) { // Previous copy in copy chain?
duke@0 662 if( prev_copy == src_copy)// Found end of chain and all interferences
duke@0 663 break; // So break out of loop
duke@0 664 // Else work back one in copy chain
duke@0 665 prev_copy = prev_copy->in(prev_copy->is_Copy());
duke@0 666 } else { // Else collect interferences
duke@0 667 uint lidx = _phc.Find(x);
duke@0 668 // Found another def of live-range being stretched?
duke@0 669 if( lidx == lr1 ) return max_juint;
duke@0 670 if( lidx == lr2 ) return max_juint;
duke@0 671
duke@0 672 // If we attempt to coalesce across a bound def
duke@0 673 if( lrgs(lidx).is_bound() ) {
duke@0 674 // Do not let the coalesced LRG expect to get the bound color
duke@0 675 rm.SUBTRACT( lrgs(lidx).mask() );
duke@0 676 // Recompute rm_size
duke@0 677 rm_size = rm.Size();
duke@0 678 //if( rm._flags ) rm_size += 1000000;
duke@0 679 if( reg_degree >= rm_size ) return max_juint;
duke@0 680 }
duke@0 681 if( rm.overlap(lrgs(lidx).mask()) ) {
duke@0 682 // Insert lidx into union LRG; returns TRUE if actually inserted
duke@0 683 if( _ulr.insert(lidx) ) {
duke@0 684 // Infinite-stack neighbors do not alter colorability, as they
duke@0 685 // can always color to some other color.
duke@0 686 if( !lrgs(lidx).mask().is_AllStack() ) {
duke@0 687 // If this coalesce will make any new neighbor uncolorable,
duke@0 688 // do not coalesce.
duke@0 689 if( lrgs(lidx).just_lo_degree() )
duke@0 690 return max_juint;
duke@0 691 // Bump our degree
duke@0 692 if( ++reg_degree >= rm_size )
duke@0 693 return max_juint;
duke@0 694 } // End of if not infinite-stack neighbor
duke@0 695 } // End of if actually inserted
duke@0 696 } // End of if live range overlaps
duke@0 697 } // End of else collect intereferences for 1 node
duke@0 698 } // End of while forever, scan back for intereferences
duke@0 699 return reg_degree;
duke@0 700 }
duke@0 701
duke@0 702 //------------------------------update_ifg-------------------------------------
duke@0 703 void PhaseConservativeCoalesce::update_ifg(uint lr1, uint lr2, IndexSet *n_lr1, IndexSet *n_lr2) {
duke@0 704 // Some original neighbors of lr1 might have gone away
duke@0 705 // because the constrained register mask prevented them.
duke@0 706 // Remove lr1 from such neighbors.
duke@0 707 IndexSetIterator one(n_lr1);
duke@0 708 uint neighbor;
duke@0 709 LRG &lrg1 = lrgs(lr1);
duke@0 710 while ((neighbor = one.next()) != 0)
duke@0 711 if( !_ulr.member(neighbor) )
duke@0 712 if( _phc._ifg->neighbors(neighbor)->remove(lr1) )
duke@0 713 lrgs(neighbor).inc_degree( -lrg1.compute_degree(lrgs(neighbor)) );
duke@0 714
duke@0 715
duke@0 716 // lr2 is now called (coalesced into) lr1.
duke@0 717 // Remove lr2 from the IFG.
duke@0 718 IndexSetIterator two(n_lr2);
duke@0 719 LRG &lrg2 = lrgs(lr2);
duke@0 720 while ((neighbor = two.next()) != 0)
duke@0 721 if( _phc._ifg->neighbors(neighbor)->remove(lr2) )
duke@0 722 lrgs(neighbor).inc_degree( -lrg2.compute_degree(lrgs(neighbor)) );
duke@0 723
duke@0 724 // Some neighbors of intermediate copies now interfere with the
duke@0 725 // combined live range.
duke@0 726 IndexSetIterator three(&_ulr);
duke@0 727 while ((neighbor = three.next()) != 0)
duke@0 728 if( _phc._ifg->neighbors(neighbor)->insert(lr1) )
duke@0 729 lrgs(neighbor).inc_degree( lrg1.compute_degree(lrgs(neighbor)) );
duke@0 730 }
duke@0 731
duke@0 732 //------------------------------record_bias------------------------------------
duke@0 733 static void record_bias( const PhaseIFG *ifg, int lr1, int lr2 ) {
duke@0 734 // Tag copy bias here
duke@0 735 if( !ifg->lrgs(lr1)._copy_bias )
duke@0 736 ifg->lrgs(lr1)._copy_bias = lr2;
duke@0 737 if( !ifg->lrgs(lr2)._copy_bias )
duke@0 738 ifg->lrgs(lr2)._copy_bias = lr1;
duke@0 739 }
duke@0 740
duke@0 741 //------------------------------copy_copy--------------------------------------
duke@0 742 // See if I can coalesce a series of multiple copies together. I need the
duke@0 743 // final dest copy and the original src copy. They can be the same Node.
duke@0 744 // Compute the compatible register masks.
duke@0 745 bool PhaseConservativeCoalesce::copy_copy( Node *dst_copy, Node *src_copy, Block *b, uint bindex ) {
duke@0 746
duke@0 747 if( !dst_copy->is_SpillCopy() ) return false;
duke@0 748 if( !src_copy->is_SpillCopy() ) return false;
duke@0 749 Node *src_def = src_copy->in(src_copy->is_Copy());
duke@0 750 uint lr1 = _phc.Find(dst_copy);
duke@0 751 uint lr2 = _phc.Find(src_def );
duke@0 752
duke@0 753 // Same live ranges already?
duke@0 754 if( lr1 == lr2 ) return false;
duke@0 755
duke@0 756 // Interfere?
duke@0 757 if( _phc._ifg->test_edge_sq( lr1, lr2 ) ) return false;
duke@0 758
duke@0 759 // Not an oop->int cast; oop->oop, int->int, AND int->oop are OK.
duke@0 760 if( !lrgs(lr1)._is_oop && lrgs(lr2)._is_oop ) // not an oop->int cast
duke@0 761 return false;
duke@0 762
duke@0 763 // Coalescing between an aligned live range and a mis-aligned live range?
duke@0 764 // No, no! Alignment changes how we count degree.
duke@0 765 if( lrgs(lr1)._fat_proj != lrgs(lr2)._fat_proj )
duke@0 766 return false;
duke@0 767
duke@0 768 // Sort; use smaller live-range number
duke@0 769 Node *lr1_node = dst_copy;
duke@0 770 Node *lr2_node = src_def;
duke@0 771 if( lr1 > lr2 ) {
duke@0 772 uint tmp = lr1; lr1 = lr2; lr2 = tmp;
duke@0 773 lr1_node = src_def; lr2_node = dst_copy;
duke@0 774 }
duke@0 775
duke@0 776 // Check for compatibility of the 2 live ranges by
duke@0 777 // intersecting their allowed register sets.
duke@0 778 RegMask rm = lrgs(lr1).mask();
duke@0 779 rm.AND(lrgs(lr2).mask());
duke@0 780 // Number of bits free
duke@0 781 uint rm_size = rm.Size();
duke@0 782
duke@0 783 // If we can use any stack slot, then effective size is infinite
duke@0 784 if( rm.is_AllStack() ) rm_size += 1000000;
duke@0 785 // Incompatible masks, no way to coalesce
duke@0 786 if( rm_size == 0 ) return false;
duke@0 787
duke@0 788 // Another early bail-out test is when we are double-coalescing and the
duke@0 789 // 2 copies are seperated by some control flow.
duke@0 790 if( dst_copy != src_copy ) {
duke@0 791 Block *src_b = _phc._cfg._bbs[src_copy->_idx];
duke@0 792 Block *b2 = b;
duke@0 793 while( b2 != src_b ) {
duke@0 794 if( b2->num_preds() > 2 ){// Found merge-point
duke@0 795 _phc._lost_opp_cflow_coalesce++;
duke@0 796 // extra record_bias commented out because Chris believes it is not
duke@0 797 // productive. Since we can record only 1 bias, we want to choose one
duke@0 798 // that stands a chance of working and this one probably does not.
duke@0 799 //record_bias( _phc._lrgs, lr1, lr2 );
duke@0 800 return false; // To hard to find all interferences
duke@0 801 }
duke@0 802 b2 = _phc._cfg._bbs[b2->pred(1)->_idx];
duke@0 803 }
duke@0 804 }
duke@0 805
duke@0 806 // Union the two interference sets together into '_ulr'
duke@0 807 uint reg_degree = _ulr.lrg_union( lr1, lr2, rm_size, _phc._ifg, rm );
duke@0 808
duke@0 809 if( reg_degree >= rm_size ) {
duke@0 810 record_bias( _phc._ifg, lr1, lr2 );
duke@0 811 return false;
duke@0 812 }
duke@0 813
duke@0 814 // Now I need to compute all the interferences between dst_copy and
duke@0 815 // src_copy. I'm not willing visit the entire interference graph, so
duke@0 816 // I limit my search to things in dst_copy's block or in a straight
duke@0 817 // line of previous blocks. I give up at merge points or when I get
duke@0 818 // more interferences than my degree. I can stop when I find src_copy.
duke@0 819 if( dst_copy != src_copy ) {
duke@0 820 reg_degree = compute_separating_interferences(dst_copy, src_copy, b, bindex, rm, rm_size, reg_degree, lr1, lr2 );
duke@0 821 if( reg_degree == max_juint ) {
duke@0 822 record_bias( _phc._ifg, lr1, lr2 );
duke@0 823 return false;
duke@0 824 }
duke@0 825 } // End of if dst_copy & src_copy are different
duke@0 826
duke@0 827
duke@0 828 // ---- THE COMBINED LRG IS COLORABLE ----
duke@0 829
duke@0 830 // YEAH - Now coalesce this copy away
duke@0 831 assert( lrgs(lr1).num_regs() == lrgs(lr2).num_regs(), "" );
duke@0 832
duke@0 833 IndexSet *n_lr1 = _phc._ifg->neighbors(lr1);
duke@0 834 IndexSet *n_lr2 = _phc._ifg->neighbors(lr2);
duke@0 835
duke@0 836 // Update the interference graph
duke@0 837 update_ifg(lr1, lr2, n_lr1, n_lr2);
duke@0 838
duke@0 839 _ulr.remove(lr1);
duke@0 840
duke@0 841 // Uncomment the following code to trace Coalescing in great detail.
duke@0 842 //
duke@0 843 //if (false) {
duke@0 844 // tty->cr();
duke@0 845 // tty->print_cr("#######################################");
duke@0 846 // tty->print_cr("union %d and %d", lr1, lr2);
duke@0 847 // n_lr1->dump();
duke@0 848 // n_lr2->dump();
duke@0 849 // tty->print_cr("resulting set is");
duke@0 850 // _ulr.dump();
duke@0 851 //}
duke@0 852
duke@0 853 // Replace n_lr1 with the new combined live range. _ulr will use
duke@0 854 // n_lr1's old memory on the next iteration. n_lr2 is cleared to
duke@0 855 // send its internal memory to the free list.
duke@0 856 _ulr.swap(n_lr1);
duke@0 857 _ulr.clear();
duke@0 858 n_lr2->clear();
duke@0 859
duke@0 860 lrgs(lr1).set_degree( _phc._ifg->effective_degree(lr1) );
duke@0 861 lrgs(lr2).set_degree( 0 );
duke@0 862
duke@0 863 // Join live ranges. Merge larger into smaller. Union lr2 into lr1 in the
duke@0 864 // union-find tree
duke@0 865 union_helper( lr1_node, lr2_node, lr1, lr2, src_def, dst_copy, src_copy, b, bindex );
duke@0 866 // Combine register restrictions
duke@0 867 lrgs(lr1).set_mask(rm);
duke@0 868 lrgs(lr1).compute_set_mask_size();
duke@0 869 lrgs(lr1)._cost += lrgs(lr2)._cost;
duke@0 870 lrgs(lr1)._area += lrgs(lr2)._area;
duke@0 871
duke@0 872 // While its uncommon to successfully coalesce live ranges that started out
duke@0 873 // being not-lo-degree, it can happen. In any case the combined coalesced
duke@0 874 // live range better Simplify nicely.
duke@0 875 lrgs(lr1)._was_lo = 1;
duke@0 876
duke@0 877 // kinda expensive to do all the time
duke@0 878 //tty->print_cr("warning: slow verify happening");
duke@0 879 //_phc._ifg->verify( &_phc );
duke@0 880 return true;
duke@0 881 }
duke@0 882
duke@0 883 //------------------------------coalesce---------------------------------------
duke@0 884 // Conservative (but pessimistic) copy coalescing of a single block
duke@0 885 void PhaseConservativeCoalesce::coalesce( Block *b ) {
duke@0 886 // Bail out on infrequent blocks
duke@0 887 if( b->is_uncommon(_phc._cfg._bbs) )
duke@0 888 return;
duke@0 889 // Check this block for copies.
duke@0 890 for( uint i = 1; i<b->end_idx(); i++ ) {
duke@0 891 // Check for actual copies on inputs. Coalesce a copy into its
duke@0 892 // input if use and copy's input are compatible.
duke@0 893 Node *copy1 = b->_nodes[i];
duke@0 894 uint idx1 = copy1->is_Copy();
duke@0 895 if( !idx1 ) continue; // Not a copy
duke@0 896
duke@0 897 if( copy_copy(copy1,copy1,b,i) ) {
duke@0 898 i--; // Retry, same location in block
duke@0 899 PhaseChaitin::_conserv_coalesce++; // Collect stats on success
duke@0 900 continue;
duke@0 901 }
duke@0 902
duke@0 903 /* do not attempt pairs. About 1/2 of all pairs can be removed by
duke@0 904 post-alloc. The other set are too few to bother.
duke@0 905 Node *copy2 = copy1->in(idx1);
duke@0 906 uint idx2 = copy2->is_Copy();
duke@0 907 if( !idx2 ) continue;
duke@0 908 if( copy_copy(copy1,copy2,b,i) ) {
duke@0 909 i--; // Retry, same location in block
duke@0 910 PhaseChaitin::_conserv_coalesce_pair++; // Collect stats on success
duke@0 911 continue;
duke@0 912 }
duke@0 913 */
duke@0 914 }
duke@0 915 }