comparison src/share/vm/opto/chaitin.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 693e4d04fd09
comparison
equal deleted inserted replaced
10109:1c6887c9afaa 10111:8373c19be854
143 _lidxs[nidx] = lidx; 143 _lidxs[nidx] = lidx;
144 } 144 }
145 145
146 #define NUMBUCKS 3 146 #define NUMBUCKS 3
147 147
148 // Straight out of Tarjan's union-find algorithm
149 uint LiveRangeMap::find_compress(uint lrg) {
150 uint cur = lrg;
151 uint next = _uf_map[cur];
152 while (next != cur) { // Scan chain of equivalences
153 assert( next < cur, "always union smaller");
154 cur = next; // until find a fixed-point
155 next = _uf_map[cur];
156 }
157
158 // Core of union-find algorithm: update chain of
159 // equivalences to be equal to the root.
160 while (lrg != next) {
161 uint tmp = _uf_map[lrg];
162 _uf_map.map(lrg, next);
163 lrg = tmp;
164 }
165 return lrg;
166 }
167
168 // Reset the Union-Find map to identity
169 void LiveRangeMap::reset_uf_map(uint max_lrg_id) {
170 _max_lrg_id= max_lrg_id;
171 // Force the Union-Find mapping to be at least this large
172 _uf_map.extend(_max_lrg_id, 0);
173 // Initialize it to be the ID mapping.
174 for (uint i = 0; i < _max_lrg_id; ++i) {
175 _uf_map.map(i, i);
176 }
177 }
178
179 // Make all Nodes map directly to their final live range; no need for
180 // the Union-Find mapping after this call.
181 void LiveRangeMap::compress_uf_map_for_nodes() {
182 // For all Nodes, compress mapping
183 uint unique = _names.Size();
184 for (uint i = 0; i < unique; ++i) {
185 uint lrg = _names[i];
186 uint compressed_lrg = find(lrg);
187 if (lrg != compressed_lrg) {
188 _names.map(i, compressed_lrg);
189 }
190 }
191 }
192
193 // Like Find above, but no path compress, so bad asymptotic behavior
194 uint LiveRangeMap::find_const(uint lrg) const {
195 if (!lrg) {
196 return lrg; // Ignore the zero LRG
197 }
198
199 // Off the end? This happens during debugging dumps when you got
200 // brand new live ranges but have not told the allocator yet.
201 if (lrg >= _max_lrg_id) {
202 return lrg;
203 }
204
205 uint next = _uf_map[lrg];
206 while (next != lrg) { // Scan chain of equivalences
207 assert(next < lrg, "always union smaller");
208 lrg = next; // until find a fixed-point
209 next = _uf_map[lrg];
210 }
211 return next;
212 }
213
148 //------------------------------Chaitin---------------------------------------- 214 //------------------------------Chaitin----------------------------------------
149 PhaseChaitin::PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher) 215 PhaseChaitin::PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher)
150 : PhaseRegAlloc(unique, cfg, matcher, 216 : PhaseRegAlloc(unique, cfg, matcher,
151 #ifndef PRODUCT 217 #ifndef PRODUCT
152 print_chaitin_statistics 218 print_chaitin_statistics
153 #else 219 #else
154 NULL 220 NULL
155 #endif 221 #endif
156 ), 222 )
157 _names(unique), _uf_map(unique), 223 , _lrg_map(unique)
158 _maxlrg(0), _live(0), 224 , _live(0)
159 _spilled_once(Thread::current()->resource_area()), 225 , _spilled_once(Thread::current()->resource_area())
160 _spilled_twice(Thread::current()->resource_area()), 226 , _spilled_twice(Thread::current()->resource_area())
161 _lo_degree(0), _lo_stk_degree(0), _hi_degree(0), _simplified(0), 227 , _lo_degree(0), _lo_stk_degree(0), _hi_degree(0), _simplified(0)
162 _oldphi(unique) 228 , _oldphi(unique)
163 #ifndef PRODUCT 229 #ifndef PRODUCT
164 , _trace_spilling(TraceSpilling || C->method_has_option("TraceSpilling")) 230 , _trace_spilling(TraceSpilling || C->method_has_option("TraceSpilling"))
165 #endif 231 #endif
166 { 232 {
167 NOT_PRODUCT( Compile::TracePhase t3("ctorChaitin", &_t_ctorChaitin, TimeCompiler); ) 233 NOT_PRODUCT( Compile::TracePhase t3("ctorChaitin", &_t_ctorChaitin, TimeCompiler); )
168 234
169 _high_frequency_lrg = MIN2(float(OPTO_LRG_HIGH_FREQ), _cfg._outer_loop_freq); 235 _high_frequency_lrg = MIN2(float(OPTO_LRG_HIGH_FREQ), _cfg._outer_loop_freq);
170 236
171 uint i,j;
172 // Build a list of basic blocks, sorted by frequency 237 // Build a list of basic blocks, sorted by frequency
173 _blks = NEW_RESOURCE_ARRAY( Block *, _cfg._num_blocks ); 238 _blks = NEW_RESOURCE_ARRAY( Block *, _cfg._num_blocks );
174 // Experiment with sorting strategies to speed compilation 239 // Experiment with sorting strategies to speed compilation
175 double cutoff = BLOCK_FREQUENCY(1.0); // Cutoff for high frequency bucket 240 double cutoff = BLOCK_FREQUENCY(1.0); // Cutoff for high frequency bucket
176 Block **buckets[NUMBUCKS]; // Array of buckets 241 Block **buckets[NUMBUCKS]; // Array of buckets
177 uint buckcnt[NUMBUCKS]; // Array of bucket counters 242 uint buckcnt[NUMBUCKS]; // Array of bucket counters
178 double buckval[NUMBUCKS]; // Array of bucket value cutoffs 243 double buckval[NUMBUCKS]; // Array of bucket value cutoffs
179 for( i = 0; i < NUMBUCKS; i++ ) { 244 for (uint i = 0; i < NUMBUCKS; i++) {
180 buckets[i] = NEW_RESOURCE_ARRAY( Block *, _cfg._num_blocks ); 245 buckets[i] = NEW_RESOURCE_ARRAY(Block *, _cfg._num_blocks);
181 buckcnt[i] = 0; 246 buckcnt[i] = 0;
182 // Bump by three orders of magnitude each time 247 // Bump by three orders of magnitude each time
183 cutoff *= 0.001; 248 cutoff *= 0.001;
184 buckval[i] = cutoff; 249 buckval[i] = cutoff;
185 for( j = 0; j < _cfg._num_blocks; j++ ) { 250 for (uint j = 0; j < _cfg._num_blocks; j++) {
186 buckets[i][j] = NULL; 251 buckets[i][j] = NULL;
187 } 252 }
188 } 253 }
189 // Sort blocks into buckets 254 // Sort blocks into buckets
190 for( i = 0; i < _cfg._num_blocks; i++ ) { 255 for (uint i = 0; i < _cfg._num_blocks; i++) {
191 for( j = 0; j < NUMBUCKS; j++ ) { 256 for (uint j = 0; j < NUMBUCKS; j++) {
192 if( (j == NUMBUCKS-1) || (_cfg._blocks[i]->_freq > buckval[j]) ) { 257 if ((j == NUMBUCKS - 1) || (_cfg._blocks[i]->_freq > buckval[j])) {
193 // Assign block to end of list for appropriate bucket 258 // Assign block to end of list for appropriate bucket
194 buckets[j][buckcnt[j]++] = _cfg._blocks[i]; 259 buckets[j][buckcnt[j]++] = _cfg._blocks[i];
195 break; // kick out of inner loop 260 break; // kick out of inner loop
196 } 261 }
197 } 262 }
198 } 263 }
199 // Dump buckets into final block array 264 // Dump buckets into final block array
200 uint blkcnt = 0; 265 uint blkcnt = 0;
201 for( i = 0; i < NUMBUCKS; i++ ) { 266 for (uint i = 0; i < NUMBUCKS; i++) {
202 for( j = 0; j < buckcnt[i]; j++ ) { 267 for (uint j = 0; j < buckcnt[i]; j++) {
203 _blks[blkcnt++] = buckets[i][j]; 268 _blks[blkcnt++] = buckets[i][j];
204 } 269 }
205 } 270 }
206 271
207 assert(blkcnt == _cfg._num_blocks, "Block array not totally filled"); 272 assert(blkcnt == _cfg._num_blocks, "Block array not totally filled");
273 }
274
275 //------------------------------Union------------------------------------------
276 // union 2 sets together.
277 void PhaseChaitin::Union( const Node *src_n, const Node *dst_n ) {
278 uint src = _lrg_map.find(src_n);
279 uint dst = _lrg_map.find(dst_n);
280 assert(src, "");
281 assert(dst, "");
282 assert(src < _lrg_map.max_lrg_id(), "oob");
283 assert(dst < _lrg_map.max_lrg_id(), "oob");
284 assert(src < dst, "always union smaller");
285 _lrg_map.uf_map(dst, src);
286 }
287
288 //------------------------------new_lrg----------------------------------------
289 void PhaseChaitin::new_lrg(const Node *x, uint lrg) {
290 // Make the Node->LRG mapping
291 _lrg_map.extend(x->_idx,lrg);
292 // Make the Union-Find mapping an identity function
293 _lrg_map.uf_extend(lrg, lrg);
294 }
295
296
297 bool PhaseChaitin::clone_projs_shared(Block *b, uint idx, Node *con, Node *copy, uint max_lrg_id) {
298 Block *bcon = _cfg._bbs[con->_idx];
299 uint cindex = bcon->find_node(con);
300 Node *con_next = bcon->_nodes[cindex+1];
301 if (con_next->in(0) != con || !con_next->is_MachProj()) {
302 return false; // No MachProj's follow
303 }
304
305 // Copy kills after the cloned constant
306 Node *kills = con_next->clone();
307 kills->set_req(0, copy);
308 b->_nodes.insert(idx, kills);
309 _cfg._bbs.map(kills->_idx, b);
310 new_lrg(kills, max_lrg_id);
311 return true;
312 }
313
314 //------------------------------compact----------------------------------------
315 // Renumber the live ranges to compact them. Makes the IFG smaller.
316 void PhaseChaitin::compact() {
317 // Current the _uf_map contains a series of short chains which are headed
318 // by a self-cycle. All the chains run from big numbers to little numbers.
319 // The Find() call chases the chains & shortens them for the next Find call.
320 // We are going to change this structure slightly. Numbers above a moving
321 // wave 'i' are unchanged. Numbers below 'j' point directly to their
322 // compacted live range with no further chaining. There are no chains or
323 // cycles below 'i', so the Find call no longer works.
324 uint j=1;
325 uint i;
326 for (i = 1; i < _lrg_map.max_lrg_id(); i++) {
327 uint lr = _lrg_map.uf_live_range_id(i);
328 // Ignore unallocated live ranges
329 if (!lr) {
330 continue;
331 }
332 assert(lr <= i, "");
333 _lrg_map.uf_map(i, ( lr == i ) ? j++ : _lrg_map.uf_live_range_id(lr));
334 }
335 // Now change the Node->LR mapping to reflect the compacted names
336 uint unique = _lrg_map.size();
337 for (i = 0; i < unique; i++) {
338 uint lrg_id = _lrg_map.live_range_id(i);
339 _lrg_map.map(i, _lrg_map.uf_live_range_id(lrg_id));
340 }
341
342 // Reset the Union-Find mapping
343 _lrg_map.reset_uf_map(j);
208 } 344 }
209 345
210 void PhaseChaitin::Register_Allocate() { 346 void PhaseChaitin::Register_Allocate() {
211 347
212 // Above the OLD FP (and in registers) are the incoming arguments. Stack 348 // Above the OLD FP (and in registers) are the incoming arguments. Stack
229 // Need live-ness for the IFG; need the IFG for coalescing. If the 365 // Need live-ness for the IFG; need the IFG for coalescing. If the
230 // liveness is JUST for coalescing, then I can get some mileage by renaming 366 // liveness is JUST for coalescing, then I can get some mileage by renaming
231 // all copy-related live ranges low and then using the max copy-related 367 // all copy-related live ranges low and then using the max copy-related
232 // live range as a cut-off for LIVE and the IFG. In other words, I can 368 // live range as a cut-off for LIVE and the IFG. In other words, I can
233 // build a subset of LIVE and IFG just for copies. 369 // build a subset of LIVE and IFG just for copies.
234 PhaseLive live(_cfg,_names,&live_arena); 370 PhaseLive live(_cfg, _lrg_map.names(), &live_arena);
235 371
236 // Need IFG for coalescing and coloring 372 // Need IFG for coalescing and coloring
237 PhaseIFG ifg( &live_arena ); 373 PhaseIFG ifg(&live_arena);
238 _ifg = &ifg; 374 _ifg = &ifg;
239
240 if (C->unique() > _names.Size()) _names.extend(C->unique()-1, 0);
241 375
242 // Come out of SSA world to the Named world. Assign (virtual) registers to 376 // Come out of SSA world to the Named world. Assign (virtual) registers to
243 // Nodes. Use the same register for all inputs and the output of PhiNodes 377 // Nodes. Use the same register for all inputs and the output of PhiNodes
244 // - effectively ending SSA form. This requires either coalescing live 378 // - effectively ending SSA form. This requires either coalescing live
245 // ranges or inserting copies. For the moment, we insert "virtual copies" 379 // ranges or inserting copies. For the moment, we insert "virtual copies"
256 { 390 {
257 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) 391 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
258 _live = NULL; // Mark live as being not available 392 _live = NULL; // Mark live as being not available
259 rm.reset_to_mark(); // Reclaim working storage 393 rm.reset_to_mark(); // Reclaim working storage
260 IndexSet::reset_memory(C, &live_arena); 394 IndexSet::reset_memory(C, &live_arena);
261 ifg.init(_maxlrg); // Empty IFG 395 ifg.init(_lrg_map.max_lrg_id()); // Empty IFG
262 gather_lrg_masks( false ); // Collect LRG masks 396 gather_lrg_masks( false ); // Collect LRG masks
263 live.compute( _maxlrg ); // Compute liveness 397 live.compute(_lrg_map.max_lrg_id()); // Compute liveness
264 _live = &live; // Mark LIVE as being available 398 _live = &live; // Mark LIVE as being available
265 } 399 }
266 400
267 // Base pointers are currently "used" by instructions which define new 401 // Base pointers are currently "used" by instructions which define new
268 // derived pointers. This makes base pointers live up to the where the 402 // derived pointers. This makes base pointers live up to the where the
269 // derived pointer is made, but not beyond. Really, they need to be live 403 // derived pointer is made, but not beyond. Really, they need to be live
270 // across any GC point where the derived value is live. So this code looks 404 // across any GC point where the derived value is live. So this code looks
271 // at all the GC points, and "stretches" the live range of any base pointer 405 // at all the GC points, and "stretches" the live range of any base pointer
272 // to the GC point. 406 // to the GC point.
273 if( stretch_base_pointer_live_ranges(&live_arena) ) { 407 if (stretch_base_pointer_live_ranges(&live_arena)) {
274 NOT_PRODUCT( Compile::TracePhase t3("computeLive (sbplr)", &_t_computeLive, TimeCompiler); ) 408 NOT_PRODUCT(Compile::TracePhase t3("computeLive (sbplr)", &_t_computeLive, TimeCompiler);)
275 // Since some live range stretched, I need to recompute live 409 // Since some live range stretched, I need to recompute live
276 _live = NULL; 410 _live = NULL;
277 rm.reset_to_mark(); // Reclaim working storage 411 rm.reset_to_mark(); // Reclaim working storage
278 IndexSet::reset_memory(C, &live_arena); 412 IndexSet::reset_memory(C, &live_arena);
279 ifg.init(_maxlrg); 413 ifg.init(_lrg_map.max_lrg_id());
280 gather_lrg_masks( false ); 414 gather_lrg_masks(false);
281 live.compute( _maxlrg ); 415 live.compute(_lrg_map.max_lrg_id());
282 _live = &live; 416 _live = &live;
283 } 417 }
284 // Create the interference graph using virtual copies 418 // Create the interference graph using virtual copies
285 build_ifg_virtual( ); // Include stack slots this time 419 build_ifg_virtual(); // Include stack slots this time
286 420
287 // Aggressive (but pessimistic) copy coalescing. 421 // Aggressive (but pessimistic) copy coalescing.
288 // This pass works on virtual copies. Any virtual copies which are not 422 // This pass works on virtual copies. Any virtual copies which are not
289 // coalesced get manifested as actual copies 423 // coalesced get manifested as actual copies
290 { 424 {
294 // meaning I can visit all the Nodes neighbors less than a Node in time 428 // meaning I can visit all the Nodes neighbors less than a Node in time
295 // O(# of neighbors), but I have to visit all the Nodes greater than a 429 // O(# of neighbors), but I have to visit all the Nodes greater than a
296 // given Node and search them for an instance, i.e., time O(#MaxLRG)). 430 // given Node and search them for an instance, i.e., time O(#MaxLRG)).
297 _ifg->SquareUp(); 431 _ifg->SquareUp();
298 432
299 PhaseAggressiveCoalesce coalesce( *this ); 433 PhaseAggressiveCoalesce coalesce(*this);
300 coalesce.coalesce_driver( ); 434 coalesce.coalesce_driver();
301 // Insert un-coalesced copies. Visit all Phis. Where inputs to a Phi do 435 // Insert un-coalesced copies. Visit all Phis. Where inputs to a Phi do
302 // not match the Phi itself, insert a copy. 436 // not match the Phi itself, insert a copy.
303 coalesce.insert_copies(_matcher); 437 coalesce.insert_copies(_matcher);
304 } 438 }
305 439
308 { 442 {
309 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) 443 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
310 _live = NULL; 444 _live = NULL;
311 rm.reset_to_mark(); // Reclaim working storage 445 rm.reset_to_mark(); // Reclaim working storage
312 IndexSet::reset_memory(C, &live_arena); 446 IndexSet::reset_memory(C, &live_arena);
313 ifg.init(_maxlrg); 447 ifg.init(_lrg_map.max_lrg_id());
314 gather_lrg_masks( true ); 448 gather_lrg_masks( true );
315 live.compute( _maxlrg ); 449 live.compute(_lrg_map.max_lrg_id());
316 _live = &live; 450 _live = &live;
317 } 451 }
318 452
319 // Build physical interference graph 453 // Build physical interference graph
320 uint must_spill = 0; 454 uint must_spill = 0;
321 must_spill = build_ifg_physical( &live_arena ); 455 must_spill = build_ifg_physical(&live_arena);
322 // If we have a guaranteed spill, might as well spill now 456 // If we have a guaranteed spill, might as well spill now
323 if( must_spill ) { 457 if (must_spill) {
324 if( !_maxlrg ) return; 458 if(!_lrg_map.max_lrg_id()) {
459 return;
460 }
325 // Bail out if unique gets too large (ie - unique > MaxNodeLimit) 461 // Bail out if unique gets too large (ie - unique > MaxNodeLimit)
326 C->check_node_count(10*must_spill, "out of nodes before split"); 462 C->check_node_count(10*must_spill, "out of nodes before split");
327 if (C->failing()) return; 463 if (C->failing()) {
328 _maxlrg = Split(_maxlrg, &split_arena); // Split spilling LRG everywhere 464 return;
465 }
466
467 uint new_max_lrg_id = Split(_lrg_map.max_lrg_id(), &split_arena); // Split spilling LRG everywhere
468 _lrg_map.set_max_lrg_id(new_max_lrg_id);
329 // Bail out if unique gets too large (ie - unique > MaxNodeLimit - 2*NodeLimitFudgeFactor) 469 // Bail out if unique gets too large (ie - unique > MaxNodeLimit - 2*NodeLimitFudgeFactor)
330 // or we failed to split 470 // or we failed to split
331 C->check_node_count(2*NodeLimitFudgeFactor, "out of nodes after physical split"); 471 C->check_node_count(2*NodeLimitFudgeFactor, "out of nodes after physical split");
332 if (C->failing()) return; 472 if (C->failing()) {
333 473 return;
334 NOT_PRODUCT( C->verify_graph_edges(); ) 474 }
475
476 NOT_PRODUCT(C->verify_graph_edges();)
335 477
336 compact(); // Compact LRGs; return new lower max lrg 478 compact(); // Compact LRGs; return new lower max lrg
337 479
338 { 480 {
339 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) 481 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
340 _live = NULL; 482 _live = NULL;
341 rm.reset_to_mark(); // Reclaim working storage 483 rm.reset_to_mark(); // Reclaim working storage
342 IndexSet::reset_memory(C, &live_arena); 484 IndexSet::reset_memory(C, &live_arena);
343 ifg.init(_maxlrg); // Build a new interference graph 485 ifg.init(_lrg_map.max_lrg_id()); // Build a new interference graph
344 gather_lrg_masks( true ); // Collect intersect mask 486 gather_lrg_masks( true ); // Collect intersect mask
345 live.compute( _maxlrg ); // Compute LIVE 487 live.compute(_lrg_map.max_lrg_id()); // Compute LIVE
346 _live = &live; 488 _live = &live;
347 } 489 }
348 build_ifg_physical( &live_arena ); 490 build_ifg_physical(&live_arena);
349 _ifg->SquareUp(); 491 _ifg->SquareUp();
350 _ifg->Compute_Effective_Degree(); 492 _ifg->Compute_Effective_Degree();
351 // Only do conservative coalescing if requested 493 // Only do conservative coalescing if requested
352 if( OptoCoalesce ) { 494 if (OptoCoalesce) {
353 // Conservative (and pessimistic) copy coalescing of those spills 495 // Conservative (and pessimistic) copy coalescing of those spills
354 PhaseConservativeCoalesce coalesce( *this ); 496 PhaseConservativeCoalesce coalesce(*this);
355 // If max live ranges greater than cutoff, don't color the stack. 497 // If max live ranges greater than cutoff, don't color the stack.
356 // This cutoff can be larger than below since it is only done once. 498 // This cutoff can be larger than below since it is only done once.
357 coalesce.coalesce_driver( ); 499 coalesce.coalesce_driver();
358 } 500 }
359 compress_uf_map_for_nodes(); 501 _lrg_map.compress_uf_map_for_nodes();
360 502
361 #ifdef ASSERT 503 #ifdef ASSERT
362 verify(&live_arena, true); 504 verify(&live_arena, true);
363 #endif 505 #endif
364 } else { 506 } else {
388 C->record_method_not_compilable("failed spill-split-recycle sanity check"); 530 C->record_method_not_compilable("failed spill-split-recycle sanity check");
389 return; 531 return;
390 } 532 }
391 } 533 }
392 534
393 if( !_maxlrg ) return; 535 if (!_lrg_map.max_lrg_id()) {
394 _maxlrg = Split(_maxlrg, &split_arena); // Split spilling LRG everywhere 536 return;
537 }
538 uint new_max_lrg_id = Split(_lrg_map.max_lrg_id(), &split_arena); // Split spilling LRG everywhere
539 _lrg_map.set_max_lrg_id(new_max_lrg_id);
395 // Bail out if unique gets too large (ie - unique > MaxNodeLimit - 2*NodeLimitFudgeFactor) 540 // Bail out if unique gets too large (ie - unique > MaxNodeLimit - 2*NodeLimitFudgeFactor)
396 C->check_node_count(2*NodeLimitFudgeFactor, "out of nodes after split"); 541 C->check_node_count(2 * NodeLimitFudgeFactor, "out of nodes after split");
397 if (C->failing()) return; 542 if (C->failing()) {
398 543 return;
399 compact(); // Compact LRGs; return new lower max lrg 544 }
545
546 compact(); // Compact LRGs; return new lower max lrg
400 547
401 // Nuke the live-ness and interference graph and LiveRanGe info 548 // Nuke the live-ness and interference graph and LiveRanGe info
402 { 549 {
403 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) 550 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
404 _live = NULL; 551 _live = NULL;
405 rm.reset_to_mark(); // Reclaim working storage 552 rm.reset_to_mark(); // Reclaim working storage
406 IndexSet::reset_memory(C, &live_arena); 553 IndexSet::reset_memory(C, &live_arena);
407 ifg.init(_maxlrg); 554 ifg.init(_lrg_map.max_lrg_id());
408 555
409 // Create LiveRanGe array. 556 // Create LiveRanGe array.
410 // Intersect register masks for all USEs and DEFs 557 // Intersect register masks for all USEs and DEFs
411 gather_lrg_masks( true ); 558 gather_lrg_masks(true);
412 live.compute( _maxlrg ); 559 live.compute(_lrg_map.max_lrg_id());
413 _live = &live; 560 _live = &live;
414 } 561 }
415 must_spill = build_ifg_physical( &live_arena ); 562 must_spill = build_ifg_physical(&live_arena);
416 _ifg->SquareUp(); 563 _ifg->SquareUp();
417 _ifg->Compute_Effective_Degree(); 564 _ifg->Compute_Effective_Degree();
418 565
419 // Only do conservative coalescing if requested 566 // Only do conservative coalescing if requested
420 if( OptoCoalesce ) { 567 if (OptoCoalesce) {
421 // Conservative (and pessimistic) copy coalescing 568 // Conservative (and pessimistic) copy coalescing
422 PhaseConservativeCoalesce coalesce( *this ); 569 PhaseConservativeCoalesce coalesce(*this);
423 // Check for few live ranges determines how aggressive coalesce is. 570 // Check for few live ranges determines how aggressive coalesce is.
424 coalesce.coalesce_driver( ); 571 coalesce.coalesce_driver();
425 } 572 }
426 compress_uf_map_for_nodes(); 573 _lrg_map.compress_uf_map_for_nodes();
427 #ifdef ASSERT 574 #ifdef ASSERT
428 verify(&live_arena, true); 575 verify(&live_arena, true);
429 #endif 576 #endif
430 cache_lrg_info(); // Count degree of LRGs 577 cache_lrg_info(); // Count degree of LRGs
431 578
433 // LRGs of low degree are trivially colorable. 580 // LRGs of low degree are trivially colorable.
434 Simplify(); 581 Simplify();
435 582
436 // Select colors by re-inserting LRGs back into the IFG in reverse order. 583 // Select colors by re-inserting LRGs back into the IFG in reverse order.
437 // Return whether or not something spills. 584 // Return whether or not something spills.
438 spills = Select( ); 585 spills = Select();
439 } 586 }
440 587
441 // Count number of Simplify-Select trips per coloring success. 588 // Count number of Simplify-Select trips per coloring success.
442 _allocator_attempts += _trip_cnt + 1; 589 _allocator_attempts += _trip_cnt + 1;
443 _allocator_successes += 1; 590 _allocator_successes += 1;
450 verify(&live_arena); 597 verify(&live_arena);
451 #endif 598 #endif
452 599
453 // max_reg is past the largest *register* used. 600 // max_reg is past the largest *register* used.
454 // Convert that to a frame_slot number. 601 // Convert that to a frame_slot number.
455 if( _max_reg <= _matcher._new_SP ) 602 if (_max_reg <= _matcher._new_SP) {
456 _framesize = C->out_preserve_stack_slots(); 603 _framesize = C->out_preserve_stack_slots();
457 else _framesize = _max_reg -_matcher._new_SP; 604 }
605 else {
606 _framesize = _max_reg -_matcher._new_SP;
607 }
458 assert((int)(_matcher._new_SP+_framesize) >= (int)_matcher._out_arg_limit, "framesize must be large enough"); 608 assert((int)(_matcher._new_SP+_framesize) >= (int)_matcher._out_arg_limit, "framesize must be large enough");
459 609
460 // This frame must preserve the required fp alignment 610 // This frame must preserve the required fp alignment
461 _framesize = round_to(_framesize, Matcher::stack_alignment_in_slots()); 611 _framesize = round_to(_framesize, Matcher::stack_alignment_in_slots());
462 assert( _framesize >= 0 && _framesize <= 1000000, "sanity check" ); 612 assert( _framesize >= 0 && _framesize <= 1000000, "sanity check" );
463 #ifndef PRODUCT 613 #ifndef PRODUCT
464 _total_framesize += _framesize; 614 _total_framesize += _framesize;
465 if( (int)_framesize > _max_framesize ) 615 if ((int)_framesize > _max_framesize) {
466 _max_framesize = _framesize; 616 _max_framesize = _framesize;
617 }
467 #endif 618 #endif
468 619
469 // Convert CISC spills 620 // Convert CISC spills
470 fixup_spills(); 621 fixup_spills();
471 622
473 CompileLog* log = Compile::current()->log(); 624 CompileLog* log = Compile::current()->log();
474 if (log != NULL) { 625 if (log != NULL) {
475 log->elem("regalloc attempts='%d' success='%d'", _trip_cnt, !C->failing()); 626 log->elem("regalloc attempts='%d' success='%d'", _trip_cnt, !C->failing());
476 } 627 }
477 628
478 if (C->failing()) return; 629 if (C->failing()) {
479 630 return;
480 NOT_PRODUCT( C->verify_graph_edges(); ) 631 }
632
633 NOT_PRODUCT(C->verify_graph_edges();)
481 634
482 // Move important info out of the live_arena to longer lasting storage. 635 // Move important info out of the live_arena to longer lasting storage.
483 alloc_node_regs(_names.Size()); 636 alloc_node_regs(_lrg_map.size());
484 for (uint i=0; i < _names.Size(); i++) { 637 for (uint i=0; i < _lrg_map.size(); i++) {
485 if (_names[i]) { // Live range associated with Node? 638 if (_lrg_map.live_range_id(i)) { // Live range associated with Node?
486 LRG &lrg = lrgs(_names[i]); 639 LRG &lrg = lrgs(_lrg_map.live_range_id(i));
487 if (!lrg.alive()) { 640 if (!lrg.alive()) {
488 set_bad(i); 641 set_bad(i);
489 } else if (lrg.num_regs() == 1) { 642 } else if (lrg.num_regs() == 1) {
490 set1(i, lrg.reg()); 643 set1(i, lrg.reg());
491 } else { // Must be a register-set 644 } else { // Must be a register-set
535 // Handle all the normal Nodes in the block 688 // Handle all the normal Nodes in the block
536 for( uint j = 0; j < cnt; j++ ) { 689 for( uint j = 0; j < cnt; j++ ) {
537 Node *n = b->_nodes[j]; 690 Node *n = b->_nodes[j];
538 // Pre-color to the zero live range, or pick virtual register 691 // Pre-color to the zero live range, or pick virtual register
539 const RegMask &rm = n->out_RegMask(); 692 const RegMask &rm = n->out_RegMask();
540 _names.map( n->_idx, rm.is_NotEmpty() ? lr_counter++ : 0 ); 693 _lrg_map.map(n->_idx, rm.is_NotEmpty() ? lr_counter++ : 0);
541 } 694 }
542 } 695 }
543 // Reset the Union-Find mapping to be identity 696 // Reset the Union-Find mapping to be identity
544 reset_uf_map(lr_counter); 697 _lrg_map.reset_uf_map(lr_counter);
545 } 698 }
546 699
547 700
548 //------------------------------gather_lrg_masks------------------------------- 701 //------------------------------gather_lrg_masks-------------------------------
549 // Gather LiveRanGe information, including register masks. Modification of 702 // Gather LiveRanGe information, including register masks. Modification of
550 // cisc spillable in_RegMasks should not be done before AggressiveCoalesce. 703 // cisc spillable in_RegMasks should not be done before AggressiveCoalesce.
551 void PhaseChaitin::gather_lrg_masks( bool after_aggressive ) { 704 void PhaseChaitin::gather_lrg_masks( bool after_aggressive ) {
552 705
553 // Nail down the frame pointer live range 706 // Nail down the frame pointer live range
554 uint fp_lrg = n2lidx(_cfg._root->in(1)->in(TypeFunc::FramePtr)); 707 uint fp_lrg = _lrg_map.live_range_id(_cfg._root->in(1)->in(TypeFunc::FramePtr));
555 lrgs(fp_lrg)._cost += 1e12; // Cost is infinite 708 lrgs(fp_lrg)._cost += 1e12; // Cost is infinite
556 709
557 // For all blocks 710 // For all blocks
558 for( uint i = 0; i < _cfg._num_blocks; i++ ) { 711 for( uint i = 0; i < _cfg._num_blocks; i++ ) {
559 Block *b = _cfg._blocks[i]; 712 Block *b = _cfg._blocks[i];
564 uint input_edge_start =1; // Skip control most nodes 717 uint input_edge_start =1; // Skip control most nodes
565 if( n->is_Mach() ) input_edge_start = n->as_Mach()->oper_input_base(); 718 if( n->is_Mach() ) input_edge_start = n->as_Mach()->oper_input_base();
566 uint idx = n->is_Copy(); 719 uint idx = n->is_Copy();
567 720
568 // Get virtual register number, same as LiveRanGe index 721 // Get virtual register number, same as LiveRanGe index
569 uint vreg = n2lidx(n); 722 uint vreg = _lrg_map.live_range_id(n);
570 LRG &lrg = lrgs(vreg); 723 LRG &lrg = lrgs(vreg);
571 if( vreg ) { // No vreg means un-allocable (e.g. memory) 724 if( vreg ) { // No vreg means un-allocable (e.g. memory)
572 725
573 // Collect has-copy bit 726 // Collect has-copy bit
574 if( idx ) { 727 if( idx ) {
575 lrg._has_copy = 1; 728 lrg._has_copy = 1;
576 uint clidx = n2lidx(n->in(idx)); 729 uint clidx = _lrg_map.live_range_id(n->in(idx));
577 LRG &copy_src = lrgs(clidx); 730 LRG &copy_src = lrgs(clidx);
578 copy_src._has_copy = 1; 731 copy_src._has_copy = 1;
579 } 732 }
580 733
581 // Check for float-vs-int live range (used in register-pressure 734 // Check for float-vs-int live range (used in register-pressure
771 // Convert operand number to edge index number 924 // Convert operand number to edge index number
772 inp = n->as_Mach()->operand_index(inp); 925 inp = n->as_Mach()->operand_index(inp);
773 } 926 }
774 // Prepare register mask for each input 927 // Prepare register mask for each input
775 for( uint k = input_edge_start; k < cnt; k++ ) { 928 for( uint k = input_edge_start; k < cnt; k++ ) {
776 uint vreg = n2lidx(n->in(k)); 929 uint vreg = _lrg_map.live_range_id(n->in(k));
777 if( !vreg ) continue; 930 if (!vreg) {
931 continue;
932 }
778 933
779 // If this instruction is CISC Spillable, add the flags 934 // If this instruction is CISC Spillable, add the flags
780 // bit to its appropriate input 935 // bit to its appropriate input
781 if( UseCISCSpill && after_aggressive && inp == k ) { 936 if( UseCISCSpill && after_aggressive && inp == k ) {
782 #ifndef PRODUCT 937 #ifndef PRODUCT
855 } // End for all allocated inputs 1010 } // End for all allocated inputs
856 } // end for all instructions 1011 } // end for all instructions
857 } // end for all blocks 1012 } // end for all blocks
858 1013
859 // Final per-liverange setup 1014 // Final per-liverange setup
860 for (uint i2=0; i2<_maxlrg; i2++) { 1015 for (uint i2 = 0; i2 < _lrg_map.max_lrg_id(); i2++) {
861 LRG &lrg = lrgs(i2); 1016 LRG &lrg = lrgs(i2);
862 assert(!lrg._is_vector || !lrg._fat_proj, "sanity"); 1017 assert(!lrg._is_vector || !lrg._fat_proj, "sanity");
863 if (lrg.num_regs() > 1 && !lrg._fat_proj) { 1018 if (lrg.num_regs() > 1 && !lrg._fat_proj) {
864 lrg.clear_to_sets(); 1019 lrg.clear_to_sets();
865 } 1020 }
877 // colorability of the graph. If any live range was of low-degree before 1032 // colorability of the graph. If any live range was of low-degree before
878 // coalescing, it should Simplify. This call sets the was-lo-degree bit. 1033 // coalescing, it should Simplify. This call sets the was-lo-degree bit.
879 // The bit is checked in Simplify. 1034 // The bit is checked in Simplify.
880 void PhaseChaitin::set_was_low() { 1035 void PhaseChaitin::set_was_low() {
881 #ifdef ASSERT 1036 #ifdef ASSERT
882 for( uint i = 1; i < _maxlrg; i++ ) { 1037 for (uint i = 1; i < _lrg_map.max_lrg_id(); i++) {
883 int size = lrgs(i).num_regs(); 1038 int size = lrgs(i).num_regs();
884 uint old_was_lo = lrgs(i)._was_lo; 1039 uint old_was_lo = lrgs(i)._was_lo;
885 lrgs(i)._was_lo = 0; 1040 lrgs(i)._was_lo = 0;
886 if( lrgs(i).lo_degree() ) { 1041 if( lrgs(i).lo_degree() ) {
887 lrgs(i)._was_lo = 1; // Trivially of low degree 1042 lrgs(i)._was_lo = 1; // Trivially of low degree
911 1066
912 //------------------------------cache_lrg_info--------------------------------- 1067 //------------------------------cache_lrg_info---------------------------------
913 // Compute cost/area ratio, in case we spill. Build the lo-degree list. 1068 // Compute cost/area ratio, in case we spill. Build the lo-degree list.
914 void PhaseChaitin::cache_lrg_info( ) { 1069 void PhaseChaitin::cache_lrg_info( ) {
915 1070
916 for( uint i = 1; i < _maxlrg; i++ ) { 1071 for (uint i = 1; i < _lrg_map.max_lrg_id(); i++) {
917 LRG &lrg = lrgs(i); 1072 LRG &lrg = lrgs(i);
918 1073
919 // Check for being of low degree: means we can be trivially colored. 1074 // Check for being of low degree: means we can be trivially colored.
920 // Low degree, dead or must-spill guys just get to simplify right away 1075 // Low degree, dead or must-spill guys just get to simplify right away
921 if( lrg.lo_degree() || 1076 if( lrg.lo_degree() ||
947 // Simplify the IFG by removing LRGs of low degree that have NO copies 1102 // Simplify the IFG by removing LRGs of low degree that have NO copies
948 void PhaseChaitin::Pre_Simplify( ) { 1103 void PhaseChaitin::Pre_Simplify( ) {
949 1104
950 // Warm up the lo-degree no-copy list 1105 // Warm up the lo-degree no-copy list
951 int lo_no_copy = 0; 1106 int lo_no_copy = 0;
952 for( uint i = 1; i < _maxlrg; i++ ) { 1107 for (uint i = 1; i < _lrg_map.max_lrg_id(); i++) {
953 if( (lrgs(i).lo_degree() && !lrgs(i)._has_copy) || 1108 if ((lrgs(i).lo_degree() && !lrgs(i)._has_copy) ||
954 !lrgs(i).alive() || 1109 !lrgs(i).alive() ||
955 lrgs(i)._must_spill ) { 1110 lrgs(i)._must_spill) {
956 lrgs(i)._next = lo_no_copy; 1111 lrgs(i)._next = lo_no_copy;
957 lo_no_copy = i; 1112 lo_no_copy = i;
958 } 1113 }
959 } 1114 }
960 1115
1161 //------------------------------bias_color------------------------------------- 1316 //------------------------------bias_color-------------------------------------
1162 // Choose a color using the biasing heuristic 1317 // Choose a color using the biasing heuristic
1163 OptoReg::Name PhaseChaitin::bias_color( LRG &lrg, int chunk ) { 1318 OptoReg::Name PhaseChaitin::bias_color( LRG &lrg, int chunk ) {
1164 1319
1165 // Check for "at_risk" LRG's 1320 // Check for "at_risk" LRG's
1166 uint risk_lrg = Find(lrg._risk_bias); 1321 uint risk_lrg = _lrg_map.find(lrg._risk_bias);
1167 if( risk_lrg != 0 ) { 1322 if( risk_lrg != 0 ) {
1168 // Walk the colored neighbors of the "at_risk" candidate 1323 // Walk the colored neighbors of the "at_risk" candidate
1169 // Choose a color which is both legal and already taken by a neighbor 1324 // Choose a color which is both legal and already taken by a neighbor
1170 // of the "at_risk" candidate in order to improve the chances of the 1325 // of the "at_risk" candidate in order to improve the chances of the
1171 // "at_risk" candidate of coloring 1326 // "at_risk" candidate of coloring
1177 if (is_legal_reg(lrg, reg, chunk)) 1332 if (is_legal_reg(lrg, reg, chunk))
1178 return reg; 1333 return reg;
1179 } 1334 }
1180 } 1335 }
1181 1336
1182 uint copy_lrg = Find(lrg._copy_bias); 1337 uint copy_lrg = _lrg_map.find(lrg._copy_bias);
1183 if( copy_lrg != 0 ) { 1338 if( copy_lrg != 0 ) {
1184 // If he has a color, 1339 // If he has a color,
1185 if( !(*(_ifg->_yanked))[copy_lrg] ) { 1340 if( !(*(_ifg->_yanked))[copy_lrg] ) {
1186 OptoReg::Name reg = lrgs(copy_lrg).reg(); 1341 OptoReg::Name reg = lrgs(copy_lrg).reg();
1187 // And it is legal for you, 1342 // And it is legal for you,
1421 //------------------------------copy_was_spilled------------------------------- 1576 //------------------------------copy_was_spilled-------------------------------
1422 // Copy 'was_spilled'-edness from the source Node to the dst Node. 1577 // Copy 'was_spilled'-edness from the source Node to the dst Node.
1423 void PhaseChaitin::copy_was_spilled( Node *src, Node *dst ) { 1578 void PhaseChaitin::copy_was_spilled( Node *src, Node *dst ) {
1424 if( _spilled_once.test(src->_idx) ) { 1579 if( _spilled_once.test(src->_idx) ) {
1425 _spilled_once.set(dst->_idx); 1580 _spilled_once.set(dst->_idx);
1426 lrgs(Find(dst))._was_spilled1 = 1; 1581 lrgs(_lrg_map.find(dst))._was_spilled1 = 1;
1427 if( _spilled_twice.test(src->_idx) ) { 1582 if( _spilled_twice.test(src->_idx) ) {
1428 _spilled_twice.set(dst->_idx); 1583 _spilled_twice.set(dst->_idx);
1429 lrgs(Find(dst))._was_spilled2 = 1; 1584 lrgs(_lrg_map.find(dst))._was_spilled2 = 1;
1430 } 1585 }
1431 } 1586 }
1432 } 1587 }
1433 1588
1434 //------------------------------set_was_spilled-------------------------------- 1589 //------------------------------set_was_spilled--------------------------------
1469 if( inp != AdlcVMDeps::Not_cisc_spillable ) { 1624 if( inp != AdlcVMDeps::Not_cisc_spillable ) {
1470 // Convert operand number to edge index number 1625 // Convert operand number to edge index number
1471 MachNode *mach = n->as_Mach(); 1626 MachNode *mach = n->as_Mach();
1472 inp = mach->operand_index(inp); 1627 inp = mach->operand_index(inp);
1473 Node *src = n->in(inp); // Value to load or store 1628 Node *src = n->in(inp); // Value to load or store
1474 LRG &lrg_cisc = lrgs( Find_const(src) ); 1629 LRG &lrg_cisc = lrgs(_lrg_map.find_const(src));
1475 OptoReg::Name src_reg = lrg_cisc.reg(); 1630 OptoReg::Name src_reg = lrg_cisc.reg();
1476 // Doubles record the HIGH register of an adjacent pair. 1631 // Doubles record the HIGH register of an adjacent pair.
1477 src_reg = OptoReg::add(src_reg,1-lrg_cisc.num_regs()); 1632 src_reg = OptoReg::add(src_reg,1-lrg_cisc.num_regs());
1478 if( OptoReg::is_stack(src_reg) ) { // If input is on stack 1633 if( OptoReg::is_stack(src_reg) ) { // If input is on stack
1479 // This is a CISC Spill, get stack offset and construct new node 1634 // This is a CISC Spill, get stack offset and construct new node
1552 // (where top() node is placed). 1707 // (where top() node is placed).
1553 base->init_req(0, _cfg._root); 1708 base->init_req(0, _cfg._root);
1554 Block *startb = _cfg._bbs[C->top()->_idx]; 1709 Block *startb = _cfg._bbs[C->top()->_idx];
1555 startb->_nodes.insert(startb->find_node(C->top()), base ); 1710 startb->_nodes.insert(startb->find_node(C->top()), base );
1556 _cfg._bbs.map( base->_idx, startb ); 1711 _cfg._bbs.map( base->_idx, startb );
1557 assert (n2lidx(base) == 0, "should not have LRG yet"); 1712 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1558 } 1713 }
1559 if (n2lidx(base) == 0) { 1714 if (_lrg_map.live_range_id(base) == 0) {
1560 new_lrg(base, maxlrg++); 1715 new_lrg(base, maxlrg++);
1561 } 1716 }
1562 assert(base->in(0) == _cfg._root && 1717 assert(base->in(0) == _cfg._root &&
1563 _cfg._bbs[base->_idx] == _cfg._bbs[C->top()->_idx], "base NULL should be shared"); 1718 _cfg._bbs[base->_idx] == _cfg._bbs[C->top()->_idx], "base NULL should be shared");
1564 derived_base_map[derived->_idx] = base; 1719 derived_base_map[derived->_idx] = base;
1565 return base; 1720 return base;
1566 } 1721 }
1567 1722
1568 // Check for AddP-related opcodes 1723 // Check for AddP-related opcodes
1569 if( !derived->is_Phi() ) { 1724 if (!derived->is_Phi()) {
1570 assert(derived->as_Mach()->ideal_Opcode() == Op_AddP, err_msg_res("but is: %s", derived->Name())); 1725 assert(derived->as_Mach()->ideal_Opcode() == Op_AddP, err_msg_res("but is: %s", derived->Name()));
1571 Node *base = derived->in(AddPNode::Base); 1726 Node *base = derived->in(AddPNode::Base);
1572 derived_base_map[derived->_idx] = base; 1727 derived_base_map[derived->_idx] = base;
1573 return base; 1728 return base;
1574 } 1729 }
1627 //------------------------------stretch_base_pointer_live_ranges--------------- 1782 //------------------------------stretch_base_pointer_live_ranges---------------
1628 // At each Safepoint, insert extra debug edges for each pair of derived value/ 1783 // At each Safepoint, insert extra debug edges for each pair of derived value/
1629 // base pointer that is live across the Safepoint for oopmap building. The 1784 // base pointer that is live across the Safepoint for oopmap building. The
1630 // edge pairs get added in after sfpt->jvmtail()->oopoff(), but are in the 1785 // edge pairs get added in after sfpt->jvmtail()->oopoff(), but are in the
1631 // required edge set. 1786 // required edge set.
1632 bool PhaseChaitin::stretch_base_pointer_live_ranges( ResourceArea *a ) { 1787 bool PhaseChaitin::stretch_base_pointer_live_ranges(ResourceArea *a) {
1633 int must_recompute_live = false; 1788 int must_recompute_live = false;
1634 uint maxlrg = _maxlrg; 1789 uint maxlrg = _lrg_map.max_lrg_id();
1635 Node **derived_base_map = (Node**)a->Amalloc(sizeof(Node*)*C->unique()); 1790 Node **derived_base_map = (Node**)a->Amalloc(sizeof(Node*)*C->unique());
1636 memset( derived_base_map, 0, sizeof(Node*)*C->unique() ); 1791 memset( derived_base_map, 0, sizeof(Node*)*C->unique() );
1637 1792
1638 // For all blocks in RPO do... 1793 // For all blocks in RPO do...
1639 for( uint i=0; i<_cfg._num_blocks; i++ ) { 1794 for( uint i=0; i<_cfg._num_blocks; i++ ) {
1667 } 1822 }
1668 } 1823 }
1669 } 1824 }
1670 1825
1671 // Get value being defined 1826 // Get value being defined
1672 uint lidx = n2lidx(n); 1827 uint lidx = _lrg_map.live_range_id(n);
1673 if( lidx && lidx < _maxlrg /* Ignore the occasional brand-new live range */) { 1828 // Ignore the occasional brand-new live range
1829 if (lidx && lidx < _lrg_map.max_lrg_id()) {
1674 // Remove from live-out set 1830 // Remove from live-out set
1675 liveout.remove(lidx); 1831 liveout.remove(lidx);
1676 1832
1677 // Copies do not define a new value and so do not interfere. 1833 // Copies do not define a new value and so do not interfere.
1678 // Remove the copies source from the liveout set before interfering. 1834 // Remove the copies source from the liveout set before interfering.
1679 uint idx = n->is_Copy(); 1835 uint idx = n->is_Copy();
1680 if( idx ) liveout.remove( n2lidx(n->in(idx)) ); 1836 if (idx) {
1837 liveout.remove(_lrg_map.live_range_id(n->in(idx)));
1838 }
1681 } 1839 }
1682 1840
1683 // Found a safepoint? 1841 // Found a safepoint?
1684 JVMState *jvms = n->jvms(); 1842 JVMState *jvms = n->jvms();
1685 if( jvms ) { 1843 if( jvms ) {
1693 const TypePtr *tj = derived->bottom_type()->isa_ptr(); 1851 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1694 assert(!derived->bottom_type()->isa_narrowoop() || 1852 assert(!derived->bottom_type()->isa_narrowoop() ||
1695 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity"); 1853 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1696 // If its an OOP with a non-zero offset, then it is derived. 1854 // If its an OOP with a non-zero offset, then it is derived.
1697 if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) { 1855 if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
1698 Node *base = find_base_for_derived( derived_base_map, derived, maxlrg ); 1856 Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
1699 assert( base->_idx < _names.Size(), "" ); 1857 assert(base->_idx < _lrg_map.size(), "");
1700 // Add reaching DEFs of derived pointer and base pointer as a 1858 // Add reaching DEFs of derived pointer and base pointer as a
1701 // pair of inputs 1859 // pair of inputs
1702 n->add_req( derived ); 1860 n->add_req(derived);
1703 n->add_req( base ); 1861 n->add_req(base);
1704 1862
1705 // See if the base pointer is already live to this point. 1863 // See if the base pointer is already live to this point.
1706 // Since I'm working on the SSA form, live-ness amounts to 1864 // Since I'm working on the SSA form, live-ness amounts to
1707 // reaching def's. So if I find the base's live range then 1865 // reaching def's. So if I find the base's live range then
1708 // I know the base's def reaches here. 1866 // I know the base's def reaches here.
1709 if( (n2lidx(base) >= _maxlrg ||// (Brand new base (hence not live) or 1867 if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
1710 !liveout.member( n2lidx(base) ) ) && // not live) AND 1868 !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
1711 (n2lidx(base) > 0) && // not a constant 1869 (_lrg_map.live_range_id(base) > 0) && // not a constant
1712 _cfg._bbs[base->_idx] != b ) { // base not def'd in blk) 1870 _cfg._bbs[base->_idx] != b) { // base not def'd in blk)
1713 // Base pointer is not currently live. Since I stretched 1871 // Base pointer is not currently live. Since I stretched
1714 // the base pointer to here and it crosses basic-block 1872 // the base pointer to here and it crosses basic-block
1715 // boundaries, the global live info is now incorrect. 1873 // boundaries, the global live info is now incorrect.
1716 // Recompute live. 1874 // Recompute live.
1717 must_recompute_live = true; 1875 must_recompute_live = true;
1719 } 1877 }
1720 } // End of scan all live data for derived ptrs crossing GC point 1878 } // End of scan all live data for derived ptrs crossing GC point
1721 } // End of if found a GC point 1879 } // End of if found a GC point
1722 1880
1723 // Make all inputs live 1881 // Make all inputs live
1724 if( !n->is_Phi() ) { // Phi function uses come from prior block 1882 if (!n->is_Phi()) { // Phi function uses come from prior block
1725 for( uint k = 1; k < n->req(); k++ ) { 1883 for (uint k = 1; k < n->req(); k++) {
1726 uint lidx = n2lidx(n->in(k)); 1884 uint lidx = _lrg_map.live_range_id(n->in(k));
1727 if( lidx < _maxlrg ) 1885 if (lidx < _lrg_map.max_lrg_id()) {
1728 liveout.insert( lidx ); 1886 liveout.insert(lidx);
1887 }
1729 } 1888 }
1730 } 1889 }
1731 1890
1732 } // End of forall instructions in block 1891 } // End of forall instructions in block
1733 liveout.clear(); // Free the memory used by liveout. 1892 liveout.clear(); // Free the memory used by liveout.
1734 1893
1735 } // End of forall blocks 1894 } // End of forall blocks
1736 _maxlrg = maxlrg; 1895 _lrg_map.set_max_lrg_id(maxlrg);
1737 1896
1738 // If I created a new live range I need to recompute live 1897 // If I created a new live range I need to recompute live
1739 if( maxlrg != _ifg->_maxlrg ) 1898 if (maxlrg != _ifg->_maxlrg) {
1740 must_recompute_live = true; 1899 must_recompute_live = true;
1900 }
1741 1901
1742 return must_recompute_live != 0; 1902 return must_recompute_live != 0;
1743 } 1903 }
1744 1904
1745 1905
1746 //------------------------------add_reference---------------------------------- 1906 //------------------------------add_reference----------------------------------
1747 // Extend the node to LRG mapping 1907 // Extend the node to LRG mapping
1748 void PhaseChaitin::add_reference( const Node *node, const Node *old_node ) { 1908
1749 _names.extend( node->_idx, n2lidx(old_node) ); 1909 void PhaseChaitin::add_reference(const Node *node, const Node *old_node) {
1910 _lrg_map.extend(node->_idx, _lrg_map.live_range_id(old_node));
1750 } 1911 }
1751 1912
1752 //------------------------------dump------------------------------------------- 1913 //------------------------------dump-------------------------------------------
1753 #ifndef PRODUCT 1914 #ifndef PRODUCT
1754 void PhaseChaitin::dump( const Node *n ) const { 1915 void PhaseChaitin::dump(const Node *n) const {
1755 uint r = (n->_idx < _names.Size() ) ? Find_const(n) : 0; 1916 uint r = (n->_idx < _lrg_map.size()) ? _lrg_map.find_const(n) : 0;
1756 tty->print("L%d",r); 1917 tty->print("L%d",r);
1757 if( r && n->Opcode() != Op_Phi ) { 1918 if (r && n->Opcode() != Op_Phi) {
1758 if( _node_regs ) { // Got a post-allocation copy of allocation? 1919 if( _node_regs ) { // Got a post-allocation copy of allocation?
1759 tty->print("["); 1920 tty->print("[");
1760 OptoReg::Name second = get_reg_second(n); 1921 OptoReg::Name second = get_reg_second(n);
1761 if( OptoReg::is_valid(second) ) { 1922 if( OptoReg::is_valid(second) ) {
1762 if( OptoReg::is_reg(second) ) 1923 if( OptoReg::is_reg(second) )
1773 n->out_RegMask().dump(); 1934 n->out_RegMask().dump();
1774 } 1935 }
1775 tty->print("/N%d\t",n->_idx); 1936 tty->print("/N%d\t",n->_idx);
1776 tty->print("%s === ", n->Name()); 1937 tty->print("%s === ", n->Name());
1777 uint k; 1938 uint k;
1778 for( k = 0; k < n->req(); k++) { 1939 for (k = 0; k < n->req(); k++) {
1779 Node *m = n->in(k); 1940 Node *m = n->in(k);
1780 if( !m ) tty->print("_ "); 1941 if (!m) {
1942 tty->print("_ ");
1943 }
1781 else { 1944 else {
1782 uint r = (m->_idx < _names.Size() ) ? Find_const(m) : 0; 1945 uint r = (m->_idx < _lrg_map.size()) ? _lrg_map.find_const(m) : 0;
1783 tty->print("L%d",r); 1946 tty->print("L%d",r);
1784 // Data MultiNode's can have projections with no real registers. 1947 // Data MultiNode's can have projections with no real registers.
1785 // Don't die while dumping them. 1948 // Don't die while dumping them.
1786 int op = n->Opcode(); 1949 int op = n->Opcode();
1787 if( r && op != Op_Phi && op != Op_Proj && op != Op_SCMemProj) { 1950 if( r && op != Op_Phi && op != Op_Proj && op != Op_SCMemProj) {
1808 } 1971 }
1809 } 1972 }
1810 if( k < n->len() && n->in(k) ) tty->print("| "); 1973 if( k < n->len() && n->in(k) ) tty->print("| ");
1811 for( ; k < n->len(); k++ ) { 1974 for( ; k < n->len(); k++ ) {
1812 Node *m = n->in(k); 1975 Node *m = n->in(k);
1813 if( !m ) break; 1976 if(!m) {
1814 uint r = (m->_idx < _names.Size() ) ? Find_const(m) : 0; 1977 break;
1978 }
1979 uint r = (m->_idx < _lrg_map.size()) ? _lrg_map.find_const(m) : 0;
1815 tty->print("L%d",r); 1980 tty->print("L%d",r);
1816 tty->print("/N%d ",m->_idx); 1981 tty->print("/N%d ",m->_idx);
1817 } 1982 }
1818 if( n->is_Mach() ) n->as_Mach()->dump_spec(tty); 1983 if( n->is_Mach() ) n->as_Mach()->dump_spec(tty);
1819 else n->dump_spec(tty); 1984 else n->dump_spec(tty);
1837 IndexSet *live = _live->live(b); 2002 IndexSet *live = _live->live(b);
1838 IndexSetIterator elements(live); 2003 IndexSetIterator elements(live);
1839 tty->print("{"); 2004 tty->print("{");
1840 uint i; 2005 uint i;
1841 while ((i = elements.next()) != 0) { 2006 while ((i = elements.next()) != 0) {
1842 tty->print("L%d ", Find_const(i)); 2007 tty->print("L%d ", _lrg_map.find_const(i));
1843 } 2008 }
1844 tty->print_cr("}"); 2009 tty->print_cr("}");
1845 } 2010 }
1846 tty->print("\n"); 2011 tty->print("\n");
1847 } 2012 }
1861 return; 2026 return;
1862 } 2027 }
1863 2028
1864 // Dump LRG array 2029 // Dump LRG array
1865 tty->print("--- Live RanGe Array ---\n"); 2030 tty->print("--- Live RanGe Array ---\n");
1866 for(uint i2 = 1; i2 < _maxlrg; i2++ ) { 2031 for (uint i2 = 1; i2 < _lrg_map.max_lrg_id(); i2++) {
1867 tty->print("L%d: ",i2); 2032 tty->print("L%d: ",i2);
1868 if( i2 < _ifg->_maxlrg ) lrgs(i2).dump( ); 2033 if (i2 < _ifg->_maxlrg) {
1869 else tty->print_cr("new LRG"); 2034 lrgs(i2).dump();
2035 }
2036 else {
2037 tty->print_cr("new LRG");
2038 }
1870 } 2039 }
1871 tty->print_cr(""); 2040 tty->print_cr("");
1872 2041
1873 // Dump lo-degree list 2042 // Dump lo-degree list
1874 tty->print("Lo degree: "); 2043 tty->print("Lo degree: ");
1937 sprintf(buf,"N%d",n->_idx); // Then use Node index 2106 sprintf(buf,"N%d",n->_idx); // Then use Node index
1938 } else if( _node_regs ) { 2107 } else if( _node_regs ) {
1939 // Post allocation, use direct mappings, no LRG info available 2108 // Post allocation, use direct mappings, no LRG info available
1940 print_reg( get_reg_first(n), this, buf ); 2109 print_reg( get_reg_first(n), this, buf );
1941 } else { 2110 } else {
1942 uint lidx = Find_const(n); // Grab LRG number 2111 uint lidx = _lrg_map.find_const(n); // Grab LRG number
1943 if( !_ifg ) { 2112 if( !_ifg ) {
1944 sprintf(buf,"L%d",lidx); // No register binding yet 2113 sprintf(buf,"L%d",lidx); // No register binding yet
1945 } else if( !lidx ) { // Special, not allocated value 2114 } else if( !lidx ) { // Special, not allocated value
1946 strcpy(buf,"Special"); 2115 strcpy(buf,"Special");
1947 } else { 2116 } else {
1966 //----------------------dump_for_spill_split_recycle-------------------------- 2135 //----------------------dump_for_spill_split_recycle--------------------------
1967 void PhaseChaitin::dump_for_spill_split_recycle() const { 2136 void PhaseChaitin::dump_for_spill_split_recycle() const {
1968 if( WizardMode && (PrintCompilation || PrintOpto) ) { 2137 if( WizardMode && (PrintCompilation || PrintOpto) ) {
1969 // Display which live ranges need to be split and the allocator's state 2138 // Display which live ranges need to be split and the allocator's state
1970 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt); 2139 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
1971 for( uint bidx = 1; bidx < _maxlrg; bidx++ ) { 2140 for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
1972 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) { 2141 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
1973 tty->print("L%d: ", bidx); 2142 tty->print("L%d: ", bidx);
1974 lrgs(bidx).dump(); 2143 lrgs(bidx).dump();
1975 } 2144 }
1976 } 2145 }
2097 2266
2098 //------------------------------dump_lrg--------------------------------------- 2267 //------------------------------dump_lrg---------------------------------------
2099 void PhaseChaitin::dump_lrg( uint lidx, bool defs_only ) const { 2268 void PhaseChaitin::dump_lrg( uint lidx, bool defs_only ) const {
2100 tty->print_cr("---dump of L%d---",lidx); 2269 tty->print_cr("---dump of L%d---",lidx);
2101 2270
2102 if( _ifg ) { 2271 if (_ifg) {
2103 if( lidx >= _maxlrg ) { 2272 if (lidx >= _lrg_map.max_lrg_id()) {
2104 tty->print("Attempt to print live range index beyond max live range.\n"); 2273 tty->print("Attempt to print live range index beyond max live range.\n");
2105 return; 2274 return;
2106 } 2275 }
2107 tty->print("L%d: ",lidx); 2276 tty->print("L%d: ",lidx);
2108 if( lidx < _ifg->_maxlrg ) lrgs(lidx).dump( ); 2277 if (lidx < _ifg->_maxlrg) {
2109 else tty->print_cr("new LRG"); 2278 lrgs(lidx).dump();
2279 } else {
2280 tty->print_cr("new LRG");
2281 }
2110 } 2282 }
2111 if( _ifg && lidx < _ifg->_maxlrg) { 2283 if( _ifg && lidx < _ifg->_maxlrg) {
2112 tty->print("Neighbors: %d - ", _ifg->neighbor_cnt(lidx)); 2284 tty->print("Neighbors: %d - ", _ifg->neighbor_cnt(lidx));
2113 _ifg->neighbors(lidx)->dump(); 2285 _ifg->neighbors(lidx)->dump();
2114 tty->cr(); 2286 tty->cr();
2119 int dump_once = 0; 2291 int dump_once = 0;
2120 2292
2121 // For all instructions 2293 // For all instructions
2122 for( uint j = 0; j < b->_nodes.size(); j++ ) { 2294 for( uint j = 0; j < b->_nodes.size(); j++ ) {
2123 Node *n = b->_nodes[j]; 2295 Node *n = b->_nodes[j];
2124 if( Find_const(n) == lidx ) { 2296 if (_lrg_map.find_const(n) == lidx) {
2125 if( !dump_once++ ) { 2297 if (!dump_once++) {
2126 tty->cr(); 2298 tty->cr();
2127 b->dump_head( &_cfg._bbs ); 2299 b->dump_head( &_cfg._bbs );
2128 } 2300 }
2129 dump(n); 2301 dump(n);
2130 continue; 2302 continue;
2131 } 2303 }
2132 if (!defs_only) { 2304 if (!defs_only) {
2133 uint cnt = n->req(); 2305 uint cnt = n->req();
2134 for( uint k = 1; k < cnt; k++ ) { 2306 for( uint k = 1; k < cnt; k++ ) {
2135 Node *m = n->in(k); 2307 Node *m = n->in(k);
2136 if (!m) continue; // be robust in the dumper 2308 if (!m) {
2137 if( Find_const(m) == lidx ) { 2309 continue; // be robust in the dumper
2138 if( !dump_once++ ) { 2310 }
2311 if (_lrg_map.find_const(m) == lidx) {
2312 if (!dump_once++) {
2139 tty->cr(); 2313 tty->cr();
2140 b->dump_head( &_cfg._bbs ); 2314 b->dump_head(&_cfg._bbs);
2141 } 2315 }
2142 dump(n); 2316 dump(n);
2143 } 2317 }
2144 } 2318 }
2145 } 2319 }