(int round, RegAlloc alloc)
| 300 | // Walk all the LRGS looking for some trivial ones to start with. |
| 301 | // During this pass all LRGS are broken into 3 disjoint sets: |
| 302 | // - trivial, removed from IFG; color_stack[0 to sptr] |
| 303 | // - trivial, not (yet) removed from IFG; color_stack[sptr to swork] |
| 304 | // - unknown; color_stack[work to maxlrg] |
| 305 | |
| 306 | // Gather all not-unified (not-null); separate trivial and non-trivial set. |
| 307 | int sptr = 0, swork = 0; |
| 308 | LRG[] color_stack = new LRG[nlrgs]; |
| 309 | for( int i=0, j=0; i<maxlrg; i++ ) { |
| 310 | LRG lrg = alloc._LRGS[i]; |
| 311 | if( lrg==null ) continue; // Unified lrgs are null here |
| 312 | color_stack[j++] = lrg; |
| 313 | if( lrg.lowDegree() ) swap(color_stack, swork++, j-1); |
| 314 | } |
| 315 | |
| 316 | // Pull all lrgs from IFG, in trivial order if possible |
| 317 | while( sptr < color_stack.length ) { |
| 318 | // Swap best color up front |
| 319 | pickColor(color_stack,sptr,swork); |
| 320 | |
| 321 | // Pick a trivial lrg, and (temporarily) remove from the IFG. |
| 322 | LRG lrg = color_stack[sptr++]; |
| 323 | // If sptr was swork, then pulled an at-risk lrg |
| 324 | if( sptr > swork ) |
| 325 | swork = sptr; |
| 326 | |
| 327 | // Walk all neighbors and remove |
| 328 | if( lrg._adj != null ) { |
| 329 | for( LRG nlrg : lrg._adj ) { |
| 330 | // Remove and compress out neighbor |
| 331 | if( nlrg.removeCompress(lrg) ) { |
| 332 | // Neighbor is just exactly going trivial as 'lrg' is removed from IFG |
| 333 | // Find "j" position in the color_stack |
| 334 | int jx = swork; while( color_stack[jx] != nlrg ) jx++; |
| 335 | // Add trivial neighbor to trivial list. Pull lrg j out of |
| 336 | // unknown set, since its now in the trivial set |
| 337 | swap(color_stack, swork++, jx); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | // Reverse simplify (unstack the color stack), and set colors (registers) for live ranges |
| 344 | while( sptr > 0 ) { |
| 345 | LRG lrg = color_stack[--sptr]; |
| 346 | if( lrg==null ) continue; |
| 347 | RegMaskRW rmask = lrg._mask.copy(); |
| 348 | // Walk neighbors and remove adjacent colors |
| 349 | if( lrg._adj!=null ) { |
| 350 | for( LRG nlrg : lrg._adj ) { |
| 351 | nlrg.reinsert(lrg); |
| 352 | int reg = nlrg._reg; |
| 353 | if( reg!= -1 ) // Failed neighbors do not count |
| 354 | rmask.clr(reg); // Remove neighbor from my choices |
| 355 | } |
| 356 | } |
| 357 | // At-risk live-range did not color? |
| 358 | if( rmask.isEmpty() ) { |
| 359 | alloc.fail(lrg); |
no test coverage detected