Mercurial > hg > truffle
comparison src/share/vm/opto/output.cpp @ 12355:cefad50507d8
Merge with hs25-b53
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 11 Oct 2013 10:38:03 +0200 |
parents | 3cce976666d9 650868c062a9 |
children | d8041d695d19 |
comparison
equal
deleted
inserted
replaced
12058:ccb4f2af2319 | 12355:cefad50507d8 |
---|---|
52 #endif | 52 #endif |
53 | 53 |
54 extern int emit_exception_handler(CodeBuffer &cbuf); | 54 extern int emit_exception_handler(CodeBuffer &cbuf); |
55 extern int emit_deopt_handler(CodeBuffer &cbuf); | 55 extern int emit_deopt_handler(CodeBuffer &cbuf); |
56 | 56 |
57 //------------------------------Output----------------------------------------- | |
58 // Convert Nodes to instruction bits and pass off to the VM | 57 // Convert Nodes to instruction bits and pass off to the VM |
59 void Compile::Output() { | 58 void Compile::Output() { |
60 // RootNode goes | 59 // RootNode goes |
61 assert( _cfg->_broot->_nodes.size() == 0, "" ); | 60 assert( _cfg->get_root_block()->number_of_nodes() == 0, "" ); |
62 | 61 |
63 // The number of new nodes (mostly MachNop) is proportional to | 62 // The number of new nodes (mostly MachNop) is proportional to |
64 // the number of java calls and inner loops which are aligned. | 63 // the number of java calls and inner loops which are aligned. |
65 if ( C->check_node_count((NodeLimitFudgeFactor + C->java_calls()*3 + | 64 if ( C->check_node_count((NodeLimitFudgeFactor + C->java_calls()*3 + |
66 C->inner_loops()*(OptoLoopAlignment-1)), | 65 C->inner_loops()*(OptoLoopAlignment-1)), |
67 "out of nodes before code generation" ) ) { | 66 "out of nodes before code generation" ) ) { |
68 return; | 67 return; |
69 } | 68 } |
70 // Make sure I can find the Start Node | 69 // Make sure I can find the Start Node |
71 Block *entry = _cfg->_blocks[1]; | 70 Block *entry = _cfg->get_block(1); |
72 Block *broot = _cfg->_broot; | 71 Block *broot = _cfg->get_root_block(); |
73 | 72 |
74 const StartNode *start = entry->_nodes[0]->as_Start(); | 73 const StartNode *start = entry->head()->as_Start(); |
75 | 74 |
76 // Replace StartNode with prolog | 75 // Replace StartNode with prolog |
77 MachPrologNode *prolog = new (this) MachPrologNode(); | 76 MachPrologNode *prolog = new (this) MachPrologNode(); |
78 entry->_nodes.map( 0, prolog ); | 77 entry->map_node(prolog, 0); |
79 _cfg->map_node_to_block(prolog, entry); | 78 _cfg->map_node_to_block(prolog, entry); |
80 _cfg->unmap_node_from_block(start); // start is no longer in any block | 79 _cfg->unmap_node_from_block(start); // start is no longer in any block |
81 | 80 |
82 // Virtual methods need an unverified entry point | 81 // Virtual methods need an unverified entry point |
83 | 82 |
107 // runtime stubs or frame converters | 106 // runtime stubs or frame converters |
108 _cfg->insert( entry, 1, new (this) MachBreakpointNode() ); | 107 _cfg->insert( entry, 1, new (this) MachBreakpointNode() ); |
109 } | 108 } |
110 | 109 |
111 // Insert epilogs before every return | 110 // Insert epilogs before every return |
112 for( uint i=0; i<_cfg->_num_blocks; i++ ) { | 111 for (uint i = 0; i < _cfg->number_of_blocks(); i++) { |
113 Block *b = _cfg->_blocks[i]; | 112 Block* block = _cfg->get_block(i); |
114 if( !b->is_connector() && b->non_connector_successor(0) == _cfg->_broot ) { // Found a program exit point? | 113 if (!block->is_connector() && block->non_connector_successor(0) == _cfg->get_root_block()) { // Found a program exit point? |
115 Node *m = b->end(); | 114 Node* m = block->end(); |
116 if( m->is_Mach() && m->as_Mach()->ideal_Opcode() != Op_Halt ) { | 115 if (m->is_Mach() && m->as_Mach()->ideal_Opcode() != Op_Halt) { |
117 MachEpilogNode *epilog = new (this) MachEpilogNode(m->as_Mach()->ideal_Opcode() == Op_Return); | 116 MachEpilogNode* epilog = new (this) MachEpilogNode(m->as_Mach()->ideal_Opcode() == Op_Return); |
118 b->add_inst( epilog ); | 117 block->add_inst(epilog); |
119 _cfg->map_node_to_block(epilog, b); | 118 _cfg->map_node_to_block(epilog, block); |
120 } | 119 } |
121 } | 120 } |
122 } | 121 } |
123 | 122 |
124 # ifdef ENABLE_ZAP_DEAD_LOCALS | 123 # ifdef ENABLE_ZAP_DEAD_LOCALS |
125 if ( ZapDeadCompiledLocals ) Insert_zap_nodes(); | 124 if (ZapDeadCompiledLocals) { |
125 Insert_zap_nodes(); | |
126 } | |
126 # endif | 127 # endif |
127 | 128 |
128 uint* blk_starts = NEW_RESOURCE_ARRAY(uint,_cfg->_num_blocks+1); | 129 uint* blk_starts = NEW_RESOURCE_ARRAY(uint, _cfg->number_of_blocks() + 1); |
129 blk_starts[0] = 0; | 130 blk_starts[0] = 0; |
130 | 131 |
131 // Initialize code buffer and process short branches. | 132 // Initialize code buffer and process short branches. |
132 CodeBuffer* cb = init_buffer(blk_starts); | 133 CodeBuffer* cb = init_buffer(blk_starts); |
133 | 134 |
134 if (cb == NULL || failing()) return; | 135 if (cb == NULL || failing()) { |
136 return; | |
137 } | |
135 | 138 |
136 ScheduleAndBundle(); | 139 ScheduleAndBundle(); |
137 | 140 |
138 #ifndef PRODUCT | 141 #ifndef PRODUCT |
139 if (trace_opto_output()) { | 142 if (trace_opto_output()) { |
140 tty->print("\n---- After ScheduleAndBundle ----\n"); | 143 tty->print("\n---- After ScheduleAndBundle ----\n"); |
141 for (uint i = 0; i < _cfg->_num_blocks; i++) { | 144 for (uint i = 0; i < _cfg->number_of_blocks(); i++) { |
142 tty->print("\nBB#%03d:\n", i); | 145 tty->print("\nBB#%03d:\n", i); |
143 Block *bb = _cfg->_blocks[i]; | 146 Block* block = _cfg->get_block(i); |
144 for (uint j = 0; j < bb->_nodes.size(); j++) { | 147 for (uint j = 0; j < block->number_of_nodes(); j++) { |
145 Node *n = bb->_nodes[j]; | 148 Node* n = block->get_node(j); |
146 OptoReg::Name reg = _regalloc->get_reg_first(n); | 149 OptoReg::Name reg = _regalloc->get_reg_first(n); |
147 tty->print(" %-6s ", reg >= 0 && reg < REG_COUNT ? Matcher::regName[reg] : ""); | 150 tty->print(" %-6s ", reg >= 0 && reg < REG_COUNT ? Matcher::regName[reg] : ""); |
148 n->dump(); | 151 n->dump(); |
149 } | 152 } |
150 } | 153 } |
151 } | 154 } |
152 #endif | 155 #endif |
153 | 156 |
154 if (failing()) return; | 157 if (failing()) { |
158 return; | |
159 } | |
155 | 160 |
156 BuildOopMaps(); | 161 BuildOopMaps(); |
157 | 162 |
158 if (failing()) return; | 163 if (failing()) { |
164 return; | |
165 } | |
159 | 166 |
160 fill_buffer(cb, blk_starts); | 167 fill_buffer(cb, blk_starts); |
161 } | 168 } |
162 | 169 |
163 bool Compile::need_stack_bang(int frame_size_in_bytes) const { | 170 bool Compile::need_stack_bang(int frame_size_in_bytes) const { |
215 | 222 |
216 if ( _method == NULL ) | 223 if ( _method == NULL ) |
217 return; // no safepoints/oopmaps emitted for calls in stubs,so we don't care | 224 return; // no safepoints/oopmaps emitted for calls in stubs,so we don't care |
218 | 225 |
219 // Insert call to zap runtime stub before every node with an oop map | 226 // Insert call to zap runtime stub before every node with an oop map |
220 for( uint i=0; i<_cfg->_num_blocks; i++ ) { | 227 for( uint i=0; i<_cfg->number_of_blocks(); i++ ) { |
221 Block *b = _cfg->_blocks[i]; | 228 Block *b = _cfg->get_block(i); |
222 for ( uint j = 0; j < b->_nodes.size(); ++j ) { | 229 for ( uint j = 0; j < b->number_of_nodes(); ++j ) { |
223 Node *n = b->_nodes[j]; | 230 Node *n = b->get_node(j); |
224 | 231 |
225 // Determining if we should insert a zap-a-lot node in output. | 232 // Determining if we should insert a zap-a-lot node in output. |
226 // We do that for all nodes that has oopmap info, except for calls | 233 // We do that for all nodes that has oopmap info, except for calls |
227 // to allocation. Calls to allocation passes in the old top-of-eden pointer | 234 // to allocation. Calls to allocation passes in the old top-of-eden pointer |
228 // and expect the C code to reset it. Hence, there can be no safepoints between | 235 // and expect the C code to reset it. Hence, there can be no safepoints between |
247 insert = false; | 254 insert = false; |
248 } | 255 } |
249 } | 256 } |
250 if (insert) { | 257 if (insert) { |
251 Node *zap = call_zap_node(n->as_MachSafePoint(), i); | 258 Node *zap = call_zap_node(n->as_MachSafePoint(), i); |
252 b->_nodes.insert( j, zap ); | 259 b->insert_node(zap, j); |
253 _cfg->map_node_to_block(zap, b); | 260 _cfg->map_node_to_block(zap, b); |
254 ++j; | 261 ++j; |
255 } | 262 } |
256 } | 263 } |
257 } | 264 } |
273 // Add the cloned OopMap to the zap node | 280 // Add the cloned OopMap to the zap node |
274 ideal_node->set_oop_map(clone); | 281 ideal_node->set_oop_map(clone); |
275 return _matcher->match_sfpt(ideal_node); | 282 return _matcher->match_sfpt(ideal_node); |
276 } | 283 } |
277 | 284 |
278 //------------------------------is_node_getting_a_safepoint-------------------- | |
279 bool Compile::is_node_getting_a_safepoint( Node* n) { | 285 bool Compile::is_node_getting_a_safepoint( Node* n) { |
280 // This code duplicates the logic prior to the call of add_safepoint | 286 // This code duplicates the logic prior to the call of add_safepoint |
281 // below in this file. | 287 // below in this file. |
282 if( n->is_MachSafePoint() ) return true; | 288 if( n->is_MachSafePoint() ) return true; |
283 return false; | 289 return false; |
284 } | 290 } |
285 | 291 |
286 # endif // ENABLE_ZAP_DEAD_LOCALS | 292 # endif // ENABLE_ZAP_DEAD_LOCALS |
287 | 293 |
288 //------------------------------compute_loop_first_inst_sizes------------------ | |
289 // Compute the size of first NumberOfLoopInstrToAlign instructions at the top | 294 // Compute the size of first NumberOfLoopInstrToAlign instructions at the top |
290 // of a loop. When aligning a loop we need to provide enough instructions | 295 // of a loop. When aligning a loop we need to provide enough instructions |
291 // in cpu's fetch buffer to feed decoders. The loop alignment could be | 296 // in cpu's fetch buffer to feed decoders. The loop alignment could be |
292 // avoided if we have enough instructions in fetch buffer at the head of a loop. | 297 // avoided if we have enough instructions in fetch buffer at the head of a loop. |
293 // By default, the size is set to 999999 by Block's constructor so that | 298 // By default, the size is set to 999999 by Block's constructor so that |
300 // The next condition is used to gate the loop alignment optimization. | 305 // The next condition is used to gate the loop alignment optimization. |
301 // Don't aligned a loop if there are enough instructions at the head of a loop | 306 // Don't aligned a loop if there are enough instructions at the head of a loop |
302 // or alignment padding is larger then MaxLoopPad. By default, MaxLoopPad | 307 // or alignment padding is larger then MaxLoopPad. By default, MaxLoopPad |
303 // is equal to OptoLoopAlignment-1 except on new Intel cpus, where it is | 308 // is equal to OptoLoopAlignment-1 except on new Intel cpus, where it is |
304 // equal to 11 bytes which is the largest address NOP instruction. | 309 // equal to 11 bytes which is the largest address NOP instruction. |
305 if( MaxLoopPad < OptoLoopAlignment-1 ) { | 310 if (MaxLoopPad < OptoLoopAlignment - 1) { |
306 uint last_block = _cfg->_num_blocks-1; | 311 uint last_block = _cfg->number_of_blocks() - 1; |
307 for( uint i=1; i <= last_block; i++ ) { | 312 for (uint i = 1; i <= last_block; i++) { |
308 Block *b = _cfg->_blocks[i]; | 313 Block* block = _cfg->get_block(i); |
309 // Check the first loop's block which requires an alignment. | 314 // Check the first loop's block which requires an alignment. |
310 if( b->loop_alignment() > (uint)relocInfo::addr_unit() ) { | 315 if (block->loop_alignment() > (uint)relocInfo::addr_unit()) { |
311 uint sum_size = 0; | 316 uint sum_size = 0; |
312 uint inst_cnt = NumberOfLoopInstrToAlign; | 317 uint inst_cnt = NumberOfLoopInstrToAlign; |
313 inst_cnt = b->compute_first_inst_size(sum_size, inst_cnt, _regalloc); | 318 inst_cnt = block->compute_first_inst_size(sum_size, inst_cnt, _regalloc); |
314 | 319 |
315 // Check subsequent fallthrough blocks if the loop's first | 320 // Check subsequent fallthrough blocks if the loop's first |
316 // block(s) does not have enough instructions. | 321 // block(s) does not have enough instructions. |
317 Block *nb = b; | 322 Block *nb = block; |
318 while( inst_cnt > 0 && | 323 while(inst_cnt > 0 && |
319 i < last_block && | 324 i < last_block && |
320 !_cfg->_blocks[i+1]->has_loop_alignment() && | 325 !_cfg->get_block(i + 1)->has_loop_alignment() && |
321 !nb->has_successor(b) ) { | 326 !nb->has_successor(block)) { |
322 i++; | 327 i++; |
323 nb = _cfg->_blocks[i]; | 328 nb = _cfg->get_block(i); |
324 inst_cnt = nb->compute_first_inst_size(sum_size, inst_cnt, _regalloc); | 329 inst_cnt = nb->compute_first_inst_size(sum_size, inst_cnt, _regalloc); |
325 } // while( inst_cnt > 0 && i < last_block ) | 330 } // while( inst_cnt > 0 && i < last_block ) |
326 | 331 |
327 b->set_first_inst_size(sum_size); | 332 block->set_first_inst_size(sum_size); |
328 } // f( b->head()->is_Loop() ) | 333 } // f( b->head()->is_Loop() ) |
329 } // for( i <= last_block ) | 334 } // for( i <= last_block ) |
330 } // if( MaxLoopPad < OptoLoopAlignment-1 ) | 335 } // if( MaxLoopPad < OptoLoopAlignment-1 ) |
331 } | 336 } |
332 | 337 |
333 //----------------------shorten_branches--------------------------------------- | |
334 // The architecture description provides short branch variants for some long | 338 // The architecture description provides short branch variants for some long |
335 // branch instructions. Replace eligible long branches with short branches. | 339 // branch instructions. Replace eligible long branches with short branches. |
336 void Compile::shorten_branches(uint* blk_starts, int& code_size, int& reloc_size, int& stub_size) { | 340 void Compile::shorten_branches(uint* blk_starts, int& code_size, int& reloc_size, int& stub_size) { |
337 | |
338 // ------------------ | |
339 // Compute size of each block, method size, and relocation information size | 341 // Compute size of each block, method size, and relocation information size |
340 uint nblocks = _cfg->_num_blocks; | 342 uint nblocks = _cfg->number_of_blocks(); |
341 | 343 |
342 uint* jmp_offset = NEW_RESOURCE_ARRAY(uint,nblocks); | 344 uint* jmp_offset = NEW_RESOURCE_ARRAY(uint,nblocks); |
343 uint* jmp_size = NEW_RESOURCE_ARRAY(uint,nblocks); | 345 uint* jmp_size = NEW_RESOURCE_ARRAY(uint,nblocks); |
344 int* jmp_nidx = NEW_RESOURCE_ARRAY(int ,nblocks); | 346 int* jmp_nidx = NEW_RESOURCE_ARRAY(int ,nblocks); |
345 DEBUG_ONLY( uint *jmp_target = NEW_RESOURCE_ARRAY(uint,nblocks); ) | 347 DEBUG_ONLY( uint *jmp_target = NEW_RESOURCE_ARRAY(uint,nblocks); ) |
362 // Step one, perform a pessimistic sizing pass. | 364 // Step one, perform a pessimistic sizing pass. |
363 uint last_call_adr = max_uint; | 365 uint last_call_adr = max_uint; |
364 uint last_avoid_back_to_back_adr = max_uint; | 366 uint last_avoid_back_to_back_adr = max_uint; |
365 uint nop_size = (new (this) MachNopNode())->size(_regalloc); | 367 uint nop_size = (new (this) MachNopNode())->size(_regalloc); |
366 for (uint i = 0; i < nblocks; i++) { // For all blocks | 368 for (uint i = 0; i < nblocks; i++) { // For all blocks |
367 Block *b = _cfg->_blocks[i]; | 369 Block* block = _cfg->get_block(i); |
368 | 370 |
369 // During short branch replacement, we store the relative (to blk_starts) | 371 // During short branch replacement, we store the relative (to blk_starts) |
370 // offset of jump in jmp_offset, rather than the absolute offset of jump. | 372 // offset of jump in jmp_offset, rather than the absolute offset of jump. |
371 // This is so that we do not need to recompute sizes of all nodes when | 373 // This is so that we do not need to recompute sizes of all nodes when |
372 // we compute correct blk_starts in our next sizing pass. | 374 // we compute correct blk_starts in our next sizing pass. |
375 jmp_nidx[i] = -1; | 377 jmp_nidx[i] = -1; |
376 DEBUG_ONLY( jmp_target[i] = 0; ) | 378 DEBUG_ONLY( jmp_target[i] = 0; ) |
377 DEBUG_ONLY( jmp_rule[i] = 0; ) | 379 DEBUG_ONLY( jmp_rule[i] = 0; ) |
378 | 380 |
379 // Sum all instruction sizes to compute block size | 381 // Sum all instruction sizes to compute block size |
380 uint last_inst = b->_nodes.size(); | 382 uint last_inst = block->number_of_nodes(); |
381 uint blk_size = 0; | 383 uint blk_size = 0; |
382 for (uint j = 0; j < last_inst; j++) { | 384 for (uint j = 0; j < last_inst; j++) { |
383 Node* nj = b->_nodes[j]; | 385 Node* nj = block->get_node(j); |
384 // Handle machine instruction nodes | 386 // Handle machine instruction nodes |
385 if (nj->is_Mach()) { | 387 if (nj->is_Mach()) { |
386 MachNode *mach = nj->as_Mach(); | 388 MachNode *mach = nj->as_Mach(); |
387 blk_size += (mach->alignment_required() - 1) * relocInfo::addr_unit(); // assume worst case padding | 389 blk_size += (mach->alignment_required() - 1) * relocInfo::addr_unit(); // assume worst case padding |
388 reloc_size += mach->reloc(); | 390 reloc_size += mach->reloc(); |
439 } | 441 } |
440 | 442 |
441 // When the next block starts a loop, we may insert pad NOP | 443 // When the next block starts a loop, we may insert pad NOP |
442 // instructions. Since we cannot know our future alignment, | 444 // instructions. Since we cannot know our future alignment, |
443 // assume the worst. | 445 // assume the worst. |
444 if (i< nblocks-1) { | 446 if (i < nblocks - 1) { |
445 Block *nb = _cfg->_blocks[i+1]; | 447 Block* nb = _cfg->get_block(i + 1); |
446 int max_loop_pad = nb->code_alignment()-relocInfo::addr_unit(); | 448 int max_loop_pad = nb->code_alignment()-relocInfo::addr_unit(); |
447 if (max_loop_pad > 0) { | 449 if (max_loop_pad > 0) { |
448 assert(is_power_of_2(max_loop_pad+relocInfo::addr_unit()), ""); | 450 assert(is_power_of_2(max_loop_pad+relocInfo::addr_unit()), ""); |
449 // Adjust last_call_adr and/or last_avoid_back_to_back_adr. | 451 // Adjust last_call_adr and/or last_avoid_back_to_back_adr. |
450 // If either is the last instruction in this block, bump by | 452 // If either is the last instruction in this block, bump by |
471 while (has_short_branch_candidate && progress) { | 473 while (has_short_branch_candidate && progress) { |
472 progress = false; | 474 progress = false; |
473 has_short_branch_candidate = false; | 475 has_short_branch_candidate = false; |
474 int adjust_block_start = 0; | 476 int adjust_block_start = 0; |
475 for (uint i = 0; i < nblocks; i++) { | 477 for (uint i = 0; i < nblocks; i++) { |
476 Block *b = _cfg->_blocks[i]; | 478 Block* block = _cfg->get_block(i); |
477 int idx = jmp_nidx[i]; | 479 int idx = jmp_nidx[i]; |
478 MachNode* mach = (idx == -1) ? NULL: b->_nodes[idx]->as_Mach(); | 480 MachNode* mach = (idx == -1) ? NULL: block->get_node(idx)->as_Mach(); |
479 if (mach != NULL && mach->may_be_short_branch()) { | 481 if (mach != NULL && mach->may_be_short_branch()) { |
480 #ifdef ASSERT | 482 #ifdef ASSERT |
481 assert(jmp_size[i] > 0 && mach->is_MachBranch(), "sanity"); | 483 assert(jmp_size[i] > 0 && mach->is_MachBranch(), "sanity"); |
482 int j; | 484 int j; |
483 // Find the branch; ignore trailing NOPs. | 485 // Find the branch; ignore trailing NOPs. |
484 for (j = b->_nodes.size()-1; j>=0; j--) { | 486 for (j = block->number_of_nodes()-1; j>=0; j--) { |
485 Node* n = b->_nodes[j]; | 487 Node* n = block->get_node(j); |
486 if (!n->is_Mach() || n->as_Mach()->ideal_Opcode() != Op_Con) | 488 if (!n->is_Mach() || n->as_Mach()->ideal_Opcode() != Op_Con) |
487 break; | 489 break; |
488 } | 490 } |
489 assert(j >= 0 && j == idx && b->_nodes[j] == (Node*)mach, "sanity"); | 491 assert(j >= 0 && j == idx && block->get_node(j) == (Node*)mach, "sanity"); |
490 #endif | 492 #endif |
491 int br_size = jmp_size[i]; | 493 int br_size = jmp_size[i]; |
492 int br_offs = blk_starts[i] + jmp_offset[i]; | 494 int br_offs = blk_starts[i] + jmp_offset[i]; |
493 | 495 |
494 // This requires the TRUE branch target be in succs[0] | 496 // This requires the TRUE branch target be in succs[0] |
495 uint bnum = b->non_connector_successor(0)->_pre_order; | 497 uint bnum = block->non_connector_successor(0)->_pre_order; |
496 int offset = blk_starts[bnum] - br_offs; | 498 int offset = blk_starts[bnum] - br_offs; |
497 if (bnum > i) { // adjust following block's offset | 499 if (bnum > i) { // adjust following block's offset |
498 offset -= adjust_block_start; | 500 offset -= adjust_block_start; |
499 } | 501 } |
500 // In the following code a nop could be inserted before | 502 // In the following code a nop could be inserted before |
518 if (needs_padding && replacement->avoid_back_to_back()) { | 520 if (needs_padding && replacement->avoid_back_to_back()) { |
519 jmp_offset[i] += nop_size; | 521 jmp_offset[i] += nop_size; |
520 diff -= nop_size; | 522 diff -= nop_size; |
521 } | 523 } |
522 adjust_block_start += diff; | 524 adjust_block_start += diff; |
523 b->_nodes.map(idx, replacement); | 525 block->map_node(replacement, idx); |
524 mach->subsume_by(replacement, C); | 526 mach->subsume_by(replacement, C); |
525 mach = replacement; | 527 mach = replacement; |
526 progress = true; | 528 progress = true; |
527 | 529 |
528 jmp_size[i] = new_size; | 530 jmp_size[i] = new_size; |
635 cik->is_array_klass(), "Not supported allocation."); | 637 cik->is_array_klass(), "Not supported allocation."); |
636 sv = new ObjectValue(spobj->_idx, | 638 sv = new ObjectValue(spobj->_idx, |
637 new ConstantOopWriteValue(cik->java_mirror()->constant_encoding())); | 639 new ConstantOopWriteValue(cik->java_mirror()->constant_encoding())); |
638 Compile::set_sv_for_object_node(objs, sv); | 640 Compile::set_sv_for_object_node(objs, sv); |
639 | 641 |
640 uint first_ind = spobj->first_index(); | 642 uint first_ind = spobj->first_index(sfpt->jvms()); |
641 for (uint i = 0; i < spobj->n_fields(); i++) { | 643 for (uint i = 0; i < spobj->n_fields(); i++) { |
642 Node* fld_node = sfpt->in(first_ind+i); | 644 Node* fld_node = sfpt->in(first_ind+i); |
643 (void)FillLocArray(sv->field_values()->length(), sfpt, fld_node, sv->field_values(), objs); | 645 (void)FillLocArray(sv->field_values()->length(), sfpt, fld_node, sv->field_values(), objs); |
644 } | 646 } |
645 } | 647 } |
890 | 892 |
891 // Build the growable array of ScopeValues for exp stack | 893 // Build the growable array of ScopeValues for exp stack |
892 GrowableArray<MonitorValue*> *monarray = new GrowableArray<MonitorValue*>(num_mon); | 894 GrowableArray<MonitorValue*> *monarray = new GrowableArray<MonitorValue*>(num_mon); |
893 | 895 |
894 // Loop over monitors and insert into array | 896 // Loop over monitors and insert into array |
895 for(idx = 0; idx < num_mon; idx++) { | 897 for (idx = 0; idx < num_mon; idx++) { |
896 // Grab the node that defines this monitor | 898 // Grab the node that defines this monitor |
897 Node* box_node = sfn->monitor_box(jvms, idx); | 899 Node* box_node = sfn->monitor_box(jvms, idx); |
898 Node* obj_node = sfn->monitor_obj(jvms, idx); | 900 Node* obj_node = sfn->monitor_obj(jvms, idx); |
899 | 901 |
900 // Create ScopeValue for object | 902 // Create ScopeValue for object |
901 ScopeValue *scval = NULL; | 903 ScopeValue *scval = NULL; |
902 | 904 |
903 if( obj_node->is_SafePointScalarObject() ) { | 905 if (obj_node->is_SafePointScalarObject()) { |
904 SafePointScalarObjectNode* spobj = obj_node->as_SafePointScalarObject(); | 906 SafePointScalarObjectNode* spobj = obj_node->as_SafePointScalarObject(); |
905 scval = Compile::sv_for_node_id(objs, spobj->_idx); | 907 scval = Compile::sv_for_node_id(objs, spobj->_idx); |
906 if (scval == NULL) { | 908 if (scval == NULL) { |
907 const Type *t = obj_node->bottom_type(); | 909 const Type *t = spobj->bottom_type(); |
908 ciKlass* cik = t->is_oopptr()->klass(); | 910 ciKlass* cik = t->is_oopptr()->klass(); |
909 assert(cik->is_instance_klass() || | 911 assert(cik->is_instance_klass() || |
910 cik->is_array_klass(), "Not supported allocation."); | 912 cik->is_array_klass(), "Not supported allocation."); |
911 ObjectValue* sv = new ObjectValue(spobj->_idx, | 913 ObjectValue* sv = new ObjectValue(spobj->_idx, |
912 new ConstantOopWriteValue(cik->java_mirror()->constant_encoding())); | 914 new ConstantOopWriteValue(cik->java_mirror()->constant_encoding())); |
913 Compile::set_sv_for_object_node(objs, sv); | 915 Compile::set_sv_for_object_node(objs, sv); |
914 | 916 |
915 uint first_ind = spobj->first_index(); | 917 uint first_ind = spobj->first_index(youngest_jvms); |
916 for (uint i = 0; i < spobj->n_fields(); i++) { | 918 for (uint i = 0; i < spobj->n_fields(); i++) { |
917 Node* fld_node = sfn->in(first_ind+i); | 919 Node* fld_node = sfn->in(first_ind+i); |
918 (void)FillLocArray(sv->field_values()->length(), sfn, fld_node, sv->field_values(), objs); | 920 (void)FillLocArray(sv->field_values()->length(), sfn, fld_node, sv->field_values(), objs); |
919 } | 921 } |
920 scval = sv; | 922 scval = sv; |
921 } | 923 } |
922 } else if( !obj_node->is_Con() ) { | 924 } else if (!obj_node->is_Con()) { |
923 OptoReg::Name obj_reg = _regalloc->get_reg_first(obj_node); | 925 OptoReg::Name obj_reg = _regalloc->get_reg_first(obj_node); |
924 if( obj_node->bottom_type()->base() == Type::NarrowOop ) { | 926 if( obj_node->bottom_type()->base() == Type::NarrowOop ) { |
925 scval = new_loc_value( _regalloc, obj_reg, Location::narrowoop ); | 927 scval = new_loc_value( _regalloc, obj_reg, Location::narrowoop ); |
926 } else { | 928 } else { |
927 scval = new_loc_value( _regalloc, obj_reg, Location::oop ); | 929 scval = new_loc_value( _regalloc, obj_reg, Location::oop ); |
1084 assert(_frame_slots >= 0 && _frame_slots < 1000000, "sanity check"); | 1086 assert(_frame_slots >= 0 && _frame_slots < 1000000, "sanity check"); |
1085 | 1087 |
1086 if (has_mach_constant_base_node()) { | 1088 if (has_mach_constant_base_node()) { |
1087 // Fill the constant table. | 1089 // Fill the constant table. |
1088 // Note: This must happen before shorten_branches. | 1090 // Note: This must happen before shorten_branches. |
1089 for (uint i = 0; i < _cfg->_num_blocks; i++) { | 1091 for (uint i = 0; i < _cfg->number_of_blocks(); i++) { |
1090 Block* b = _cfg->_blocks[i]; | 1092 Block* b = _cfg->get_block(i); |
1091 | 1093 |
1092 for (uint j = 0; j < b->_nodes.size(); j++) { | 1094 for (uint j = 0; j < b->number_of_nodes(); j++) { |
1093 Node* n = b->_nodes[j]; | 1095 Node* n = b->get_node(j); |
1094 | 1096 |
1095 // If the node is a MachConstantNode evaluate the constant | 1097 // If the node is a MachConstantNode evaluate the constant |
1096 // value section. | 1098 // value section. |
1097 if (n->is_MachConstant()) { | 1099 if (n->is_MachConstant()) { |
1098 MachConstantNode* machcon = n->as_MachConstant(); | 1100 MachConstantNode* machcon = n->as_MachConstant(); |
1171 _oop_map_set = new OopMapSet(); | 1173 _oop_map_set = new OopMapSet(); |
1172 | 1174 |
1173 // !!!!! This preserves old handling of oopmaps for now | 1175 // !!!!! This preserves old handling of oopmaps for now |
1174 debug_info()->set_oopmaps(_oop_map_set); | 1176 debug_info()->set_oopmaps(_oop_map_set); |
1175 | 1177 |
1176 uint nblocks = _cfg->_num_blocks; | 1178 uint nblocks = _cfg->number_of_blocks(); |
1177 // Count and start of implicit null check instructions | 1179 // Count and start of implicit null check instructions |
1178 uint inct_cnt = 0; | 1180 uint inct_cnt = 0; |
1179 uint *inct_starts = NEW_RESOURCE_ARRAY(uint, nblocks+1); | 1181 uint *inct_starts = NEW_RESOURCE_ARRAY(uint, nblocks+1); |
1180 | 1182 |
1181 // Count and start of calls | 1183 // Count and start of calls |
1219 | 1221 |
1220 // ------------------ | 1222 // ------------------ |
1221 // Now fill in the code buffer | 1223 // Now fill in the code buffer |
1222 Node *delay_slot = NULL; | 1224 Node *delay_slot = NULL; |
1223 | 1225 |
1224 for (uint i=0; i < nblocks; i++) { | 1226 for (uint i = 0; i < nblocks; i++) { |
1225 Block *b = _cfg->_blocks[i]; | 1227 Block* block = _cfg->get_block(i); |
1226 | 1228 Node* head = block->head(); |
1227 Node *head = b->head(); | |
1228 | 1229 |
1229 // If this block needs to start aligned (i.e, can be reached other | 1230 // If this block needs to start aligned (i.e, can be reached other |
1230 // than by falling-thru from the previous block), then force the | 1231 // than by falling-thru from the previous block), then force the |
1231 // start of a new bundle. | 1232 // start of a new bundle. |
1232 if (Pipeline::requires_bundling() && starts_bundle(head)) | 1233 if (Pipeline::requires_bundling() && starts_bundle(head)) { |
1233 cb->flush_bundle(true); | 1234 cb->flush_bundle(true); |
1235 } | |
1234 | 1236 |
1235 #ifdef ASSERT | 1237 #ifdef ASSERT |
1236 if (!b->is_connector()) { | 1238 if (!block->is_connector()) { |
1237 stringStream st; | 1239 stringStream st; |
1238 b->dump_head(_cfg, &st); | 1240 block->dump_head(_cfg, &st); |
1239 MacroAssembler(cb).block_comment(st.as_string()); | 1241 MacroAssembler(cb).block_comment(st.as_string()); |
1240 } | 1242 } |
1241 jmp_target[i] = 0; | 1243 jmp_target[i] = 0; |
1242 jmp_offset[i] = 0; | 1244 jmp_offset[i] = 0; |
1243 jmp_size[i] = 0; | 1245 jmp_size[i] = 0; |
1244 jmp_rule[i] = 0; | 1246 jmp_rule[i] = 0; |
1245 #endif | 1247 #endif |
1246 int blk_offset = current_offset; | 1248 int blk_offset = current_offset; |
1247 | 1249 |
1248 // Define the label at the beginning of the basic block | 1250 // Define the label at the beginning of the basic block |
1249 MacroAssembler(cb).bind(blk_labels[b->_pre_order]); | 1251 MacroAssembler(cb).bind(blk_labels[block->_pre_order]); |
1250 | 1252 |
1251 uint last_inst = b->_nodes.size(); | 1253 uint last_inst = block->number_of_nodes(); |
1252 | 1254 |
1253 // Emit block normally, except for last instruction. | 1255 // Emit block normally, except for last instruction. |
1254 // Emit means "dump code bits into code buffer". | 1256 // Emit means "dump code bits into code buffer". |
1255 for (uint j = 0; j<last_inst; j++) { | 1257 for (uint j = 0; j<last_inst; j++) { |
1256 | 1258 |
1257 // Get the node | 1259 // Get the node |
1258 Node* n = b->_nodes[j]; | 1260 Node* n = block->get_node(j); |
1259 | 1261 |
1260 // See if delay slots are supported | 1262 // See if delay slots are supported |
1261 if (valid_bundle_info(n) && | 1263 if (valid_bundle_info(n) && |
1262 node_bundling(n)->used_in_unconditional_delay()) { | 1264 node_bundling(n)->used_in_unconditional_delay()) { |
1263 assert(delay_slot == NULL, "no use of delay slot node"); | 1265 assert(delay_slot == NULL, "no use of delay slot node"); |
1307 | 1309 |
1308 if(padding > 0) { | 1310 if(padding > 0) { |
1309 assert((padding % nop_size) == 0, "padding is not a multiple of NOP size"); | 1311 assert((padding % nop_size) == 0, "padding is not a multiple of NOP size"); |
1310 int nops_cnt = padding / nop_size; | 1312 int nops_cnt = padding / nop_size; |
1311 MachNode *nop = new (this) MachNopNode(nops_cnt); | 1313 MachNode *nop = new (this) MachNopNode(nops_cnt); |
1312 b->_nodes.insert(j++, nop); | 1314 block->insert_node(nop, j++); |
1313 last_inst++; | 1315 last_inst++; |
1314 _cfg->map_node_to_block(nop, b); | 1316 _cfg->map_node_to_block(nop, block); |
1315 nop->emit(*cb, _regalloc); | 1317 nop->emit(*cb, _regalloc); |
1316 cb->flush_bundle(true); | 1318 cb->flush_bundle(true); |
1317 current_offset = cb->insts_size(); | 1319 current_offset = cb->insts_size(); |
1318 } | 1320 } |
1319 | 1321 |
1323 | 1325 |
1324 // This destination address is NOT PC-relative | 1326 // This destination address is NOT PC-relative |
1325 mcall->method_set((intptr_t)mcall->entry_point()); | 1327 mcall->method_set((intptr_t)mcall->entry_point()); |
1326 | 1328 |
1327 // Save the return address | 1329 // Save the return address |
1328 call_returns[b->_pre_order] = current_offset + mcall->ret_addr_offset(); | 1330 call_returns[block->_pre_order] = current_offset + mcall->ret_addr_offset(); |
1329 | 1331 |
1330 if (mcall->is_MachCallLeaf()) { | 1332 if (mcall->is_MachCallLeaf()) { |
1331 is_mcall = false; | 1333 is_mcall = false; |
1332 is_sfn = false; | 1334 is_sfn = false; |
1333 } | 1335 } |
1360 } | 1362 } |
1361 | 1363 |
1362 // If this is a branch, then fill in the label with the target BB's label | 1364 // If this is a branch, then fill in the label with the target BB's label |
1363 else if (mach->is_MachBranch()) { | 1365 else if (mach->is_MachBranch()) { |
1364 // This requires the TRUE branch target be in succs[0] | 1366 // This requires the TRUE branch target be in succs[0] |
1365 uint block_num = b->non_connector_successor(0)->_pre_order; | 1367 uint block_num = block->non_connector_successor(0)->_pre_order; |
1366 | 1368 |
1367 // Try to replace long branch if delay slot is not used, | 1369 // Try to replace long branch if delay slot is not used, |
1368 // it is mostly for back branches since forward branch's | 1370 // it is mostly for back branches since forward branch's |
1369 // distance is not updated yet. | 1371 // distance is not updated yet. |
1370 bool delay_slot_is_used = valid_bundle_info(n) && | 1372 bool delay_slot_is_used = valid_bundle_info(n) && |
1393 int new_size = replacement->size(_regalloc); | 1395 int new_size = replacement->size(_regalloc); |
1394 assert((br_size - new_size) >= (int)nop_size, "short_branch size should be smaller"); | 1396 assert((br_size - new_size) >= (int)nop_size, "short_branch size should be smaller"); |
1395 // Insert padding between avoid_back_to_back branches. | 1397 // Insert padding between avoid_back_to_back branches. |
1396 if (needs_padding && replacement->avoid_back_to_back()) { | 1398 if (needs_padding && replacement->avoid_back_to_back()) { |
1397 MachNode *nop = new (this) MachNopNode(); | 1399 MachNode *nop = new (this) MachNopNode(); |
1398 b->_nodes.insert(j++, nop); | 1400 block->insert_node(nop, j++); |
1399 _cfg->map_node_to_block(nop, b); | 1401 _cfg->map_node_to_block(nop, block); |
1400 last_inst++; | 1402 last_inst++; |
1401 nop->emit(*cb, _regalloc); | 1403 nop->emit(*cb, _regalloc); |
1402 cb->flush_bundle(true); | 1404 cb->flush_bundle(true); |
1403 current_offset = cb->insts_size(); | 1405 current_offset = cb->insts_size(); |
1404 } | 1406 } |
1406 jmp_target[i] = block_num; | 1408 jmp_target[i] = block_num; |
1407 jmp_offset[i] = current_offset - blk_offset; | 1409 jmp_offset[i] = current_offset - blk_offset; |
1408 jmp_size[i] = new_size; | 1410 jmp_size[i] = new_size; |
1409 jmp_rule[i] = mach->rule(); | 1411 jmp_rule[i] = mach->rule(); |
1410 #endif | 1412 #endif |
1411 b->_nodes.map(j, replacement); | 1413 block->map_node(replacement, j); |
1412 mach->subsume_by(replacement, C); | 1414 mach->subsume_by(replacement, C); |
1413 n = replacement; | 1415 n = replacement; |
1414 mach = replacement; | 1416 mach = replacement; |
1415 } | 1417 } |
1416 } | 1418 } |
1417 mach->as_MachBranch()->label_set( &blk_labels[block_num], block_num ); | 1419 mach->as_MachBranch()->label_set( &blk_labels[block_num], block_num ); |
1418 } else if (mach->ideal_Opcode() == Op_Jump) { | 1420 } else if (mach->ideal_Opcode() == Op_Jump) { |
1419 for (uint h = 0; h < b->_num_succs; h++) { | 1421 for (uint h = 0; h < block->_num_succs; h++) { |
1420 Block* succs_block = b->_succs[h]; | 1422 Block* succs_block = block->_succs[h]; |
1421 for (uint j = 1; j < succs_block->num_preds(); j++) { | 1423 for (uint j = 1; j < succs_block->num_preds(); j++) { |
1422 Node* jpn = succs_block->pred(j); | 1424 Node* jpn = succs_block->pred(j); |
1423 if (jpn->is_JumpProj() && jpn->in(0) == mach) { | 1425 if (jpn->is_JumpProj() && jpn->in(0) == mach) { |
1424 uint block_num = succs_block->non_connector()->_pre_order; | 1426 uint block_num = succs_block->non_connector()->_pre_order; |
1425 Label *blkLabel = &blk_labels[block_num]; | 1427 Label *blkLabel = &blk_labels[block_num]; |
1426 mach->add_case_label(jpn->as_JumpProj()->proj_no(), blkLabel); | 1428 mach->add_case_label(jpn->as_JumpProj()->proj_no(), blkLabel); |
1427 } | 1429 } |
1428 } | 1430 } |
1429 } | 1431 } |
1430 } | 1432 } |
1431 | |
1432 #ifdef ASSERT | 1433 #ifdef ASSERT |
1433 // Check that oop-store precedes the card-mark | 1434 // Check that oop-store precedes the card-mark |
1434 else if (mach->ideal_Opcode() == Op_StoreCM) { | 1435 else if (mach->ideal_Opcode() == Op_StoreCM) { |
1435 uint storeCM_idx = j; | 1436 uint storeCM_idx = j; |
1436 int count = 0; | 1437 int count = 0; |
1437 for (uint prec = mach->req(); prec < mach->len(); prec++) { | 1438 for (uint prec = mach->req(); prec < mach->len(); prec++) { |
1438 Node *oop_store = mach->in(prec); // Precedence edge | 1439 Node *oop_store = mach->in(prec); // Precedence edge |
1439 if (oop_store == NULL) continue; | 1440 if (oop_store == NULL) continue; |
1440 count++; | 1441 count++; |
1441 uint i4; | 1442 uint i4; |
1442 for( i4 = 0; i4 < last_inst; ++i4 ) { | 1443 for (i4 = 0; i4 < last_inst; ++i4) { |
1443 if( b->_nodes[i4] == oop_store ) break; | 1444 if (block->get_node(i4) == oop_store) { |
1445 break; | |
1446 } | |
1444 } | 1447 } |
1445 // Note: This test can provide a false failure if other precedence | 1448 // Note: This test can provide a false failure if other precedence |
1446 // edges have been added to the storeCMNode. | 1449 // edges have been added to the storeCMNode. |
1447 assert( i4 == last_inst || i4 < storeCM_idx, "CM card-mark executes before oop-store"); | 1450 assert(i4 == last_inst || i4 < storeCM_idx, "CM card-mark executes before oop-store"); |
1448 } | 1451 } |
1449 assert(count > 0, "storeCM expects at least one precedence edge"); | 1452 assert(count > 0, "storeCM expects at least one precedence edge"); |
1450 } | 1453 } |
1451 #endif | 1454 #endif |
1452 | |
1453 else if (!n->is_Proj()) { | 1455 else if (!n->is_Proj()) { |
1454 // Remember the beginning of the previous instruction, in case | 1456 // Remember the beginning of the previous instruction, in case |
1455 // it's followed by a flag-kill and a null-check. Happens on | 1457 // it's followed by a flag-kill and a null-check. Happens on |
1456 // Intel all the time, with add-to-memory kind of opcodes. | 1458 // Intel all the time, with add-to-memory kind of opcodes. |
1457 previous_offset = current_offset; | 1459 previous_offset = current_offset; |
1543 } // End for all instructions in block | 1545 } // End for all instructions in block |
1544 | 1546 |
1545 // If the next block is the top of a loop, pad this block out to align | 1547 // If the next block is the top of a loop, pad this block out to align |
1546 // the loop top a little. Helps prevent pipe stalls at loop back branches. | 1548 // the loop top a little. Helps prevent pipe stalls at loop back branches. |
1547 if (i < nblocks-1) { | 1549 if (i < nblocks-1) { |
1548 Block *nb = _cfg->_blocks[i+1]; | 1550 Block *nb = _cfg->get_block(i + 1); |
1549 int padding = nb->alignment_padding(current_offset); | 1551 int padding = nb->alignment_padding(current_offset); |
1550 if( padding > 0 ) { | 1552 if( padding > 0 ) { |
1551 MachNode *nop = new (this) MachNopNode(padding / nop_size); | 1553 MachNode *nop = new (this) MachNopNode(padding / nop_size); |
1552 b->_nodes.insert( b->_nodes.size(), nop ); | 1554 block->insert_node(nop, block->number_of_nodes()); |
1553 _cfg->map_node_to_block(nop, b); | 1555 _cfg->map_node_to_block(nop, block); |
1554 nop->emit(*cb, _regalloc); | 1556 nop->emit(*cb, _regalloc); |
1555 current_offset = cb->insts_size(); | 1557 current_offset = cb->insts_size(); |
1556 } | 1558 } |
1557 } | 1559 } |
1558 // Verify that the distance for generated before forward | 1560 // Verify that the distance for generated before forward |
1587 assert(false, "Displacement too large for short jmp"); | 1589 assert(false, "Displacement too large for short jmp"); |
1588 } | 1590 } |
1589 } | 1591 } |
1590 } | 1592 } |
1591 #endif | 1593 #endif |
1592 | |
1593 // ------------------ | |
1594 | 1594 |
1595 #ifndef PRODUCT | 1595 #ifndef PRODUCT |
1596 // Information on the size of the method, without the extraneous code | 1596 // Information on the size of the method, without the extraneous code |
1597 Scheduling::increment_method_size(cb->insts_size()); | 1597 Scheduling::increment_method_size(cb->insts_size()); |
1598 #endif | 1598 #endif |
1650 | 1650 |
1651 void Compile::FillExceptionTables(uint cnt, uint *call_returns, uint *inct_starts, Label *blk_labels) { | 1651 void Compile::FillExceptionTables(uint cnt, uint *call_returns, uint *inct_starts, Label *blk_labels) { |
1652 _inc_table.set_size(cnt); | 1652 _inc_table.set_size(cnt); |
1653 | 1653 |
1654 uint inct_cnt = 0; | 1654 uint inct_cnt = 0; |
1655 for( uint i=0; i<_cfg->_num_blocks; i++ ) { | 1655 for (uint i = 0; i < _cfg->number_of_blocks(); i++) { |
1656 Block *b = _cfg->_blocks[i]; | 1656 Block* block = _cfg->get_block(i); |
1657 Node *n = NULL; | 1657 Node *n = NULL; |
1658 int j; | 1658 int j; |
1659 | 1659 |
1660 // Find the branch; ignore trailing NOPs. | 1660 // Find the branch; ignore trailing NOPs. |
1661 for( j = b->_nodes.size()-1; j>=0; j-- ) { | 1661 for (j = block->number_of_nodes() - 1; j >= 0; j--) { |
1662 n = b->_nodes[j]; | 1662 n = block->get_node(j); |
1663 if( !n->is_Mach() || n->as_Mach()->ideal_Opcode() != Op_Con ) | 1663 if (!n->is_Mach() || n->as_Mach()->ideal_Opcode() != Op_Con) { |
1664 break; | 1664 break; |
1665 } | |
1665 } | 1666 } |
1666 | 1667 |
1667 // If we didn't find anything, continue | 1668 // If we didn't find anything, continue |
1668 if( j < 0 ) continue; | 1669 if (j < 0) { |
1670 continue; | |
1671 } | |
1669 | 1672 |
1670 // Compute ExceptionHandlerTable subtable entry and add it | 1673 // Compute ExceptionHandlerTable subtable entry and add it |
1671 // (skip empty blocks) | 1674 // (skip empty blocks) |
1672 if( n->is_Catch() ) { | 1675 if (n->is_Catch()) { |
1673 | 1676 |
1674 // Get the offset of the return from the call | 1677 // Get the offset of the return from the call |
1675 uint call_return = call_returns[b->_pre_order]; | 1678 uint call_return = call_returns[block->_pre_order]; |
1676 #ifdef ASSERT | 1679 #ifdef ASSERT |
1677 assert( call_return > 0, "no call seen for this basic block" ); | 1680 assert( call_return > 0, "no call seen for this basic block" ); |
1678 while( b->_nodes[--j]->is_MachProj() ) ; | 1681 while (block->get_node(--j)->is_MachProj()) ; |
1679 assert( b->_nodes[j]->is_MachCall(), "CatchProj must follow call" ); | 1682 assert(block->get_node(j)->is_MachCall(), "CatchProj must follow call"); |
1680 #endif | 1683 #endif |
1681 // last instruction is a CatchNode, find it's CatchProjNodes | 1684 // last instruction is a CatchNode, find it's CatchProjNodes |
1682 int nof_succs = b->_num_succs; | 1685 int nof_succs = block->_num_succs; |
1683 // allocate space | 1686 // allocate space |
1684 GrowableArray<intptr_t> handler_bcis(nof_succs); | 1687 GrowableArray<intptr_t> handler_bcis(nof_succs); |
1685 GrowableArray<intptr_t> handler_pcos(nof_succs); | 1688 GrowableArray<intptr_t> handler_pcos(nof_succs); |
1686 // iterate through all successors | 1689 // iterate through all successors |
1687 for (int j = 0; j < nof_succs; j++) { | 1690 for (int j = 0; j < nof_succs; j++) { |
1688 Block* s = b->_succs[j]; | 1691 Block* s = block->_succs[j]; |
1689 bool found_p = false; | 1692 bool found_p = false; |
1690 for( uint k = 1; k < s->num_preds(); k++ ) { | 1693 for (uint k = 1; k < s->num_preds(); k++) { |
1691 Node *pk = s->pred(k); | 1694 Node* pk = s->pred(k); |
1692 if( pk->is_CatchProj() && pk->in(0) == n ) { | 1695 if (pk->is_CatchProj() && pk->in(0) == n) { |
1693 const CatchProjNode* p = pk->as_CatchProj(); | 1696 const CatchProjNode* p = pk->as_CatchProj(); |
1694 found_p = true; | 1697 found_p = true; |
1695 // add the corresponding handler bci & pco information | 1698 // add the corresponding handler bci & pco information |
1696 if( p->_con != CatchProjNode::fall_through_index ) { | 1699 if (p->_con != CatchProjNode::fall_through_index) { |
1697 // p leads to an exception handler (and is not fall through) | 1700 // p leads to an exception handler (and is not fall through) |
1698 assert(s == _cfg->_blocks[s->_pre_order],"bad numbering"); | 1701 assert(s == _cfg->get_block(s->_pre_order), "bad numbering"); |
1699 // no duplicates, please | 1702 // no duplicates, please |
1700 if( !handler_bcis.contains(p->handler_bci()) ) { | 1703 if (!handler_bcis.contains(p->handler_bci())) { |
1701 uint block_num = s->non_connector()->_pre_order; | 1704 uint block_num = s->non_connector()->_pre_order; |
1702 handler_bcis.append(p->handler_bci()); | 1705 handler_bcis.append(p->handler_bci()); |
1703 handler_pcos.append(blk_labels[block_num].loc_pos()); | 1706 handler_pcos.append(blk_labels[block_num].loc_pos()); |
1704 } | 1707 } |
1705 } | 1708 } |
1714 _handler_table.add_subtable(call_return, &handler_bcis, NULL, &handler_pcos); | 1717 _handler_table.add_subtable(call_return, &handler_bcis, NULL, &handler_pcos); |
1715 continue; | 1718 continue; |
1716 } | 1719 } |
1717 | 1720 |
1718 // Handle implicit null exception table updates | 1721 // Handle implicit null exception table updates |
1719 if( n->is_MachNullCheck() ) { | 1722 if (n->is_MachNullCheck()) { |
1720 uint block_num = b->non_connector_successor(0)->_pre_order; | 1723 uint block_num = block->non_connector_successor(0)->_pre_order; |
1721 _inc_table.append( inct_starts[inct_cnt++], blk_labels[block_num].loc_pos() ); | 1724 _inc_table.append(inct_starts[inct_cnt++], blk_labels[block_num].loc_pos()); |
1722 continue; | 1725 continue; |
1723 } | 1726 } |
1724 } // End of for all blocks fill in exception table entries | 1727 } // End of for all blocks fill in exception table entries |
1725 } | 1728 } |
1726 | 1729 |
1775 memset(_node_latency, 0, node_max * sizeof(unsigned short)); | 1778 memset(_node_latency, 0, node_max * sizeof(unsigned short)); |
1776 memset(_uses, 0, node_max * sizeof(short)); | 1779 memset(_uses, 0, node_max * sizeof(short)); |
1777 memset(_current_latency, 0, node_max * sizeof(unsigned short)); | 1780 memset(_current_latency, 0, node_max * sizeof(unsigned short)); |
1778 | 1781 |
1779 // Clear the bundling information | 1782 // Clear the bundling information |
1780 memcpy(_bundle_use_elements, | 1783 memcpy(_bundle_use_elements, Pipeline_Use::elaborated_elements, sizeof(Pipeline_Use::elaborated_elements)); |
1781 Pipeline_Use::elaborated_elements, | |
1782 sizeof(Pipeline_Use::elaborated_elements)); | |
1783 | 1784 |
1784 // Get the last node | 1785 // Get the last node |
1785 Block *bb = _cfg->_blocks[_cfg->_blocks.size()-1]; | 1786 Block* block = _cfg->get_block(_cfg->number_of_blocks() - 1); |
1786 | 1787 |
1787 _next_node = bb->_nodes[bb->_nodes.size()-1]; | 1788 _next_node = block->get_node(block->number_of_nodes() - 1); |
1788 } | 1789 } |
1789 | 1790 |
1790 #ifndef PRODUCT | 1791 #ifndef PRODUCT |
1791 // Scheduling destructor | 1792 // Scheduling destructor |
1792 Scheduling::~Scheduling() { | 1793 Scheduling::~Scheduling() { |
1832 memcpy(_bundle_use_elements, | 1833 memcpy(_bundle_use_elements, |
1833 Pipeline_Use::elaborated_elements, | 1834 Pipeline_Use::elaborated_elements, |
1834 sizeof(Pipeline_Use::elaborated_elements)); | 1835 sizeof(Pipeline_Use::elaborated_elements)); |
1835 } | 1836 } |
1836 | 1837 |
1837 //------------------------------ScheduleAndBundle------------------------------ | |
1838 // Perform instruction scheduling and bundling over the sequence of | 1838 // Perform instruction scheduling and bundling over the sequence of |
1839 // instructions in backwards order. | 1839 // instructions in backwards order. |
1840 void Compile::ScheduleAndBundle() { | 1840 void Compile::ScheduleAndBundle() { |
1841 | 1841 |
1842 // Don't optimize this if it isn't a method | 1842 // Don't optimize this if it isn't a method |
1859 // Walk backwards over each basic block, computing the needed alignment | 1859 // Walk backwards over each basic block, computing the needed alignment |
1860 // Walk over all the basic blocks | 1860 // Walk over all the basic blocks |
1861 scheduling.DoScheduling(); | 1861 scheduling.DoScheduling(); |
1862 } | 1862 } |
1863 | 1863 |
1864 //------------------------------ComputeLocalLatenciesForward------------------- | |
1865 // Compute the latency of all the instructions. This is fairly simple, | 1864 // Compute the latency of all the instructions. This is fairly simple, |
1866 // because we already have a legal ordering. Walk over the instructions | 1865 // because we already have a legal ordering. Walk over the instructions |
1867 // from first to last, and compute the latency of the instruction based | 1866 // from first to last, and compute the latency of the instruction based |
1868 // on the latency of the preceding instruction(s). | 1867 // on the latency of the preceding instruction(s). |
1869 void Scheduling::ComputeLocalLatenciesForward(const Block *bb) { | 1868 void Scheduling::ComputeLocalLatenciesForward(const Block *bb) { |
1877 | 1876 |
1878 // This is a kludge, forcing all latency calculations to start at 1. | 1877 // This is a kludge, forcing all latency calculations to start at 1. |
1879 // Used to allow latency 0 to force an instruction to the beginning | 1878 // Used to allow latency 0 to force an instruction to the beginning |
1880 // of the bb | 1879 // of the bb |
1881 uint latency = 1; | 1880 uint latency = 1; |
1882 Node *use = bb->_nodes[j]; | 1881 Node *use = bb->get_node(j); |
1883 uint nlen = use->len(); | 1882 uint nlen = use->len(); |
1884 | 1883 |
1885 // Walk over all the inputs | 1884 // Walk over all the inputs |
1886 for ( uint k=0; k < nlen; k++ ) { | 1885 for ( uint k=0; k < nlen; k++ ) { |
1887 Node *def = use->in(k); | 1886 Node *def = use->in(k); |
2029 #endif | 2028 #endif |
2030 | 2029 |
2031 return _available[0]; | 2030 return _available[0]; |
2032 } | 2031 } |
2033 | 2032 |
2034 //------------------------------AddNodeToAvailableList------------------------- | |
2035 void Scheduling::AddNodeToAvailableList(Node *n) { | 2033 void Scheduling::AddNodeToAvailableList(Node *n) { |
2036 assert( !n->is_Proj(), "projections never directly made available" ); | 2034 assert( !n->is_Proj(), "projections never directly made available" ); |
2037 #ifndef PRODUCT | 2035 #ifndef PRODUCT |
2038 if (_cfg->C->trace_opto_output()) { | 2036 if (_cfg->C->trace_opto_output()) { |
2039 tty->print("# AddNodeToAvailableList: "); | 2037 tty->print("# AddNodeToAvailableList: "); |
2075 if (_cfg->C->trace_opto_output()) | 2073 if (_cfg->C->trace_opto_output()) |
2076 dump_available(); | 2074 dump_available(); |
2077 #endif | 2075 #endif |
2078 } | 2076 } |
2079 | 2077 |
2080 //------------------------------DecrementUseCounts----------------------------- | |
2081 void Scheduling::DecrementUseCounts(Node *n, const Block *bb) { | 2078 void Scheduling::DecrementUseCounts(Node *n, const Block *bb) { |
2082 for ( uint i=0; i < n->len(); i++ ) { | 2079 for ( uint i=0; i < n->len(); i++ ) { |
2083 Node *def = n->in(i); | 2080 Node *def = n->in(i); |
2084 if (!def) continue; | 2081 if (!def) continue; |
2085 if( def->is_Proj() ) // If this is a machine projection, then | 2082 if( def->is_Proj() ) // If this is a machine projection, then |
2098 if ((--_uses[def->_idx]) == 0) | 2095 if ((--_uses[def->_idx]) == 0) |
2099 AddNodeToAvailableList(def); | 2096 AddNodeToAvailableList(def); |
2100 } | 2097 } |
2101 } | 2098 } |
2102 | 2099 |
2103 //------------------------------AddNodeToBundle-------------------------------- | |
2104 void Scheduling::AddNodeToBundle(Node *n, const Block *bb) { | 2100 void Scheduling::AddNodeToBundle(Node *n, const Block *bb) { |
2105 #ifndef PRODUCT | 2101 #ifndef PRODUCT |
2106 if (_cfg->C->trace_opto_output()) { | 2102 if (_cfg->C->trace_opto_output()) { |
2107 tty->print("# AddNodeToBundle: "); | 2103 tty->print("# AddNodeToBundle: "); |
2108 n->dump(); | 2104 n->dump(); |
2291 (op != Op_Node && // Not an unused antidepedence node and | 2287 (op != Op_Node && // Not an unused antidepedence node and |
2292 // not an unallocated boxlock | 2288 // not an unallocated boxlock |
2293 (OptoReg::is_valid(_regalloc->get_reg_first(n)) || op != Op_BoxLock)) ) { | 2289 (OptoReg::is_valid(_regalloc->get_reg_first(n)) || op != Op_BoxLock)) ) { |
2294 | 2290 |
2295 // Push any trailing projections | 2291 // Push any trailing projections |
2296 if( bb->_nodes[bb->_nodes.size()-1] != n ) { | 2292 if( bb->get_node(bb->number_of_nodes()-1) != n ) { |
2297 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | 2293 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { |
2298 Node *foi = n->fast_out(i); | 2294 Node *foi = n->fast_out(i); |
2299 if( foi->is_Proj() ) | 2295 if( foi->is_Proj() ) |
2300 _scheduled.push(foi); | 2296 _scheduled.push(foi); |
2301 } | 2297 } |
2313 // Walk all the definitions, decrementing use counts, and | 2309 // Walk all the definitions, decrementing use counts, and |
2314 // if a definition has a 0 use count, place it in the available list. | 2310 // if a definition has a 0 use count, place it in the available list. |
2315 DecrementUseCounts(n,bb); | 2311 DecrementUseCounts(n,bb); |
2316 } | 2312 } |
2317 | 2313 |
2318 //------------------------------ComputeUseCount-------------------------------- | |
2319 // This method sets the use count within a basic block. We will ignore all | 2314 // This method sets the use count within a basic block. We will ignore all |
2320 // uses outside the current basic block. As we are doing a backwards walk, | 2315 // uses outside the current basic block. As we are doing a backwards walk, |
2321 // any node we reach that has a use count of 0 may be scheduled. This also | 2316 // any node we reach that has a use count of 0 may be scheduled. This also |
2322 // avoids the problem of cyclic references from phi nodes, as long as phi | 2317 // avoids the problem of cyclic references from phi nodes, as long as phi |
2323 // nodes are at the front of the basic block. This method also initializes | 2318 // nodes are at the front of the basic block. This method also initializes |
2335 | 2330 |
2336 // No delay slot specified | 2331 // No delay slot specified |
2337 _unconditional_delay_slot = NULL; | 2332 _unconditional_delay_slot = NULL; |
2338 | 2333 |
2339 #ifdef ASSERT | 2334 #ifdef ASSERT |
2340 for( uint i=0; i < bb->_nodes.size(); i++ ) | 2335 for( uint i=0; i < bb->number_of_nodes(); i++ ) |
2341 assert( _uses[bb->_nodes[i]->_idx] == 0, "_use array not clean" ); | 2336 assert( _uses[bb->get_node(i)->_idx] == 0, "_use array not clean" ); |
2342 #endif | 2337 #endif |
2343 | 2338 |
2344 // Force the _uses count to never go to zero for unscheduable pieces | 2339 // Force the _uses count to never go to zero for unscheduable pieces |
2345 // of the block | 2340 // of the block |
2346 for( uint k = 0; k < _bb_start; k++ ) | 2341 for( uint k = 0; k < _bb_start; k++ ) |
2347 _uses[bb->_nodes[k]->_idx] = 1; | 2342 _uses[bb->get_node(k)->_idx] = 1; |
2348 for( uint l = _bb_end; l < bb->_nodes.size(); l++ ) | 2343 for( uint l = _bb_end; l < bb->number_of_nodes(); l++ ) |
2349 _uses[bb->_nodes[l]->_idx] = 1; | 2344 _uses[bb->get_node(l)->_idx] = 1; |
2350 | 2345 |
2351 // Iterate backwards over the instructions in the block. Don't count the | 2346 // Iterate backwards over the instructions in the block. Don't count the |
2352 // branch projections at end or the block header instructions. | 2347 // branch projections at end or the block header instructions. |
2353 for( uint j = _bb_end-1; j >= _bb_start; j-- ) { | 2348 for( uint j = _bb_end-1; j >= _bb_start; j-- ) { |
2354 Node *n = bb->_nodes[j]; | 2349 Node *n = bb->get_node(j); |
2355 if( n->is_Proj() ) continue; // Projections handled another way | 2350 if( n->is_Proj() ) continue; // Projections handled another way |
2356 | 2351 |
2357 // Account for all uses | 2352 // Account for all uses |
2358 for ( uint k = 0; k < n->len(); k++ ) { | 2353 for ( uint k = 0; k < n->len(); k++ ) { |
2359 Node *inp = n->in(k); | 2354 Node *inp = n->in(k); |
2398 | 2393 |
2399 Block *succ_bb = NULL; | 2394 Block *succ_bb = NULL; |
2400 Block *bb; | 2395 Block *bb; |
2401 | 2396 |
2402 // Walk over all the basic blocks in reverse order | 2397 // Walk over all the basic blocks in reverse order |
2403 for( int i=_cfg->_num_blocks-1; i >= 0; succ_bb = bb, i-- ) { | 2398 for (int i = _cfg->number_of_blocks() - 1; i >= 0; succ_bb = bb, i--) { |
2404 bb = _cfg->_blocks[i]; | 2399 bb = _cfg->get_block(i); |
2405 | 2400 |
2406 #ifndef PRODUCT | 2401 #ifndef PRODUCT |
2407 if (_cfg->C->trace_opto_output()) { | 2402 if (_cfg->C->trace_opto_output()) { |
2408 tty->print("# Schedule BB#%03d (initial)\n", i); | 2403 tty->print("# Schedule BB#%03d (initial)\n", i); |
2409 for (uint j = 0; j < bb->_nodes.size(); j++) | 2404 for (uint j = 0; j < bb->number_of_nodes(); j++) { |
2410 bb->_nodes[j]->dump(); | 2405 bb->get_node(j)->dump(); |
2406 } | |
2411 } | 2407 } |
2412 #endif | 2408 #endif |
2413 | 2409 |
2414 // On the head node, skip processing | 2410 // On the head node, skip processing |
2415 if( bb == _cfg->_broot ) | 2411 if (bb == _cfg->get_root_block()) { |
2416 continue; | 2412 continue; |
2413 } | |
2417 | 2414 |
2418 // Skip empty, connector blocks | 2415 // Skip empty, connector blocks |
2419 if (bb->is_connector()) | 2416 if (bb->is_connector()) |
2420 continue; | 2417 continue; |
2421 | 2418 |
2430 #endif | 2427 #endif |
2431 step_and_clear(); | 2428 step_and_clear(); |
2432 } | 2429 } |
2433 | 2430 |
2434 // Leave untouched the starting instruction, any Phis, a CreateEx node | 2431 // Leave untouched the starting instruction, any Phis, a CreateEx node |
2435 // or Top. bb->_nodes[_bb_start] is the first schedulable instruction. | 2432 // or Top. bb->get_node(_bb_start) is the first schedulable instruction. |
2436 _bb_end = bb->_nodes.size()-1; | 2433 _bb_end = bb->number_of_nodes()-1; |
2437 for( _bb_start=1; _bb_start <= _bb_end; _bb_start++ ) { | 2434 for( _bb_start=1; _bb_start <= _bb_end; _bb_start++ ) { |
2438 Node *n = bb->_nodes[_bb_start]; | 2435 Node *n = bb->get_node(_bb_start); |
2439 // Things not matched, like Phinodes and ProjNodes don't get scheduled. | 2436 // Things not matched, like Phinodes and ProjNodes don't get scheduled. |
2440 // Also, MachIdealNodes do not get scheduled | 2437 // Also, MachIdealNodes do not get scheduled |
2441 if( !n->is_Mach() ) continue; // Skip non-machine nodes | 2438 if( !n->is_Mach() ) continue; // Skip non-machine nodes |
2442 MachNode *mach = n->as_Mach(); | 2439 MachNode *mach = n->as_Mach(); |
2443 int iop = mach->ideal_Opcode(); | 2440 int iop = mach->ideal_Opcode(); |
2453 // might schedule. _bb_end points just after last schedulable inst. We | 2450 // might schedule. _bb_end points just after last schedulable inst. We |
2454 // normally schedule conditional branches (despite them being forced last | 2451 // normally schedule conditional branches (despite them being forced last |
2455 // in the block), because they have delay slots we can fill. Calls all | 2452 // in the block), because they have delay slots we can fill. Calls all |
2456 // have their delay slots filled in the template expansions, so we don't | 2453 // have their delay slots filled in the template expansions, so we don't |
2457 // bother scheduling them. | 2454 // bother scheduling them. |
2458 Node *last = bb->_nodes[_bb_end]; | 2455 Node *last = bb->get_node(_bb_end); |
2459 // Ignore trailing NOPs. | 2456 // Ignore trailing NOPs. |
2460 while (_bb_end > 0 && last->is_Mach() && | 2457 while (_bb_end > 0 && last->is_Mach() && |
2461 last->as_Mach()->ideal_Opcode() == Op_Con) { | 2458 last->as_Mach()->ideal_Opcode() == Op_Con) { |
2462 last = bb->_nodes[--_bb_end]; | 2459 last = bb->get_node(--_bb_end); |
2463 } | 2460 } |
2464 assert(!last->is_Mach() || last->as_Mach()->ideal_Opcode() != Op_Con, ""); | 2461 assert(!last->is_Mach() || last->as_Mach()->ideal_Opcode() != Op_Con, ""); |
2465 if( last->is_Catch() || | 2462 if( last->is_Catch() || |
2466 // Exclude unreachable path case when Halt node is in a separate block. | 2463 // Exclude unreachable path case when Halt node is in a separate block. |
2467 (_bb_end > 1 && last->is_Mach() && last->as_Mach()->ideal_Opcode() == Op_Halt) ) { | 2464 (_bb_end > 1 && last->is_Mach() && last->as_Mach()->ideal_Opcode() == Op_Halt) ) { |
2468 // There must be a prior call. Skip it. | 2465 // There must be a prior call. Skip it. |
2469 while( !bb->_nodes[--_bb_end]->is_MachCall() ) { | 2466 while( !bb->get_node(--_bb_end)->is_MachCall() ) { |
2470 assert( bb->_nodes[_bb_end]->is_MachProj(), "skipping projections after expected call" ); | 2467 assert( bb->get_node(_bb_end)->is_MachProj(), "skipping projections after expected call" ); |
2471 } | 2468 } |
2472 } else if( last->is_MachNullCheck() ) { | 2469 } else if( last->is_MachNullCheck() ) { |
2473 // Backup so the last null-checked memory instruction is | 2470 // Backup so the last null-checked memory instruction is |
2474 // outside the schedulable range. Skip over the nullcheck, | 2471 // outside the schedulable range. Skip over the nullcheck, |
2475 // projection, and the memory nodes. | 2472 // projection, and the memory nodes. |
2476 Node *mem = last->in(1); | 2473 Node *mem = last->in(1); |
2477 do { | 2474 do { |
2478 _bb_end--; | 2475 _bb_end--; |
2479 } while (mem != bb->_nodes[_bb_end]); | 2476 } while (mem != bb->get_node(_bb_end)); |
2480 } else { | 2477 } else { |
2481 // Set _bb_end to point after last schedulable inst. | 2478 // Set _bb_end to point after last schedulable inst. |
2482 _bb_end++; | 2479 _bb_end++; |
2483 } | 2480 } |
2484 | 2481 |
2503 } | 2500 } |
2504 | 2501 |
2505 assert( _scheduled.size() == _bb_end - _bb_start, "wrong number of instructions" ); | 2502 assert( _scheduled.size() == _bb_end - _bb_start, "wrong number of instructions" ); |
2506 #ifdef ASSERT | 2503 #ifdef ASSERT |
2507 for( uint l = _bb_start; l < _bb_end; l++ ) { | 2504 for( uint l = _bb_start; l < _bb_end; l++ ) { |
2508 Node *n = bb->_nodes[l]; | 2505 Node *n = bb->get_node(l); |
2509 uint m; | 2506 uint m; |
2510 for( m = 0; m < _bb_end-_bb_start; m++ ) | 2507 for( m = 0; m < _bb_end-_bb_start; m++ ) |
2511 if( _scheduled[m] == n ) | 2508 if( _scheduled[m] == n ) |
2512 break; | 2509 break; |
2513 assert( m < _bb_end-_bb_start, "instruction missing in schedule" ); | 2510 assert( m < _bb_end-_bb_start, "instruction missing in schedule" ); |
2514 } | 2511 } |
2515 #endif | 2512 #endif |
2516 | 2513 |
2517 // Now copy the instructions (in reverse order) back to the block | 2514 // Now copy the instructions (in reverse order) back to the block |
2518 for ( uint k = _bb_start; k < _bb_end; k++ ) | 2515 for ( uint k = _bb_start; k < _bb_end; k++ ) |
2519 bb->_nodes.map(k, _scheduled[_bb_end-k-1]); | 2516 bb->map_node(_scheduled[_bb_end-k-1], k); |
2520 | 2517 |
2521 #ifndef PRODUCT | 2518 #ifndef PRODUCT |
2522 if (_cfg->C->trace_opto_output()) { | 2519 if (_cfg->C->trace_opto_output()) { |
2523 tty->print("# Schedule BB#%03d (final)\n", i); | 2520 tty->print("# Schedule BB#%03d (final)\n", i); |
2524 uint current = 0; | 2521 uint current = 0; |
2525 for (uint j = 0; j < bb->_nodes.size(); j++) { | 2522 for (uint j = 0; j < bb->number_of_nodes(); j++) { |
2526 Node *n = bb->_nodes[j]; | 2523 Node *n = bb->get_node(j); |
2527 if( valid_bundle_info(n) ) { | 2524 if( valid_bundle_info(n) ) { |
2528 Bundle *bundle = node_bundling(n); | 2525 Bundle *bundle = node_bundling(n); |
2529 if (bundle->instr_count() > 0 || bundle->flags() > 0) { | 2526 if (bundle->instr_count() > 0 || bundle->flags() > 0) { |
2530 tty->print("*** Bundle: "); | 2527 tty->print("*** Bundle: "); |
2531 bundle->dump(); | 2528 bundle->dump(); |
2548 // Record final node-bundling array location | 2545 // Record final node-bundling array location |
2549 _regalloc->C->set_node_bundling_base(_node_bundling_base); | 2546 _regalloc->C->set_node_bundling_base(_node_bundling_base); |
2550 | 2547 |
2551 } // end DoScheduling | 2548 } // end DoScheduling |
2552 | 2549 |
2553 //------------------------------verify_good_schedule--------------------------- | |
2554 // Verify that no live-range used in the block is killed in the block by a | 2550 // Verify that no live-range used in the block is killed in the block by a |
2555 // wrong DEF. This doesn't verify live-ranges that span blocks. | 2551 // wrong DEF. This doesn't verify live-ranges that span blocks. |
2556 | 2552 |
2557 // Check for edge existence. Used to avoid adding redundant precedence edges. | 2553 // Check for edge existence. Used to avoid adding redundant precedence edges. |
2558 static bool edge_from_to( Node *from, Node *to ) { | 2554 static bool edge_from_to( Node *from, Node *to ) { |
2561 return true; | 2557 return true; |
2562 return false; | 2558 return false; |
2563 } | 2559 } |
2564 | 2560 |
2565 #ifdef ASSERT | 2561 #ifdef ASSERT |
2566 //------------------------------verify_do_def---------------------------------- | |
2567 void Scheduling::verify_do_def( Node *n, OptoReg::Name def, const char *msg ) { | 2562 void Scheduling::verify_do_def( Node *n, OptoReg::Name def, const char *msg ) { |
2568 // Check for bad kills | 2563 // Check for bad kills |
2569 if( OptoReg::is_valid(def) ) { // Ignore stores & control flow | 2564 if( OptoReg::is_valid(def) ) { // Ignore stores & control flow |
2570 Node *prior_use = _reg_node[def]; | 2565 Node *prior_use = _reg_node[def]; |
2571 if( prior_use && !edge_from_to(prior_use,n) ) { | 2566 if( prior_use && !edge_from_to(prior_use,n) ) { |
2577 } | 2572 } |
2578 _reg_node.map(def,NULL); // Kill live USEs | 2573 _reg_node.map(def,NULL); // Kill live USEs |
2579 } | 2574 } |
2580 } | 2575 } |
2581 | 2576 |
2582 //------------------------------verify_good_schedule--------------------------- | |
2583 void Scheduling::verify_good_schedule( Block *b, const char *msg ) { | 2577 void Scheduling::verify_good_schedule( Block *b, const char *msg ) { |
2584 | 2578 |
2585 // Zap to something reasonable for the verify code | 2579 // Zap to something reasonable for the verify code |
2586 _reg_node.clear(); | 2580 _reg_node.clear(); |
2587 | 2581 |
2588 // Walk over the block backwards. Check to make sure each DEF doesn't | 2582 // Walk over the block backwards. Check to make sure each DEF doesn't |
2589 // kill a live value (other than the one it's supposed to). Add each | 2583 // kill a live value (other than the one it's supposed to). Add each |
2590 // USE to the live set. | 2584 // USE to the live set. |
2591 for( uint i = b->_nodes.size()-1; i >= _bb_start; i-- ) { | 2585 for( uint i = b->number_of_nodes()-1; i >= _bb_start; i-- ) { |
2592 Node *n = b->_nodes[i]; | 2586 Node *n = b->get_node(i); |
2593 int n_op = n->Opcode(); | 2587 int n_op = n->Opcode(); |
2594 if( n_op == Op_MachProj && n->ideal_reg() == MachProjNode::fat_proj ) { | 2588 if( n_op == Op_MachProj && n->ideal_reg() == MachProjNode::fat_proj ) { |
2595 // Fat-proj kills a slew of registers | 2589 // Fat-proj kills a slew of registers |
2596 RegMask rm = n->out_RegMask();// Make local copy | 2590 RegMask rm = n->out_RegMask();// Make local copy |
2597 while( rm.is_NotEmpty() ) { | 2591 while( rm.is_NotEmpty() ) { |
2637 if( from != to && // No cycles (for things like LD L0,[L0+4] ) | 2631 if( from != to && // No cycles (for things like LD L0,[L0+4] ) |
2638 !edge_from_to( from, to ) ) // Avoid duplicate edge | 2632 !edge_from_to( from, to ) ) // Avoid duplicate edge |
2639 from->add_prec(to); | 2633 from->add_prec(to); |
2640 } | 2634 } |
2641 | 2635 |
2642 //------------------------------anti_do_def------------------------------------ | |
2643 void Scheduling::anti_do_def( Block *b, Node *def, OptoReg::Name def_reg, int is_def ) { | 2636 void Scheduling::anti_do_def( Block *b, Node *def, OptoReg::Name def_reg, int is_def ) { |
2644 if( !OptoReg::is_valid(def_reg) ) // Ignore stores & control flow | 2637 if( !OptoReg::is_valid(def_reg) ) // Ignore stores & control flow |
2645 return; | 2638 return; |
2646 | 2639 |
2647 Node *pinch = _reg_node[def_reg]; // Get pinch point | 2640 Node *pinch = _reg_node[def_reg]; // Get pinch point |
2707 | 2700 |
2708 // Add edge from kill to pinch-point | 2701 // Add edge from kill to pinch-point |
2709 add_prec_edge_from_to(kill,pinch); | 2702 add_prec_edge_from_to(kill,pinch); |
2710 } | 2703 } |
2711 | 2704 |
2712 //------------------------------anti_do_use------------------------------------ | |
2713 void Scheduling::anti_do_use( Block *b, Node *use, OptoReg::Name use_reg ) { | 2705 void Scheduling::anti_do_use( Block *b, Node *use, OptoReg::Name use_reg ) { |
2714 if( !OptoReg::is_valid(use_reg) ) // Ignore stores & control flow | 2706 if( !OptoReg::is_valid(use_reg) ) // Ignore stores & control flow |
2715 return; | 2707 return; |
2716 Node *pinch = _reg_node[use_reg]; // Get pinch point | 2708 Node *pinch = _reg_node[use_reg]; // Get pinch point |
2717 // Check for no later def_reg/kill in block | 2709 // Check for no later def_reg/kill in block |
2720 _cfg->get_block_for_node(use) == b) { | 2712 _cfg->get_block_for_node(use) == b) { |
2721 if( pinch->Opcode() == Op_Node && // Real pinch-point (not optimistic?) | 2713 if( pinch->Opcode() == Op_Node && // Real pinch-point (not optimistic?) |
2722 pinch->req() == 1 ) { // pinch not yet in block? | 2714 pinch->req() == 1 ) { // pinch not yet in block? |
2723 pinch->del_req(0); // yank pointer to later-def, also set flag | 2715 pinch->del_req(0); // yank pointer to later-def, also set flag |
2724 // Insert the pinch-point in the block just after the last use | 2716 // Insert the pinch-point in the block just after the last use |
2725 b->_nodes.insert(b->find_node(use)+1,pinch); | 2717 b->insert_node(pinch, b->find_node(use) + 1); |
2726 _bb_end++; // Increase size scheduled region in block | 2718 _bb_end++; // Increase size scheduled region in block |
2727 } | 2719 } |
2728 | 2720 |
2729 add_prec_edge_from_to(pinch,use); | 2721 add_prec_edge_from_to(pinch,use); |
2730 } | 2722 } |
2731 } | 2723 } |
2732 | 2724 |
2733 //------------------------------ComputeRegisterAntidependences----------------- | |
2734 // We insert antidependences between the reads and following write of | 2725 // We insert antidependences between the reads and following write of |
2735 // allocated registers to prevent illegal code motion. Hopefully, the | 2726 // allocated registers to prevent illegal code motion. Hopefully, the |
2736 // number of added references should be fairly small, especially as we | 2727 // number of added references should be fairly small, especially as we |
2737 // are only adding references within the current basic block. | 2728 // are only adding references within the current basic block. |
2738 void Scheduling::ComputeRegisterAntidependencies(Block *b) { | 2729 void Scheduling::ComputeRegisterAntidependencies(Block *b) { |
2773 // block. Leftover node from some prior block is treated like a NULL (no | 2764 // block. Leftover node from some prior block is treated like a NULL (no |
2774 // prior def, so no anti-dependence needed). Valid def is distinguished by | 2765 // prior def, so no anti-dependence needed). Valid def is distinguished by |
2775 // it being in the current block. | 2766 // it being in the current block. |
2776 bool fat_proj_seen = false; | 2767 bool fat_proj_seen = false; |
2777 uint last_safept = _bb_end-1; | 2768 uint last_safept = _bb_end-1; |
2778 Node* end_node = (_bb_end-1 >= _bb_start) ? b->_nodes[last_safept] : NULL; | 2769 Node* end_node = (_bb_end-1 >= _bb_start) ? b->get_node(last_safept) : NULL; |
2779 Node* last_safept_node = end_node; | 2770 Node* last_safept_node = end_node; |
2780 for( uint i = _bb_end-1; i >= _bb_start; i-- ) { | 2771 for( uint i = _bb_end-1; i >= _bb_start; i-- ) { |
2781 Node *n = b->_nodes[i]; | 2772 Node *n = b->get_node(i); |
2782 int is_def = n->outcnt(); // def if some uses prior to adding precedence edges | 2773 int is_def = n->outcnt(); // def if some uses prior to adding precedence edges |
2783 if( n->is_MachProj() && n->ideal_reg() == MachProjNode::fat_proj ) { | 2774 if( n->is_MachProj() && n->ideal_reg() == MachProjNode::fat_proj ) { |
2784 // Fat-proj kills a slew of registers | 2775 // Fat-proj kills a slew of registers |
2785 // This can add edges to 'n' and obscure whether or not it was a def, | 2776 // This can add edges to 'n' and obscure whether or not it was a def, |
2786 // hence the is_def flag. | 2777 // hence the is_def flag. |
2825 } | 2816 } |
2826 } | 2817 } |
2827 // Do not allow defs of new derived values to float above GC | 2818 // Do not allow defs of new derived values to float above GC |
2828 // points unless the base is definitely available at the GC point. | 2819 // points unless the base is definitely available at the GC point. |
2829 | 2820 |
2830 Node *m = b->_nodes[i]; | 2821 Node *m = b->get_node(i); |
2831 | 2822 |
2832 // Add precedence edge from following safepoint to use of derived pointer | 2823 // Add precedence edge from following safepoint to use of derived pointer |
2833 if( last_safept_node != end_node && | 2824 if( last_safept_node != end_node && |
2834 m != last_safept_node) { | 2825 m != last_safept_node) { |
2835 for (uint k = 1; k < m->req(); k++) { | 2826 for (uint k = 1; k < m->req(); k++) { |
2842 } | 2833 } |
2843 } | 2834 } |
2844 | 2835 |
2845 if( n->jvms() ) { // Precedence edge from derived to safept | 2836 if( n->jvms() ) { // Precedence edge from derived to safept |
2846 // Check if last_safept_node was moved by pinch-point insertion in anti_do_use() | 2837 // Check if last_safept_node was moved by pinch-point insertion in anti_do_use() |
2847 if( b->_nodes[last_safept] != last_safept_node ) { | 2838 if( b->get_node(last_safept) != last_safept_node ) { |
2848 last_safept = b->find_node(last_safept_node); | 2839 last_safept = b->find_node(last_safept_node); |
2849 } | 2840 } |
2850 for( uint j=last_safept; j > i; j-- ) { | 2841 for( uint j=last_safept; j > i; j-- ) { |
2851 Node *mach = b->_nodes[j]; | 2842 Node *mach = b->get_node(j); |
2852 if( mach->is_Mach() && mach->as_Mach()->ideal_Opcode() == Op_AddP ) | 2843 if( mach->is_Mach() && mach->as_Mach()->ideal_Opcode() == Op_AddP ) |
2853 mach->add_prec( n ); | 2844 mach->add_prec( n ); |
2854 } | 2845 } |
2855 last_safept = i; | 2846 last_safept = i; |
2856 last_safept_node = m; | 2847 last_safept_node = m; |
2861 // Garbage collect pinch nodes that were not consumed. | 2852 // Garbage collect pinch nodes that were not consumed. |
2862 // They are usually created by a fat kill MachProj for a call. | 2853 // They are usually created by a fat kill MachProj for a call. |
2863 garbage_collect_pinch_nodes(); | 2854 garbage_collect_pinch_nodes(); |
2864 } | 2855 } |
2865 } | 2856 } |
2866 | |
2867 //------------------------------garbage_collect_pinch_nodes------------------------------- | |
2868 | 2857 |
2869 // Garbage collect pinch nodes for reuse by other blocks. | 2858 // Garbage collect pinch nodes for reuse by other blocks. |
2870 // | 2859 // |
2871 // The block scheduler's insertion of anti-dependence | 2860 // The block scheduler's insertion of anti-dependence |
2872 // edges creates many pinch nodes when the block contains | 2861 // edges creates many pinch nodes when the block contains |
2938 } | 2927 } |
2939 // May have a later_def entry | 2928 // May have a later_def entry |
2940 pinch->set_req(0, NULL); | 2929 pinch->set_req(0, NULL); |
2941 } | 2930 } |
2942 | 2931 |
2943 //------------------------------print_statistics------------------------------- | |
2944 #ifndef PRODUCT | 2932 #ifndef PRODUCT |
2945 | 2933 |
2946 void Scheduling::dump_available() const { | 2934 void Scheduling::dump_available() const { |
2947 tty->print("#Availist "); | 2935 tty->print("#Availist "); |
2948 for (uint i = 0; i < _available.size(); i++) | 2936 for (uint i = 0; i < _available.size(); i++) |