207 , _oldphi(unique) |
207 , _oldphi(unique) |
208 #ifndef PRODUCT |
208 #ifndef PRODUCT |
209 , _trace_spilling(TraceSpilling || C->method_has_option("TraceSpilling")) |
209 , _trace_spilling(TraceSpilling || C->method_has_option("TraceSpilling")) |
210 #endif |
210 #endif |
211 { |
211 { |
212 NOT_PRODUCT( Compile::TracePhase t3("ctorChaitin", &_t_ctorChaitin, TimeCompiler); ) |
212 Compile::TracePhase tp("ctorChaitin", &timers[_t_ctorChaitin]); |
213 |
213 |
214 _high_frequency_lrg = MIN2(double(OPTO_LRG_HIGH_FREQ), _cfg.get_outer_loop_frequency()); |
214 _high_frequency_lrg = MIN2(double(OPTO_LRG_HIGH_FREQ), _cfg.get_outer_loop_frequency()); |
215 |
215 |
216 // Build a list of basic blocks, sorted by frequency |
216 // Build a list of basic blocks, sorted by frequency |
217 _blks = NEW_RESOURCE_ARRAY(Block *, _cfg.number_of_blocks()); |
217 _blks = NEW_RESOURCE_ARRAY(Block *, _cfg.number_of_blocks()); |
293 return found_projs; |
293 return found_projs; |
294 } |
294 } |
295 |
295 |
296 // Renumber the live ranges to compact them. Makes the IFG smaller. |
296 // Renumber the live ranges to compact them. Makes the IFG smaller. |
297 void PhaseChaitin::compact() { |
297 void PhaseChaitin::compact() { |
|
298 Compile::TracePhase tp("chaitinCompact", &timers[_t_chaitinCompact]); |
|
299 |
298 // Current the _uf_map contains a series of short chains which are headed |
300 // Current the _uf_map contains a series of short chains which are headed |
299 // by a self-cycle. All the chains run from big numbers to little numbers. |
301 // by a self-cycle. All the chains run from big numbers to little numbers. |
300 // The Find() call chases the chains & shortens them for the next Find call. |
302 // The Find() call chases the chains & shortens them for the next Find call. |
301 // We are going to change this structure slightly. Numbers above a moving |
303 // We are going to change this structure slightly. Numbers above a moving |
302 // wave 'i' are unchanged. Numbers below 'j' point directly to their |
304 // wave 'i' are unchanged. Numbers below 'j' point directly to their |
367 // Veify the graph before RA. |
369 // Veify the graph before RA. |
368 verify(&live_arena); |
370 verify(&live_arena); |
369 #endif |
371 #endif |
370 |
372 |
371 { |
373 { |
372 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) |
374 Compile::TracePhase tp("computeLive", &timers[_t_computeLive]); |
373 _live = NULL; // Mark live as being not available |
375 _live = NULL; // Mark live as being not available |
374 rm.reset_to_mark(); // Reclaim working storage |
376 rm.reset_to_mark(); // Reclaim working storage |
375 IndexSet::reset_memory(C, &live_arena); |
377 IndexSet::reset_memory(C, &live_arena); |
376 ifg.init(_lrg_map.max_lrg_id()); // Empty IFG |
378 ifg.init(_lrg_map.max_lrg_id()); // Empty IFG |
377 gather_lrg_masks( false ); // Collect LRG masks |
379 gather_lrg_masks( false ); // Collect LRG masks |
384 // derived pointer is made, but not beyond. Really, they need to be live |
386 // derived pointer is made, but not beyond. Really, they need to be live |
385 // across any GC point where the derived value is live. So this code looks |
387 // across any GC point where the derived value is live. So this code looks |
386 // at all the GC points, and "stretches" the live range of any base pointer |
388 // at all the GC points, and "stretches" the live range of any base pointer |
387 // to the GC point. |
389 // to the GC point. |
388 if (stretch_base_pointer_live_ranges(&live_arena)) { |
390 if (stretch_base_pointer_live_ranges(&live_arena)) { |
389 NOT_PRODUCT(Compile::TracePhase t3("computeLive (sbplr)", &_t_computeLive, TimeCompiler);) |
391 Compile::TracePhase tp("computeLive (sbplr)", &timers[_t_computeLive]); |
390 // Since some live range stretched, I need to recompute live |
392 // Since some live range stretched, I need to recompute live |
391 _live = NULL; |
393 _live = NULL; |
392 rm.reset_to_mark(); // Reclaim working storage |
394 rm.reset_to_mark(); // Reclaim working storage |
393 IndexSet::reset_memory(C, &live_arena); |
395 IndexSet::reset_memory(C, &live_arena); |
394 ifg.init(_lrg_map.max_lrg_id()); |
396 ifg.init(_lrg_map.max_lrg_id()); |
397 _live = &live; |
399 _live = &live; |
398 } |
400 } |
399 // Create the interference graph using virtual copies |
401 // Create the interference graph using virtual copies |
400 build_ifg_virtual(); // Include stack slots this time |
402 build_ifg_virtual(); // Include stack slots this time |
401 |
403 |
|
404 // The IFG is/was triangular. I am 'squaring it up' so Union can run |
|
405 // faster. Union requires a 'for all' operation which is slow on the |
|
406 // triangular adjacency matrix (quick reminder: the IFG is 'sparse' - |
|
407 // meaning I can visit all the Nodes neighbors less than a Node in time |
|
408 // O(# of neighbors), but I have to visit all the Nodes greater than a |
|
409 // given Node and search them for an instance, i.e., time O(#MaxLRG)). |
|
410 _ifg->SquareUp(); |
|
411 |
402 // Aggressive (but pessimistic) copy coalescing. |
412 // Aggressive (but pessimistic) copy coalescing. |
403 // This pass works on virtual copies. Any virtual copies which are not |
413 // This pass works on virtual copies. Any virtual copies which are not |
404 // coalesced get manifested as actual copies |
414 // coalesced get manifested as actual copies |
405 { |
415 { |
406 // The IFG is/was triangular. I am 'squaring it up' so Union can run |
416 Compile::TracePhase tp("chaitinCoalesce1", &timers[_t_chaitinCoalesce1]); |
407 // faster. Union requires a 'for all' operation which is slow on the |
|
408 // triangular adjacency matrix (quick reminder: the IFG is 'sparse' - |
|
409 // meaning I can visit all the Nodes neighbors less than a Node in time |
|
410 // O(# of neighbors), but I have to visit all the Nodes greater than a |
|
411 // given Node and search them for an instance, i.e., time O(#MaxLRG)). |
|
412 _ifg->SquareUp(); |
|
413 |
417 |
414 PhaseAggressiveCoalesce coalesce(*this); |
418 PhaseAggressiveCoalesce coalesce(*this); |
415 coalesce.coalesce_driver(); |
419 coalesce.coalesce_driver(); |
416 // Insert un-coalesced copies. Visit all Phis. Where inputs to a Phi do |
420 // Insert un-coalesced copies. Visit all Phis. Where inputs to a Phi do |
417 // not match the Phi itself, insert a copy. |
421 // not match the Phi itself, insert a copy. |
422 } |
426 } |
423 |
427 |
424 // After aggressive coalesce, attempt a first cut at coloring. |
428 // After aggressive coalesce, attempt a first cut at coloring. |
425 // To color, we need the IFG and for that we need LIVE. |
429 // To color, we need the IFG and for that we need LIVE. |
426 { |
430 { |
427 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) |
431 Compile::TracePhase tp("computeLive", &timers[_t_computeLive]); |
428 _live = NULL; |
432 _live = NULL; |
429 rm.reset_to_mark(); // Reclaim working storage |
433 rm.reset_to_mark(); // Reclaim working storage |
430 IndexSet::reset_memory(C, &live_arena); |
434 IndexSet::reset_memory(C, &live_arena); |
431 ifg.init(_lrg_map.max_lrg_id()); |
435 ifg.init(_lrg_map.max_lrg_id()); |
432 gather_lrg_masks( true ); |
436 gather_lrg_masks( true ); |
460 NOT_PRODUCT(C->verify_graph_edges();) |
464 NOT_PRODUCT(C->verify_graph_edges();) |
461 |
465 |
462 compact(); // Compact LRGs; return new lower max lrg |
466 compact(); // Compact LRGs; return new lower max lrg |
463 |
467 |
464 { |
468 { |
465 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) |
469 Compile::TracePhase tp("computeLive", &timers[_t_computeLive]); |
466 _live = NULL; |
470 _live = NULL; |
467 rm.reset_to_mark(); // Reclaim working storage |
471 rm.reset_to_mark(); // Reclaim working storage |
468 IndexSet::reset_memory(C, &live_arena); |
472 IndexSet::reset_memory(C, &live_arena); |
469 ifg.init(_lrg_map.max_lrg_id()); // Build a new interference graph |
473 ifg.init(_lrg_map.max_lrg_id()); // Build a new interference graph |
470 gather_lrg_masks( true ); // Collect intersect mask |
474 gather_lrg_masks( true ); // Collect intersect mask |
474 build_ifg_physical(&live_arena); |
478 build_ifg_physical(&live_arena); |
475 _ifg->SquareUp(); |
479 _ifg->SquareUp(); |
476 _ifg->Compute_Effective_Degree(); |
480 _ifg->Compute_Effective_Degree(); |
477 // Only do conservative coalescing if requested |
481 // Only do conservative coalescing if requested |
478 if (OptoCoalesce) { |
482 if (OptoCoalesce) { |
|
483 Compile::TracePhase tp("chaitinCoalesce2", &timers[_t_chaitinCoalesce2]); |
479 // Conservative (and pessimistic) copy coalescing of those spills |
484 // Conservative (and pessimistic) copy coalescing of those spills |
480 PhaseConservativeCoalesce coalesce(*this); |
485 PhaseConservativeCoalesce coalesce(*this); |
481 // If max live ranges greater than cutoff, don't color the stack. |
486 // If max live ranges greater than cutoff, don't color the stack. |
482 // This cutoff can be larger than below since it is only done once. |
487 // This cutoff can be larger than below since it is only done once. |
483 coalesce.coalesce_driver(); |
488 coalesce.coalesce_driver(); |
529 |
534 |
530 compact(); // Compact LRGs; return new lower max lrg |
535 compact(); // Compact LRGs; return new lower max lrg |
531 |
536 |
532 // Nuke the live-ness and interference graph and LiveRanGe info |
537 // Nuke the live-ness and interference graph and LiveRanGe info |
533 { |
538 { |
534 NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); ) |
539 Compile::TracePhase tp("computeLive", &timers[_t_computeLive]); |
535 _live = NULL; |
540 _live = NULL; |
536 rm.reset_to_mark(); // Reclaim working storage |
541 rm.reset_to_mark(); // Reclaim working storage |
537 IndexSet::reset_memory(C, &live_arena); |
542 IndexSet::reset_memory(C, &live_arena); |
538 ifg.init(_lrg_map.max_lrg_id()); |
543 ifg.init(_lrg_map.max_lrg_id()); |
539 |
544 |
547 _ifg->SquareUp(); |
552 _ifg->SquareUp(); |
548 _ifg->Compute_Effective_Degree(); |
553 _ifg->Compute_Effective_Degree(); |
549 |
554 |
550 // Only do conservative coalescing if requested |
555 // Only do conservative coalescing if requested |
551 if (OptoCoalesce) { |
556 if (OptoCoalesce) { |
|
557 Compile::TracePhase tp("chaitinCoalesce3", &timers[_t_chaitinCoalesce3]); |
552 // Conservative (and pessimistic) copy coalescing |
558 // Conservative (and pessimistic) copy coalescing |
553 PhaseConservativeCoalesce coalesce(*this); |
559 PhaseConservativeCoalesce coalesce(*this); |
554 // Check for few live ranges determines how aggressive coalesce is. |
560 // Check for few live ranges determines how aggressive coalesce is. |
555 coalesce.coalesce_driver(); |
561 coalesce.coalesce_driver(); |
556 } |
562 } |
1052 |
1058 |
1053 #define REGISTER_CONSTRAINED 16 |
1059 #define REGISTER_CONSTRAINED 16 |
1054 |
1060 |
1055 // Compute cost/area ratio, in case we spill. Build the lo-degree list. |
1061 // Compute cost/area ratio, in case we spill. Build the lo-degree list. |
1056 void PhaseChaitin::cache_lrg_info( ) { |
1062 void PhaseChaitin::cache_lrg_info( ) { |
|
1063 Compile::TracePhase tp("chaitinCacheLRG", &timers[_t_chaitinCacheLRG]); |
1057 |
1064 |
1058 for (uint i = 1; i < _lrg_map.max_lrg_id(); i++) { |
1065 for (uint i = 1; i < _lrg_map.max_lrg_id(); i++) { |
1059 LRG &lrg = lrgs(i); |
1066 LRG &lrg = lrgs(i); |
1060 |
1067 |
1061 // Check for being of low degree: means we can be trivially colored. |
1068 // Check for being of low degree: means we can be trivially colored. |
1135 // No more lo-degree no-copy live ranges to simplify |
1142 // No more lo-degree no-copy live ranges to simplify |
1136 } |
1143 } |
1137 |
1144 |
1138 // Simplify the IFG by removing LRGs of low degree. |
1145 // Simplify the IFG by removing LRGs of low degree. |
1139 void PhaseChaitin::Simplify( ) { |
1146 void PhaseChaitin::Simplify( ) { |
|
1147 Compile::TracePhase tp("chaitinSimplify", &timers[_t_chaitinSimplify]); |
1140 |
1148 |
1141 while( 1 ) { // Repeat till simplified it all |
1149 while( 1 ) { // Repeat till simplified it all |
1142 // May want to explore simplifying lo_degree before _lo_stk_degree. |
1150 // May want to explore simplifying lo_degree before _lo_stk_degree. |
1143 // This might result in more spills coloring into registers during |
1151 // This might result in more spills coloring into registers during |
1144 // Select(). |
1152 // Select(). |
1382 // Select colors by re-inserting LRGs back into the IFG. LRGs are re-inserted |
1390 // Select colors by re-inserting LRGs back into the IFG. LRGs are re-inserted |
1383 // in reverse order of removal. As long as nothing of hi-degree was yanked, |
1391 // in reverse order of removal. As long as nothing of hi-degree was yanked, |
1384 // everything going back is guaranteed a color. Select that color. If some |
1392 // everything going back is guaranteed a color. Select that color. If some |
1385 // hi-degree LRG cannot get a color then we record that we must spill. |
1393 // hi-degree LRG cannot get a color then we record that we must spill. |
1386 uint PhaseChaitin::Select( ) { |
1394 uint PhaseChaitin::Select( ) { |
|
1395 Compile::TracePhase tp("chaitinSelect", &timers[_t_chaitinSelect]); |
|
1396 |
1387 uint spill_reg = LRG::SPILL_REG; |
1397 uint spill_reg = LRG::SPILL_REG; |
1388 _max_reg = OptoReg::Name(0); // Past max register used |
1398 _max_reg = OptoReg::Name(0); // Past max register used |
1389 while( _simplified ) { |
1399 while( _simplified ) { |
1390 // Pull next LRG from the simplified list - in reverse order of removal |
1400 // Pull next LRG from the simplified list - in reverse order of removal |
1391 uint lidx = _simplified; |
1401 uint lidx = _simplified; |
1575 // Stores. Use-def chains are NOT preserved, but Node->LRG->reg maps are. |
1585 // Stores. Use-def chains are NOT preserved, but Node->LRG->reg maps are. |
1576 void PhaseChaitin::fixup_spills() { |
1586 void PhaseChaitin::fixup_spills() { |
1577 // This function does only cisc spill work. |
1587 // This function does only cisc spill work. |
1578 if( !UseCISCSpill ) return; |
1588 if( !UseCISCSpill ) return; |
1579 |
1589 |
1580 NOT_PRODUCT( Compile::TracePhase t3("fixupSpills", &_t_fixupSpills, TimeCompiler); ) |
1590 Compile::TracePhase tp("fixupSpills", &timers[_t_fixupSpills]); |
1581 |
1591 |
1582 // Grab the Frame Pointer |
1592 // Grab the Frame Pointer |
1583 Node *fp = _cfg.get_root_block()->head()->in(1)->in(TypeFunc::FramePtr); |
1593 Node *fp = _cfg.get_root_block()->head()->in(1)->in(TypeFunc::FramePtr); |
1584 |
1594 |
1585 // For all blocks |
1595 // For all blocks |