261 } |
261 } |
262 |
262 |
263 # endif // ENABLE_ZAP_DEAD_LOCALS |
263 # endif // ENABLE_ZAP_DEAD_LOCALS |
264 |
264 |
265 //------------------------------compute_loop_first_inst_sizes------------------ |
265 //------------------------------compute_loop_first_inst_sizes------------------ |
266 // Compute the size of first NumberOfLoopInstrToAlign instructions at head |
266 // Compute the size of first NumberOfLoopInstrToAlign instructions at the top |
267 // of a loop. When aligning a loop we need to provide enough instructions |
267 // of a loop. When aligning a loop we need to provide enough instructions |
268 // in cpu's fetch buffer to feed decoders. The loop alignment could be |
268 // in cpu's fetch buffer to feed decoders. The loop alignment could be |
269 // avoided if we have enough instructions in fetch buffer at the head of a loop. |
269 // avoided if we have enough instructions in fetch buffer at the head of a loop. |
270 // By default, the size is set to 999999 by Block's constructor so that |
270 // By default, the size is set to 999999 by Block's constructor so that |
271 // a loop will be aligned if the size is not reset here. |
271 // a loop will be aligned if the size is not reset here. |
282 if( MaxLoopPad < OptoLoopAlignment-1 ) { |
282 if( MaxLoopPad < OptoLoopAlignment-1 ) { |
283 uint last_block = _cfg->_num_blocks-1; |
283 uint last_block = _cfg->_num_blocks-1; |
284 for( uint i=1; i <= last_block; i++ ) { |
284 for( uint i=1; i <= last_block; i++ ) { |
285 Block *b = _cfg->_blocks[i]; |
285 Block *b = _cfg->_blocks[i]; |
286 // Check the first loop's block which requires an alignment. |
286 // Check the first loop's block which requires an alignment. |
287 if( b->head()->is_Loop() && |
287 if( b->loop_alignment() > (uint)relocInfo::addr_unit() ) { |
288 b->code_alignment() > (uint)relocInfo::addr_unit() ) { |
|
289 uint sum_size = 0; |
288 uint sum_size = 0; |
290 uint inst_cnt = NumberOfLoopInstrToAlign; |
289 uint inst_cnt = NumberOfLoopInstrToAlign; |
291 inst_cnt = b->compute_first_inst_size(sum_size, inst_cnt, |
290 inst_cnt = b->compute_first_inst_size(sum_size, inst_cnt, _regalloc); |
292 _regalloc); |
291 |
293 // Check the next fallthrough block if first loop's block does not have |
292 // Check subsequent fallthrough blocks if the loop's first |
294 // enough instructions. |
293 // block(s) does not have enough instructions. |
295 if( inst_cnt > 0 && i < last_block ) { |
294 Block *nb = b; |
296 // First, check if the first loop's block contains whole loop. |
295 while( inst_cnt > 0 && |
297 // LoopNode::LoopBackControl == 2. |
296 i < last_block && |
298 Block *bx = _cfg->_bbs[b->pred(2)->_idx]; |
297 !_cfg->_blocks[i+1]->has_loop_alignment() && |
299 // Skip connector blocks (with limit in case of irreducible loops). |
298 !nb->has_successor(b) ) { |
300 int search_limit = 16; |
299 i++; |
301 while( bx->is_connector() && search_limit-- > 0) { |
300 nb = _cfg->_blocks[i]; |
302 bx = _cfg->_bbs[bx->pred(1)->_idx]; |
301 inst_cnt = nb->compute_first_inst_size(sum_size, inst_cnt, _regalloc); |
303 } |
302 } // while( inst_cnt > 0 && i < last_block ) |
304 if( bx != b ) { // loop body is in several blocks. |
303 |
305 Block *nb = NULL; |
|
306 while( inst_cnt > 0 && i < last_block && nb != bx && |
|
307 !_cfg->_blocks[i+1]->head()->is_Loop() ) { |
|
308 i++; |
|
309 nb = _cfg->_blocks[i]; |
|
310 inst_cnt = nb->compute_first_inst_size(sum_size, inst_cnt, |
|
311 _regalloc); |
|
312 } // while( inst_cnt > 0 && i < last_block ) |
|
313 } // if( bx != b ) |
|
314 } // if( inst_cnt > 0 && i < last_block ) |
|
315 b->set_first_inst_size(sum_size); |
304 b->set_first_inst_size(sum_size); |
316 } // f( b->head()->is_Loop() ) |
305 } // f( b->head()->is_Loop() ) |
317 } // for( i <= last_block ) |
306 } // for( i <= last_block ) |
318 } // if( MaxLoopPad < OptoLoopAlignment-1 ) |
307 } // if( MaxLoopPad < OptoLoopAlignment-1 ) |
319 } |
308 } |
510 |
499 |
511 if ( i != _cfg->_num_blocks-1) { |
500 if ( i != _cfg->_num_blocks-1) { |
512 // Get the size of the block |
501 // Get the size of the block |
513 uint blk_size = adr - blk_starts[i]; |
502 uint blk_size = adr - blk_starts[i]; |
514 |
503 |
515 // When the next block starts a loop, we may insert pad NOP |
504 // When the next block is the top of a loop, we may insert pad NOP |
516 // instructions. |
505 // instructions. |
517 Block *nb = _cfg->_blocks[i+1]; |
506 Block *nb = _cfg->_blocks[i+1]; |
518 int current_offset = blk_starts[i] + blk_size; |
507 int current_offset = blk_starts[i] + blk_size; |
519 current_offset += nb->alignment_padding(current_offset); |
508 current_offset += nb->alignment_padding(current_offset); |
520 // Save block size; update total method size |
509 // Save block size; update total method size |
1380 delay_slot = NULL; |
1369 delay_slot = NULL; |
1381 } |
1370 } |
1382 |
1371 |
1383 } // End for all instructions in block |
1372 } // End for all instructions in block |
1384 |
1373 |
1385 // If the next block _starts_ a loop, pad this block out to align |
1374 // If the next block is the top of a loop, pad this block out to align |
1386 // the loop start a little. Helps prevent pipe stalls at loop starts |
1375 // the loop top a little. Helps prevent pipe stalls at loop back branches. |
1387 int nop_size = (new (this) MachNopNode())->size(_regalloc); |
1376 int nop_size = (new (this) MachNopNode())->size(_regalloc); |
1388 if( i<_cfg->_num_blocks-1 ) { |
1377 if( i<_cfg->_num_blocks-1 ) { |
1389 Block *nb = _cfg->_blocks[i+1]; |
1378 Block *nb = _cfg->_blocks[i+1]; |
1390 uint padding = nb->alignment_padding(current_offset); |
1379 uint padding = nb->alignment_padding(current_offset); |
1391 if( padding > 0 ) { |
1380 if( padding > 0 ) { |