Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/ifg.cpp @ 12071:adb9a7d94cb5
8023003: Cleanup the public interface to PhaseCFG
Summary: public methods that don't need to be public should be private.
Reviewed-by: kvn, twisti
author | adlertz |
---|---|
date | Fri, 16 Aug 2013 10:23:55 +0200 |
parents | d1034bd8cefc |
children | 650868c062a9 |
comparison
equal
deleted
inserted
replaced
12070:afbe18ae0905 | 12071:adb9a7d94cb5 |
---|---|
35 #include "opto/indexSet.hpp" | 35 #include "opto/indexSet.hpp" |
36 #include "opto/machnode.hpp" | 36 #include "opto/machnode.hpp" |
37 #include "opto/memnode.hpp" | 37 #include "opto/memnode.hpp" |
38 #include "opto/opcodes.hpp" | 38 #include "opto/opcodes.hpp" |
39 | 39 |
40 //============================================================================= | |
41 //------------------------------IFG-------------------------------------------- | |
42 PhaseIFG::PhaseIFG( Arena *arena ) : Phase(Interference_Graph), _arena(arena) { | 40 PhaseIFG::PhaseIFG( Arena *arena ) : Phase(Interference_Graph), _arena(arena) { |
43 } | 41 } |
44 | 42 |
45 //------------------------------init------------------------------------------- | |
46 void PhaseIFG::init( uint maxlrg ) { | 43 void PhaseIFG::init( uint maxlrg ) { |
47 _maxlrg = maxlrg; | 44 _maxlrg = maxlrg; |
48 _yanked = new (_arena) VectorSet(_arena); | 45 _yanked = new (_arena) VectorSet(_arena); |
49 _is_square = false; | 46 _is_square = false; |
50 // Make uninitialized adjacency lists | 47 // Make uninitialized adjacency lists |
57 _adjs[i].initialize(maxlrg); | 54 _adjs[i].initialize(maxlrg); |
58 _lrgs[i].Set_All(); | 55 _lrgs[i].Set_All(); |
59 } | 56 } |
60 } | 57 } |
61 | 58 |
62 //------------------------------add-------------------------------------------- | |
63 // Add edge between vertices a & b. These are sorted (triangular matrix), | 59 // Add edge between vertices a & b. These are sorted (triangular matrix), |
64 // then the smaller number is inserted in the larger numbered array. | 60 // then the smaller number is inserted in the larger numbered array. |
65 int PhaseIFG::add_edge( uint a, uint b ) { | 61 int PhaseIFG::add_edge( uint a, uint b ) { |
66 lrgs(a).invalid_degree(); | 62 lrgs(a).invalid_degree(); |
67 lrgs(b).invalid_degree(); | 63 lrgs(b).invalid_degree(); |
69 assert( !_is_square, "only on triangular" ); | 65 assert( !_is_square, "only on triangular" ); |
70 if( a < b ) { uint tmp = a; a = b; b = tmp; } | 66 if( a < b ) { uint tmp = a; a = b; b = tmp; } |
71 return _adjs[a].insert( b ); | 67 return _adjs[a].insert( b ); |
72 } | 68 } |
73 | 69 |
74 //------------------------------add_vector------------------------------------- | |
75 // Add an edge between 'a' and everything in the vector. | 70 // Add an edge between 'a' and everything in the vector. |
76 void PhaseIFG::add_vector( uint a, IndexSet *vec ) { | 71 void PhaseIFG::add_vector( uint a, IndexSet *vec ) { |
77 // IFG is triangular, so do the inserts where 'a' < 'b'. | 72 // IFG is triangular, so do the inserts where 'a' < 'b'. |
78 assert( !_is_square, "only on triangular" ); | 73 assert( !_is_square, "only on triangular" ); |
79 IndexSet *adjs_a = &_adjs[a]; | 74 IndexSet *adjs_a = &_adjs[a]; |
84 while ((neighbor = elements.next()) != 0) { | 79 while ((neighbor = elements.next()) != 0) { |
85 add_edge( a, neighbor ); | 80 add_edge( a, neighbor ); |
86 } | 81 } |
87 } | 82 } |
88 | 83 |
89 //------------------------------test------------------------------------------- | |
90 // Is there an edge between a and b? | 84 // Is there an edge between a and b? |
91 int PhaseIFG::test_edge( uint a, uint b ) const { | 85 int PhaseIFG::test_edge( uint a, uint b ) const { |
92 // Sort a and b, so that a is larger | 86 // Sort a and b, so that a is larger |
93 assert( !_is_square, "only on triangular" ); | 87 assert( !_is_square, "only on triangular" ); |
94 if( a < b ) { uint tmp = a; a = b; b = tmp; } | 88 if( a < b ) { uint tmp = a; a = b; b = tmp; } |
95 return _adjs[a].member(b); | 89 return _adjs[a].member(b); |
96 } | 90 } |
97 | 91 |
98 //------------------------------SquareUp--------------------------------------- | |
99 // Convert triangular matrix to square matrix | 92 // Convert triangular matrix to square matrix |
100 void PhaseIFG::SquareUp() { | 93 void PhaseIFG::SquareUp() { |
101 assert( !_is_square, "only on triangular" ); | 94 assert( !_is_square, "only on triangular" ); |
102 | 95 |
103 // Simple transpose | 96 // Simple transpose |
109 } | 102 } |
110 } | 103 } |
111 _is_square = true; | 104 _is_square = true; |
112 } | 105 } |
113 | 106 |
114 //------------------------------Compute_Effective_Degree----------------------- | |
115 // Compute effective degree in bulk | 107 // Compute effective degree in bulk |
116 void PhaseIFG::Compute_Effective_Degree() { | 108 void PhaseIFG::Compute_Effective_Degree() { |
117 assert( _is_square, "only on square" ); | 109 assert( _is_square, "only on square" ); |
118 | 110 |
119 for( uint i = 0; i < _maxlrg; i++ ) | 111 for( uint i = 0; i < _maxlrg; i++ ) |
120 lrgs(i).set_degree(effective_degree(i)); | 112 lrgs(i).set_degree(effective_degree(i)); |
121 } | 113 } |
122 | 114 |
123 //------------------------------test_edge_sq----------------------------------- | |
124 int PhaseIFG::test_edge_sq( uint a, uint b ) const { | 115 int PhaseIFG::test_edge_sq( uint a, uint b ) const { |
125 assert( _is_square, "only on square" ); | 116 assert( _is_square, "only on square" ); |
126 // Swap, so that 'a' has the lesser count. Then binary search is on | 117 // Swap, so that 'a' has the lesser count. Then binary search is on |
127 // the smaller of a's list and b's list. | 118 // the smaller of a's list and b's list. |
128 if( neighbor_cnt(a) > neighbor_cnt(b) ) { uint tmp = a; a = b; b = tmp; } | 119 if( neighbor_cnt(a) > neighbor_cnt(b) ) { uint tmp = a; a = b; b = tmp; } |
129 //return _adjs[a].unordered_member(b); | 120 //return _adjs[a].unordered_member(b); |
130 return _adjs[a].member(b); | 121 return _adjs[a].member(b); |
131 } | 122 } |
132 | 123 |
133 //------------------------------Union------------------------------------------ | |
134 // Union edges of B into A | 124 // Union edges of B into A |
135 void PhaseIFG::Union( uint a, uint b ) { | 125 void PhaseIFG::Union( uint a, uint b ) { |
136 assert( _is_square, "only on square" ); | 126 assert( _is_square, "only on square" ); |
137 IndexSet *A = &_adjs[a]; | 127 IndexSet *A = &_adjs[a]; |
138 IndexSetIterator b_elements(&_adjs[b]); | 128 IndexSetIterator b_elements(&_adjs[b]); |
144 lrgs(datum).invalid_degree(); | 134 lrgs(datum).invalid_degree(); |
145 } | 135 } |
146 } | 136 } |
147 } | 137 } |
148 | 138 |
149 //------------------------------remove_node------------------------------------ | |
150 // Yank a Node and all connected edges from the IFG. Return a | 139 // Yank a Node and all connected edges from the IFG. Return a |
151 // list of neighbors (edges) yanked. | 140 // list of neighbors (edges) yanked. |
152 IndexSet *PhaseIFG::remove_node( uint a ) { | 141 IndexSet *PhaseIFG::remove_node( uint a ) { |
153 assert( _is_square, "only on square" ); | 142 assert( _is_square, "only on square" ); |
154 assert( !_yanked->test(a), "" ); | 143 assert( !_yanked->test(a), "" ); |
163 lrgs(datum).inc_degree( -lrg_a.compute_degree(lrgs(datum)) ); | 152 lrgs(datum).inc_degree( -lrg_a.compute_degree(lrgs(datum)) ); |
164 } | 153 } |
165 return neighbors(a); | 154 return neighbors(a); |
166 } | 155 } |
167 | 156 |
168 //------------------------------re_insert-------------------------------------- | |
169 // Re-insert a yanked Node. | 157 // Re-insert a yanked Node. |
170 void PhaseIFG::re_insert( uint a ) { | 158 void PhaseIFG::re_insert( uint a ) { |
171 assert( _is_square, "only on square" ); | 159 assert( _is_square, "only on square" ); |
172 assert( _yanked->test(a), "" ); | 160 assert( _yanked->test(a), "" ); |
173 (*_yanked) >>= a; | 161 (*_yanked) >>= a; |
178 _adjs[datum].insert(a); | 166 _adjs[datum].insert(a); |
179 lrgs(datum).invalid_degree(); | 167 lrgs(datum).invalid_degree(); |
180 } | 168 } |
181 } | 169 } |
182 | 170 |
183 //------------------------------compute_degree--------------------------------- | |
184 // Compute the degree between 2 live ranges. If both live ranges are | 171 // Compute the degree between 2 live ranges. If both live ranges are |
185 // aligned-adjacent powers-of-2 then we use the MAX size. If either is | 172 // aligned-adjacent powers-of-2 then we use the MAX size. If either is |
186 // mis-aligned (or for Fat-Projections, not-adjacent) then we have to | 173 // mis-aligned (or for Fat-Projections, not-adjacent) then we have to |
187 // MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why | 174 // MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why |
188 // this is so. | 175 // this is so. |
194 ? (num_regs * nregs) // then use product | 181 ? (num_regs * nregs) // then use product |
195 : MAX2(num_regs,nregs); // else use max | 182 : MAX2(num_regs,nregs); // else use max |
196 return tmp; | 183 return tmp; |
197 } | 184 } |
198 | 185 |
199 //------------------------------effective_degree------------------------------- | |
200 // Compute effective degree for this live range. If both live ranges are | 186 // Compute effective degree for this live range. If both live ranges are |
201 // aligned-adjacent powers-of-2 then we use the MAX size. If either is | 187 // aligned-adjacent powers-of-2 then we use the MAX size. If either is |
202 // mis-aligned (or for Fat-Projections, not-adjacent) then we have to | 188 // mis-aligned (or for Fat-Projections, not-adjacent) then we have to |
203 // MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why | 189 // MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why |
204 // this is so. | 190 // this is so. |
219 return eff; | 205 return eff; |
220 } | 206 } |
221 | 207 |
222 | 208 |
223 #ifndef PRODUCT | 209 #ifndef PRODUCT |
224 //------------------------------dump------------------------------------------- | |
225 void PhaseIFG::dump() const { | 210 void PhaseIFG::dump() const { |
226 tty->print_cr("-- Interference Graph --%s--", | 211 tty->print_cr("-- Interference Graph --%s--", |
227 _is_square ? "square" : "triangular" ); | 212 _is_square ? "square" : "triangular" ); |
228 if( _is_square ) { | 213 if( _is_square ) { |
229 for( uint i = 0; i < _maxlrg; i++ ) { | 214 for( uint i = 0; i < _maxlrg; i++ ) { |
258 tty->print("}\n"); | 243 tty->print("}\n"); |
259 } | 244 } |
260 tty->print("\n"); | 245 tty->print("\n"); |
261 } | 246 } |
262 | 247 |
263 //------------------------------stats------------------------------------------ | |
264 void PhaseIFG::stats() const { | 248 void PhaseIFG::stats() const { |
265 ResourceMark rm; | 249 ResourceMark rm; |
266 int *h_cnt = NEW_RESOURCE_ARRAY(int,_maxlrg*2); | 250 int *h_cnt = NEW_RESOURCE_ARRAY(int,_maxlrg*2); |
267 memset( h_cnt, 0, sizeof(int)*_maxlrg*2 ); | 251 memset( h_cnt, 0, sizeof(int)*_maxlrg*2 ); |
268 uint i; | 252 uint i; |
274 if( h_cnt[i] ) | 258 if( h_cnt[i] ) |
275 tty->print("%d/%d ",i,h_cnt[i]); | 259 tty->print("%d/%d ",i,h_cnt[i]); |
276 tty->print_cr(""); | 260 tty->print_cr(""); |
277 } | 261 } |
278 | 262 |
279 //------------------------------verify----------------------------------------- | |
280 void PhaseIFG::verify( const PhaseChaitin *pc ) const { | 263 void PhaseIFG::verify( const PhaseChaitin *pc ) const { |
281 // IFG is square, sorted and no need for Find | 264 // IFG is square, sorted and no need for Find |
282 for( uint i = 0; i < _maxlrg; i++ ) { | 265 for( uint i = 0; i < _maxlrg; i++ ) { |
283 assert(!((*_yanked)[i]) || !neighbor_cnt(i), "Is removed completely" ); | 266 assert(!((*_yanked)[i]) || !neighbor_cnt(i), "Is removed completely" ); |
284 IndexSet *set = &_adjs[i]; | 267 IndexSet *set = &_adjs[i]; |
296 assert(!lrgs(i)._degree_valid || effective_degree(i) == lrgs(i).degree(), "degree is valid but wrong"); | 279 assert(!lrgs(i)._degree_valid || effective_degree(i) == lrgs(i).degree(), "degree is valid but wrong"); |
297 } | 280 } |
298 } | 281 } |
299 #endif | 282 #endif |
300 | 283 |
301 //------------------------------interfere_with_live---------------------------- | |
302 // Interfere this register with everything currently live. Use the RegMasks | 284 // Interfere this register with everything currently live. Use the RegMasks |
303 // to trim the set of possible interferences. Return a count of register-only | 285 // to trim the set of possible interferences. Return a count of register-only |
304 // interferences as an estimate of register pressure. | 286 // interferences as an estimate of register pressure. |
305 void PhaseChaitin::interfere_with_live( uint r, IndexSet *liveout ) { | 287 void PhaseChaitin::interfere_with_live( uint r, IndexSet *liveout ) { |
306 uint retval = 0; | 288 uint retval = 0; |
313 while( (l = elements.next()) != 0 ) | 295 while( (l = elements.next()) != 0 ) |
314 if( rm.overlap( lrgs(l).mask() ) ) | 296 if( rm.overlap( lrgs(l).mask() ) ) |
315 _ifg->add_edge( r, l ); | 297 _ifg->add_edge( r, l ); |
316 } | 298 } |
317 | 299 |
318 //------------------------------build_ifg_virtual------------------------------ | |
319 // Actually build the interference graph. Uses virtual registers only, no | 300 // Actually build the interference graph. Uses virtual registers only, no |
320 // physical register masks. This allows me to be very aggressive when | 301 // physical register masks. This allows me to be very aggressive when |
321 // coalescing copies. Some of this aggressiveness will have to be undone | 302 // coalescing copies. Some of this aggressiveness will have to be undone |
322 // later, but I'd rather get all the copies I can now (since unremoved copies | 303 // later, but I'd rather get all the copies I can now (since unremoved copies |
323 // at this point can end up in bad places). Copies I re-insert later I have | 304 // at this point can end up in bad places). Copies I re-insert later I have |
324 // more opportunity to insert them in low-frequency locations. | 305 // more opportunity to insert them in low-frequency locations. |
325 void PhaseChaitin::build_ifg_virtual( ) { | 306 void PhaseChaitin::build_ifg_virtual( ) { |
326 | 307 |
327 // For all blocks (in any order) do... | 308 // For all blocks (in any order) do... |
328 for( uint i=0; i<_cfg._num_blocks; i++ ) { | 309 for (uint i = 0; i < _cfg.number_of_blocks(); i++) { |
329 Block *b = _cfg._blocks[i]; | 310 Block* block = _cfg.get_block(i); |
330 IndexSet *liveout = _live->live(b); | 311 IndexSet* liveout = _live->live(block); |
331 | 312 |
332 // The IFG is built by a single reverse pass over each basic block. | 313 // The IFG is built by a single reverse pass over each basic block. |
333 // Starting with the known live-out set, we remove things that get | 314 // Starting with the known live-out set, we remove things that get |
334 // defined and add things that become live (essentially executing one | 315 // defined and add things that become live (essentially executing one |
335 // pass of a standard LIVE analysis). Just before a Node defines a value | 316 // pass of a standard LIVE analysis). Just before a Node defines a value |
336 // (and removes it from the live-ness set) that value is certainly live. | 317 // (and removes it from the live-ness set) that value is certainly live. |
337 // The defined value interferes with everything currently live. The | 318 // The defined value interferes with everything currently live. The |
338 // value is then removed from the live-ness set and it's inputs are | 319 // value is then removed from the live-ness set and it's inputs are |
339 // added to the live-ness set. | 320 // added to the live-ness set. |
340 for( uint j = b->end_idx() + 1; j > 1; j-- ) { | 321 for (uint j = block->end_idx() + 1; j > 1; j--) { |
341 Node *n = b->_nodes[j-1]; | 322 Node* n = block->_nodes[j - 1]; |
342 | 323 |
343 // Get value being defined | 324 // Get value being defined |
344 uint r = _lrg_map.live_range_id(n); | 325 uint r = _lrg_map.live_range_id(n); |
345 | 326 |
346 // Some special values do not allocate | 327 // Some special values do not allocate |
406 } | 387 } |
407 } // End of forall instructions in block | 388 } // End of forall instructions in block |
408 } // End of forall blocks | 389 } // End of forall blocks |
409 } | 390 } |
410 | 391 |
411 //------------------------------count_int_pressure----------------------------- | |
412 uint PhaseChaitin::count_int_pressure( IndexSet *liveout ) { | 392 uint PhaseChaitin::count_int_pressure( IndexSet *liveout ) { |
413 IndexSetIterator elements(liveout); | 393 IndexSetIterator elements(liveout); |
414 uint lidx; | 394 uint lidx; |
415 uint cnt = 0; | 395 uint cnt = 0; |
416 while ((lidx = elements.next()) != 0) { | 396 while ((lidx = elements.next()) != 0) { |
422 cnt += lrgs(lidx).reg_pressure(); | 402 cnt += lrgs(lidx).reg_pressure(); |
423 } | 403 } |
424 return cnt; | 404 return cnt; |
425 } | 405 } |
426 | 406 |
427 //------------------------------count_float_pressure--------------------------- | |
428 uint PhaseChaitin::count_float_pressure( IndexSet *liveout ) { | 407 uint PhaseChaitin::count_float_pressure( IndexSet *liveout ) { |
429 IndexSetIterator elements(liveout); | 408 IndexSetIterator elements(liveout); |
430 uint lidx; | 409 uint lidx; |
431 uint cnt = 0; | 410 uint cnt = 0; |
432 while ((lidx = elements.next()) != 0) { | 411 while ((lidx = elements.next()) != 0) { |
436 cnt += lrgs(lidx).reg_pressure(); | 415 cnt += lrgs(lidx).reg_pressure(); |
437 } | 416 } |
438 return cnt; | 417 return cnt; |
439 } | 418 } |
440 | 419 |
441 //------------------------------lower_pressure--------------------------------- | |
442 // Adjust register pressure down by 1. Capture last hi-to-low transition, | 420 // Adjust register pressure down by 1. Capture last hi-to-low transition, |
443 static void lower_pressure( LRG *lrg, uint where, Block *b, uint *pressure, uint *hrp_index ) { | 421 static void lower_pressure( LRG *lrg, uint where, Block *b, uint *pressure, uint *hrp_index ) { |
444 if (lrg->mask().is_UP() && lrg->mask_size()) { | 422 if (lrg->mask().is_UP() && lrg->mask_size()) { |
445 if (lrg->_is_float || lrg->_is_vector) { | 423 if (lrg->_is_float || lrg->_is_vector) { |
446 pressure[1] -= lrg->reg_pressure(); | 424 pressure[1] -= lrg->reg_pressure(); |
458 } | 436 } |
459 } | 437 } |
460 } | 438 } |
461 } | 439 } |
462 | 440 |
463 //------------------------------build_ifg_physical----------------------------- | |
464 // Build the interference graph using physical registers when available. | 441 // Build the interference graph using physical registers when available. |
465 // That is, if 2 live ranges are simultaneously alive but in their acceptable | 442 // That is, if 2 live ranges are simultaneously alive but in their acceptable |
466 // register sets do not overlap, then they do not interfere. | 443 // register sets do not overlap, then they do not interfere. |
467 uint PhaseChaitin::build_ifg_physical( ResourceArea *a ) { | 444 uint PhaseChaitin::build_ifg_physical( ResourceArea *a ) { |
468 NOT_PRODUCT( Compile::TracePhase t3("buildIFG", &_t_buildIFGphysical, TimeCompiler); ) | 445 NOT_PRODUCT( Compile::TracePhase t3("buildIFG", &_t_buildIFGphysical, TimeCompiler); ) |
469 | 446 |
470 uint spill_reg = LRG::SPILL_REG; | |
471 uint must_spill = 0; | 447 uint must_spill = 0; |
472 | 448 |
473 // For all blocks (in any order) do... | 449 // For all blocks (in any order) do... |
474 for( uint i = 0; i < _cfg._num_blocks; i++ ) { | 450 for (uint i = 0; i < _cfg.number_of_blocks(); i++) { |
475 Block *b = _cfg._blocks[i]; | 451 Block* block = _cfg.get_block(i); |
476 // Clone (rather than smash in place) the liveout info, so it is alive | 452 // Clone (rather than smash in place) the liveout info, so it is alive |
477 // for the "collect_gc_info" phase later. | 453 // for the "collect_gc_info" phase later. |
478 IndexSet liveout(_live->live(b)); | 454 IndexSet liveout(_live->live(block)); |
479 uint last_inst = b->end_idx(); | 455 uint last_inst = block->end_idx(); |
480 // Compute first nonphi node index | 456 // Compute first nonphi node index |
481 uint first_inst; | 457 uint first_inst; |
482 for( first_inst = 1; first_inst < last_inst; first_inst++ ) | 458 for (first_inst = 1; first_inst < last_inst; first_inst++) { |
483 if( !b->_nodes[first_inst]->is_Phi() ) | 459 if (!block->_nodes[first_inst]->is_Phi()) { |
484 break; | 460 break; |
461 } | |
462 } | |
485 | 463 |
486 // Spills could be inserted before CreateEx node which should be | 464 // Spills could be inserted before CreateEx node which should be |
487 // first instruction in block after Phis. Move CreateEx up. | 465 // first instruction in block after Phis. Move CreateEx up. |
488 for( uint insidx = first_inst; insidx < last_inst; insidx++ ) { | 466 for (uint insidx = first_inst; insidx < last_inst; insidx++) { |
489 Node *ex = b->_nodes[insidx]; | 467 Node *ex = block->_nodes[insidx]; |
490 if( ex->is_SpillCopy() ) continue; | 468 if (ex->is_SpillCopy()) { |
491 if( insidx > first_inst && ex->is_Mach() && | 469 continue; |
492 ex->as_Mach()->ideal_Opcode() == Op_CreateEx ) { | 470 } |
471 if (insidx > first_inst && ex->is_Mach() && ex->as_Mach()->ideal_Opcode() == Op_CreateEx) { | |
493 // If the CreateEx isn't above all the MachSpillCopies | 472 // If the CreateEx isn't above all the MachSpillCopies |
494 // then move it to the top. | 473 // then move it to the top. |
495 b->_nodes.remove(insidx); | 474 block->_nodes.remove(insidx); |
496 b->_nodes.insert(first_inst, ex); | 475 block->_nodes.insert(first_inst, ex); |
497 } | 476 } |
498 // Stop once a CreateEx or any other node is found | 477 // Stop once a CreateEx or any other node is found |
499 break; | 478 break; |
500 } | 479 } |
501 | 480 |
502 // Reset block's register pressure values for each ifg construction | 481 // Reset block's register pressure values for each ifg construction |
503 uint pressure[2], hrp_index[2]; | 482 uint pressure[2], hrp_index[2]; |
504 pressure[0] = pressure[1] = 0; | 483 pressure[0] = pressure[1] = 0; |
505 hrp_index[0] = hrp_index[1] = last_inst+1; | 484 hrp_index[0] = hrp_index[1] = last_inst+1; |
506 b->_reg_pressure = b->_freg_pressure = 0; | 485 block->_reg_pressure = block->_freg_pressure = 0; |
507 // Liveout things are presumed live for the whole block. We accumulate | 486 // Liveout things are presumed live for the whole block. We accumulate |
508 // 'area' accordingly. If they get killed in the block, we'll subtract | 487 // 'area' accordingly. If they get killed in the block, we'll subtract |
509 // the unused part of the block from the area. | 488 // the unused part of the block from the area. |
510 int inst_count = last_inst - first_inst; | 489 int inst_count = last_inst - first_inst; |
511 double cost = (inst_count <= 0) ? 0.0 : b->_freq * double(inst_count); | 490 double cost = (inst_count <= 0) ? 0.0 : block->_freq * double(inst_count); |
512 assert(!(cost < 0.0), "negative spill cost" ); | 491 assert(!(cost < 0.0), "negative spill cost" ); |
513 IndexSetIterator elements(&liveout); | 492 IndexSetIterator elements(&liveout); |
514 uint lidx; | 493 uint lidx; |
515 while ((lidx = elements.next()) != 0) { | 494 while ((lidx = elements.next()) != 0) { |
516 LRG &lrg = lrgs(lidx); | 495 LRG &lrg = lrgs(lidx); |
517 lrg._area += cost; | 496 lrg._area += cost; |
518 // Compute initial register pressure | 497 // Compute initial register pressure |
519 if (lrg.mask().is_UP() && lrg.mask_size()) { | 498 if (lrg.mask().is_UP() && lrg.mask_size()) { |
520 if (lrg._is_float || lrg._is_vector) { // Count float pressure | 499 if (lrg._is_float || lrg._is_vector) { // Count float pressure |
521 pressure[1] += lrg.reg_pressure(); | 500 pressure[1] += lrg.reg_pressure(); |
522 if( pressure[1] > b->_freg_pressure ) | 501 if (pressure[1] > block->_freg_pressure) { |
523 b->_freg_pressure = pressure[1]; | 502 block->_freg_pressure = pressure[1]; |
503 } | |
524 // Count int pressure, but do not count the SP, flags | 504 // Count int pressure, but do not count the SP, flags |
525 } else if( lrgs(lidx).mask().overlap(*Matcher::idealreg2regmask[Op_RegI]) ) { | 505 } else if(lrgs(lidx).mask().overlap(*Matcher::idealreg2regmask[Op_RegI])) { |
526 pressure[0] += lrg.reg_pressure(); | 506 pressure[0] += lrg.reg_pressure(); |
527 if( pressure[0] > b->_reg_pressure ) | 507 if (pressure[0] > block->_reg_pressure) { |
528 b->_reg_pressure = pressure[0]; | 508 block->_reg_pressure = pressure[0]; |
509 } | |
529 } | 510 } |
530 } | 511 } |
531 } | 512 } |
532 assert( pressure[0] == count_int_pressure (&liveout), "" ); | 513 assert( pressure[0] == count_int_pressure (&liveout), "" ); |
533 assert( pressure[1] == count_float_pressure(&liveout), "" ); | 514 assert( pressure[1] == count_float_pressure(&liveout), "" ); |
539 // (and removes it from the live-ness set) that value is certainly live. | 520 // (and removes it from the live-ness set) that value is certainly live. |
540 // The defined value interferes with everything currently live. The | 521 // The defined value interferes with everything currently live. The |
541 // value is then removed from the live-ness set and it's inputs are added | 522 // value is then removed from the live-ness set and it's inputs are added |
542 // to the live-ness set. | 523 // to the live-ness set. |
543 uint j; | 524 uint j; |
544 for( j = last_inst + 1; j > 1; j-- ) { | 525 for (j = last_inst + 1; j > 1; j--) { |
545 Node *n = b->_nodes[j - 1]; | 526 Node* n = block->_nodes[j - 1]; |
546 | 527 |
547 // Get value being defined | 528 // Get value being defined |
548 uint r = _lrg_map.live_range_id(n); | 529 uint r = _lrg_map.live_range_id(n); |
549 | 530 |
550 // Some special values do not allocate | 531 // Some special values do not allocate |
551 if(r) { | 532 if(r) { |
552 // A DEF normally costs block frequency; rematerialized values are | 533 // A DEF normally costs block frequency; rematerialized values are |
553 // removed from the DEF sight, so LOWER costs here. | 534 // removed from the DEF sight, so LOWER costs here. |
554 lrgs(r)._cost += n->rematerialize() ? 0 : b->_freq; | 535 lrgs(r)._cost += n->rematerialize() ? 0 : block->_freq; |
555 | 536 |
556 // If it is not live, then this instruction is dead. Probably caused | 537 // If it is not live, then this instruction is dead. Probably caused |
557 // by spilling and rematerialization. Who cares why, yank this baby. | 538 // by spilling and rematerialization. Who cares why, yank this baby. |
558 if( !liveout.member(r) && n->Opcode() != Op_SafePoint ) { | 539 if( !liveout.member(r) && n->Opcode() != Op_SafePoint ) { |
559 Node *def = n->in(0); | 540 Node *def = n->in(0); |
560 if( !n->is_Proj() || | 541 if( !n->is_Proj() || |
561 // Could also be a flags-projection of a dead ADD or such. | 542 // Could also be a flags-projection of a dead ADD or such. |
562 (_lrg_map.live_range_id(def) && !liveout.member(_lrg_map.live_range_id(def)))) { | 543 (_lrg_map.live_range_id(def) && !liveout.member(_lrg_map.live_range_id(def)))) { |
563 b->_nodes.remove(j - 1); | 544 block->_nodes.remove(j - 1); |
564 if (lrgs(r)._def == n) { | 545 if (lrgs(r)._def == n) { |
565 lrgs(r)._def = 0; | 546 lrgs(r)._def = 0; |
566 } | 547 } |
567 n->disconnect_inputs(NULL, C); | 548 n->disconnect_inputs(NULL, C); |
568 _cfg.unmap_node_from_block(n); | 549 _cfg.unmap_node_from_block(n); |
578 if (lrgs(r)._fat_proj) { | 559 if (lrgs(r)._fat_proj) { |
579 // Count the int-only registers | 560 // Count the int-only registers |
580 RegMask itmp = lrgs(r).mask(); | 561 RegMask itmp = lrgs(r).mask(); |
581 itmp.AND(*Matcher::idealreg2regmask[Op_RegI]); | 562 itmp.AND(*Matcher::idealreg2regmask[Op_RegI]); |
582 int iregs = itmp.Size(); | 563 int iregs = itmp.Size(); |
583 if( pressure[0]+iregs > b->_reg_pressure ) | 564 if (pressure[0]+iregs > block->_reg_pressure) { |
584 b->_reg_pressure = pressure[0]+iregs; | 565 block->_reg_pressure = pressure[0] + iregs; |
585 if( pressure[0] <= (uint)INTPRESSURE && | 566 } |
586 pressure[0]+iregs > (uint)INTPRESSURE ) { | 567 if (pressure[0] <= (uint)INTPRESSURE && pressure[0] + iregs > (uint)INTPRESSURE) { |
587 hrp_index[0] = j-1; | 568 hrp_index[0] = j - 1; |
588 } | 569 } |
589 // Count the float-only registers | 570 // Count the float-only registers |
590 RegMask ftmp = lrgs(r).mask(); | 571 RegMask ftmp = lrgs(r).mask(); |
591 ftmp.AND(*Matcher::idealreg2regmask[Op_RegD]); | 572 ftmp.AND(*Matcher::idealreg2regmask[Op_RegD]); |
592 int fregs = ftmp.Size(); | 573 int fregs = ftmp.Size(); |
593 if( pressure[1]+fregs > b->_freg_pressure ) | 574 if (pressure[1] + fregs > block->_freg_pressure) { |
594 b->_freg_pressure = pressure[1]+fregs; | 575 block->_freg_pressure = pressure[1] + fregs; |
595 if( pressure[1] <= (uint)FLOATPRESSURE && | 576 } |
596 pressure[1]+fregs > (uint)FLOATPRESSURE ) { | 577 if(pressure[1] <= (uint)FLOATPRESSURE && pressure[1]+fregs > (uint)FLOATPRESSURE) { |
597 hrp_index[1] = j-1; | 578 hrp_index[1] = j - 1; |
598 } | 579 } |
599 } | 580 } |
600 | 581 |
601 } else { // Else it is live | 582 } else { // Else it is live |
602 // A DEF also ends 'area' partway through the block. | 583 // A DEF also ends 'area' partway through the block. |
605 | 586 |
606 // Insure high score for immediate-use spill copies so they get a color | 587 // Insure high score for immediate-use spill copies so they get a color |
607 if( n->is_SpillCopy() | 588 if( n->is_SpillCopy() |
608 && lrgs(r).is_singledef() // MultiDef live range can still split | 589 && lrgs(r).is_singledef() // MultiDef live range can still split |
609 && n->outcnt() == 1 // and use must be in this block | 590 && n->outcnt() == 1 // and use must be in this block |
610 && _cfg.get_block_for_node(n->unique_out()) == b ) { | 591 && _cfg.get_block_for_node(n->unique_out()) == block) { |
611 // All single-use MachSpillCopy(s) that immediately precede their | 592 // All single-use MachSpillCopy(s) that immediately precede their |
612 // use must color early. If a longer live range steals their | 593 // use must color early. If a longer live range steals their |
613 // color, the spill copy will split and may push another spill copy | 594 // color, the spill copy will split and may push another spill copy |
614 // further away resulting in an infinite spill-split-retry cycle. | 595 // further away resulting in an infinite spill-split-retry cycle. |
615 // Assigning a zero area results in a high score() and a good | 596 // Assigning a zero area results in a high score() and a good |
616 // location in the simplify list. | 597 // location in the simplify list. |
617 // | 598 // |
618 | 599 |
619 Node *single_use = n->unique_out(); | 600 Node *single_use = n->unique_out(); |
620 assert( b->find_node(single_use) >= j, "Use must be later in block"); | 601 assert(block->find_node(single_use) >= j, "Use must be later in block"); |
621 // Use can be earlier in block if it is a Phi, but then I should be a MultiDef | 602 // Use can be earlier in block if it is a Phi, but then I should be a MultiDef |
622 | 603 |
623 // Find first non SpillCopy 'm' that follows the current instruction | 604 // Find first non SpillCopy 'm' that follows the current instruction |
624 // (j - 1) is index for current instruction 'n' | 605 // (j - 1) is index for current instruction 'n' |
625 Node *m = n; | 606 Node *m = n; |
626 for( uint i = j; i <= last_inst && m->is_SpillCopy(); ++i ) { m = b->_nodes[i]; } | 607 for (uint i = j; i <= last_inst && m->is_SpillCopy(); ++i) { |
627 if( m == single_use ) { | 608 m = block->_nodes[i]; |
609 } | |
610 if (m == single_use) { | |
628 lrgs(r)._area = 0.0; | 611 lrgs(r)._area = 0.0; |
629 } | 612 } |
630 } | 613 } |
631 | 614 |
632 // Remove from live-out set | 615 // Remove from live-out set |
633 if( liveout.remove(r) ) { | 616 if( liveout.remove(r) ) { |
634 // Adjust register pressure. | 617 // Adjust register pressure. |
635 // Capture last hi-to-lo pressure transition | 618 // Capture last hi-to-lo pressure transition |
636 lower_pressure( &lrgs(r), j-1, b, pressure, hrp_index ); | 619 lower_pressure(&lrgs(r), j - 1, block, pressure, hrp_index); |
637 assert( pressure[0] == count_int_pressure (&liveout), "" ); | 620 assert( pressure[0] == count_int_pressure (&liveout), "" ); |
638 assert( pressure[1] == count_float_pressure(&liveout), "" ); | 621 assert( pressure[1] == count_float_pressure(&liveout), "" ); |
639 } | 622 } |
640 | 623 |
641 // Copies do not define a new value and so do not interfere. | 624 // Copies do not define a new value and so do not interfere. |
644 if (idx) { | 627 if (idx) { |
645 uint x = _lrg_map.live_range_id(n->in(idx)); | 628 uint x = _lrg_map.live_range_id(n->in(idx)); |
646 if (liveout.remove(x)) { | 629 if (liveout.remove(x)) { |
647 lrgs(x)._area -= cost; | 630 lrgs(x)._area -= cost; |
648 // Adjust register pressure. | 631 // Adjust register pressure. |
649 lower_pressure(&lrgs(x), j-1, b, pressure, hrp_index); | 632 lower_pressure(&lrgs(x), j - 1, block, pressure, hrp_index); |
650 assert( pressure[0] == count_int_pressure (&liveout), "" ); | 633 assert( pressure[0] == count_int_pressure (&liveout), "" ); |
651 assert( pressure[1] == count_float_pressure(&liveout), "" ); | 634 assert( pressure[1] == count_float_pressure(&liveout), "" ); |
652 } | 635 } |
653 } | 636 } |
654 } // End of if live or not | 637 } // End of if live or not |
716 | 699 |
717 } // End of if normal register-allocated value | 700 } // End of if normal register-allocated value |
718 | 701 |
719 // Area remaining in the block | 702 // Area remaining in the block |
720 inst_count--; | 703 inst_count--; |
721 cost = (inst_count <= 0) ? 0.0 : b->_freq * double(inst_count); | 704 cost = (inst_count <= 0) ? 0.0 : block->_freq * double(inst_count); |
722 | 705 |
723 // Make all inputs live | 706 // Make all inputs live |
724 if( !n->is_Phi() ) { // Phi function uses come from prior block | 707 if( !n->is_Phi() ) { // Phi function uses come from prior block |
725 JVMState* jvms = n->jvms(); | 708 JVMState* jvms = n->jvms(); |
726 uint debug_start = jvms ? jvms->debug_start() : 999999; | 709 uint debug_start = jvms ? jvms->debug_start() : 999999; |
741 LRG &lrg = lrgs(x); | 724 LRG &lrg = lrgs(x); |
742 // No use-side cost for spilling debug info | 725 // No use-side cost for spilling debug info |
743 if (k < debug_start) { | 726 if (k < debug_start) { |
744 // A USE costs twice block frequency (once for the Load, once | 727 // A USE costs twice block frequency (once for the Load, once |
745 // for a Load-delay). Rematerialized uses only cost once. | 728 // for a Load-delay). Rematerialized uses only cost once. |
746 lrg._cost += (def->rematerialize() ? b->_freq : (b->_freq + b->_freq)); | 729 lrg._cost += (def->rematerialize() ? block->_freq : (block->_freq + block->_freq)); |
747 } | 730 } |
748 // It is live now | 731 // It is live now |
749 if (liveout.insert(x)) { | 732 if (liveout.insert(x)) { |
750 // Newly live things assumed live from here to top of block | 733 // Newly live things assumed live from here to top of block |
751 lrg._area += cost; | 734 lrg._area += cost; |
752 // Adjust register pressure | 735 // Adjust register pressure |
753 if (lrg.mask().is_UP() && lrg.mask_size()) { | 736 if (lrg.mask().is_UP() && lrg.mask_size()) { |
754 if (lrg._is_float || lrg._is_vector) { | 737 if (lrg._is_float || lrg._is_vector) { |
755 pressure[1] += lrg.reg_pressure(); | 738 pressure[1] += lrg.reg_pressure(); |
756 if( pressure[1] > b->_freg_pressure ) | 739 if (pressure[1] > block->_freg_pressure) { |
757 b->_freg_pressure = pressure[1]; | 740 block->_freg_pressure = pressure[1]; |
741 } | |
758 } else if( lrg.mask().overlap(*Matcher::idealreg2regmask[Op_RegI]) ) { | 742 } else if( lrg.mask().overlap(*Matcher::idealreg2regmask[Op_RegI]) ) { |
759 pressure[0] += lrg.reg_pressure(); | 743 pressure[0] += lrg.reg_pressure(); |
760 if( pressure[0] > b->_reg_pressure ) | 744 if (pressure[0] > block->_reg_pressure) { |
761 b->_reg_pressure = pressure[0]; | 745 block->_reg_pressure = pressure[0]; |
746 } | |
762 } | 747 } |
763 } | 748 } |
764 assert( pressure[0] == count_int_pressure (&liveout), "" ); | 749 assert( pressure[0] == count_int_pressure (&liveout), "" ); |
765 assert( pressure[1] == count_float_pressure(&liveout), "" ); | 750 assert( pressure[1] == count_float_pressure(&liveout), "" ); |
766 } | 751 } |
770 } // End of reverse pass over all instructions in block | 755 } // End of reverse pass over all instructions in block |
771 | 756 |
772 // If we run off the top of the block with high pressure and | 757 // If we run off the top of the block with high pressure and |
773 // never see a hi-to-low pressure transition, just record that | 758 // never see a hi-to-low pressure transition, just record that |
774 // the whole block is high pressure. | 759 // the whole block is high pressure. |
775 if( pressure[0] > (uint)INTPRESSURE ) { | 760 if (pressure[0] > (uint)INTPRESSURE) { |
776 hrp_index[0] = 0; | 761 hrp_index[0] = 0; |
777 if( pressure[0] > b->_reg_pressure ) | 762 if (pressure[0] > block->_reg_pressure) { |
778 b->_reg_pressure = pressure[0]; | 763 block->_reg_pressure = pressure[0]; |
779 } | 764 } |
780 if( pressure[1] > (uint)FLOATPRESSURE ) { | 765 } |
766 if (pressure[1] > (uint)FLOATPRESSURE) { | |
781 hrp_index[1] = 0; | 767 hrp_index[1] = 0; |
782 if( pressure[1] > b->_freg_pressure ) | 768 if (pressure[1] > block->_freg_pressure) { |
783 b->_freg_pressure = pressure[1]; | 769 block->_freg_pressure = pressure[1]; |
770 } | |
784 } | 771 } |
785 | 772 |
786 // Compute high pressure indice; avoid landing in the middle of projnodes | 773 // Compute high pressure indice; avoid landing in the middle of projnodes |
787 j = hrp_index[0]; | 774 j = hrp_index[0]; |
788 if( j < b->_nodes.size() && j < b->end_idx()+1 ) { | 775 if (j < block->_nodes.size() && j < block->end_idx() + 1) { |
789 Node *cur = b->_nodes[j]; | 776 Node* cur = block->_nodes[j]; |
790 while( cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch() ) { | 777 while (cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch()) { |
791 j--; | 778 j--; |
792 cur = b->_nodes[j]; | 779 cur = block->_nodes[j]; |
793 } | 780 } |
794 } | 781 } |
795 b->_ihrp_index = j; | 782 block->_ihrp_index = j; |
796 j = hrp_index[1]; | 783 j = hrp_index[1]; |
797 if( j < b->_nodes.size() && j < b->end_idx()+1 ) { | 784 if (j < block->_nodes.size() && j < block->end_idx() + 1) { |
798 Node *cur = b->_nodes[j]; | 785 Node* cur = block->_nodes[j]; |
799 while( cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch() ) { | 786 while (cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch()) { |
800 j--; | 787 j--; |
801 cur = b->_nodes[j]; | 788 cur = block->_nodes[j]; |
802 } | 789 } |
803 } | 790 } |
804 b->_fhrp_index = j; | 791 block->_fhrp_index = j; |
805 | 792 |
806 #ifndef PRODUCT | 793 #ifndef PRODUCT |
807 // Gather Register Pressure Statistics | 794 // Gather Register Pressure Statistics |
808 if( PrintOptoStatistics ) { | 795 if( PrintOptoStatistics ) { |
809 if( b->_reg_pressure > (uint)INTPRESSURE || b->_freg_pressure > (uint)FLOATPRESSURE ) | 796 if (block->_reg_pressure > (uint)INTPRESSURE || block->_freg_pressure > (uint)FLOATPRESSURE) { |
810 _high_pressure++; | 797 _high_pressure++; |
811 else | 798 } else { |
812 _low_pressure++; | 799 _low_pressure++; |
800 } | |
813 } | 801 } |
814 #endif | 802 #endif |
815 } // End of for all blocks | 803 } // End of for all blocks |
816 | 804 |
817 return must_spill; | 805 return must_spill; |