Mercurial > hg > truffle
comparison src/share/vm/opto/coalesce.cpp @ 12167:650868c062a9
8023691: Create interface for nodes in class Block
Summary: Create public methods for accessing the nodes in a block
Reviewed-by: kvn, roland
author | adlertz |
---|---|
date | Mon, 26 Aug 2013 12:50:23 +0200 |
parents | 4b2838704fd5 |
children | 4b078f877b56 |
comparison
equal
deleted
inserted
replaced
12161:e1fbb86b47e4 | 12167:650868c062a9 |
---|---|
52 tty->print("B%d ", _phc._cfg.get_block_for_node(b->pred(j))->_pre_order); | 52 tty->print("B%d ", _phc._cfg.get_block_for_node(b->pred(j))->_pre_order); |
53 tty->print("-> "); | 53 tty->print("-> "); |
54 for( j=0; j<b->_num_succs; j++ ) | 54 for( j=0; j<b->_num_succs; j++ ) |
55 tty->print("B%d ",b->_succs[j]->_pre_order); | 55 tty->print("B%d ",b->_succs[j]->_pre_order); |
56 tty->print(" IDom: B%d/#%d\n", b->_idom ? b->_idom->_pre_order : 0, b->_dom_depth); | 56 tty->print(" IDom: B%d/#%d\n", b->_idom ? b->_idom->_pre_order : 0, b->_dom_depth); |
57 uint cnt = b->_nodes.size(); | 57 uint cnt = b->number_of_nodes(); |
58 for( j=0; j<cnt; j++ ) { | 58 for( j=0; j<cnt; j++ ) { |
59 Node *n = b->_nodes[j]; | 59 Node *n = b->get_node(j); |
60 dump( n ); | 60 dump( n ); |
61 tty->print("\t%s\t",n->Name()); | 61 tty->print("\t%s\t",n->Name()); |
62 | 62 |
63 // Dump the inputs | 63 // Dump the inputs |
64 uint k; // Exit value of loop | 64 uint k; // Exit value of loop |
150 // Scan backwards for the locations of the last use of the dst_name. | 150 // Scan backwards for the locations of the last use of the dst_name. |
151 // I am about to clobber the dst_name, so the copy must be inserted | 151 // I am about to clobber the dst_name, so the copy must be inserted |
152 // after the last use. Last use is really first-use on a backwards scan. | 152 // after the last use. Last use is really first-use on a backwards scan. |
153 uint i = b->end_idx()-1; | 153 uint i = b->end_idx()-1; |
154 while(1) { | 154 while(1) { |
155 Node *n = b->_nodes[i]; | 155 Node *n = b->get_node(i); |
156 // Check for end of virtual copies; this is also the end of the | 156 // Check for end of virtual copies; this is also the end of the |
157 // parallel renaming effort. | 157 // parallel renaming effort. |
158 if (n->_idx < _unique) { | 158 if (n->_idx < _unique) { |
159 break; | 159 break; |
160 } | 160 } |
172 uint kill_src_idx = b->end_idx(); | 172 uint kill_src_idx = b->end_idx(); |
173 // There can be only 1 kill that exits any block and that is | 173 // There can be only 1 kill that exits any block and that is |
174 // the last kill. Thus it is the first kill on a backwards scan. | 174 // the last kill. Thus it is the first kill on a backwards scan. |
175 i = b->end_idx()-1; | 175 i = b->end_idx()-1; |
176 while (1) { | 176 while (1) { |
177 Node *n = b->_nodes[i]; | 177 Node *n = b->get_node(i); |
178 // Check for end of virtual copies; this is also the end of the | 178 // Check for end of virtual copies; this is also the end of the |
179 // parallel renaming effort. | 179 // parallel renaming effort. |
180 if (n->_idx < _unique) { | 180 if (n->_idx < _unique) { |
181 break; | 181 break; |
182 } | 182 } |
198 | 198 |
199 // Insert new temp between copy and source | 199 // Insert new temp between copy and source |
200 tmp ->set_req(idx,copy->in(idx)); | 200 tmp ->set_req(idx,copy->in(idx)); |
201 copy->set_req(idx,tmp); | 201 copy->set_req(idx,tmp); |
202 // Save source in temp early, before source is killed | 202 // Save source in temp early, before source is killed |
203 b->_nodes.insert(kill_src_idx,tmp); | 203 b->insert_node(tmp, kill_src_idx); |
204 _phc._cfg.map_node_to_block(tmp, b); | 204 _phc._cfg.map_node_to_block(tmp, b); |
205 last_use_idx++; | 205 last_use_idx++; |
206 } | 206 } |
207 | 207 |
208 // Insert just after last use | 208 // Insert just after last use |
209 b->_nodes.insert(last_use_idx+1,copy); | 209 b->insert_node(copy, last_use_idx + 1); |
210 } | 210 } |
211 | 211 |
212 void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) { | 212 void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) { |
213 // We do LRGs compressing and fix a liveout data only here since the other | 213 // We do LRGs compressing and fix a liveout data only here since the other |
214 // place in Split() is guarded by the assert which we never hit. | 214 // place in Split() is guarded by the assert which we never hit. |
235 C->check_node_count(NodeLimitFudgeFactor, "out of nodes in coalesce"); | 235 C->check_node_count(NodeLimitFudgeFactor, "out of nodes in coalesce"); |
236 if (C->failing()) return; | 236 if (C->failing()) return; |
237 Block *b = _phc._cfg.get_block(i); | 237 Block *b = _phc._cfg.get_block(i); |
238 uint cnt = b->num_preds(); // Number of inputs to the Phi | 238 uint cnt = b->num_preds(); // Number of inputs to the Phi |
239 | 239 |
240 for( uint l = 1; l<b->_nodes.size(); l++ ) { | 240 for( uint l = 1; l<b->number_of_nodes(); l++ ) { |
241 Node *n = b->_nodes[l]; | 241 Node *n = b->get_node(l); |
242 | 242 |
243 // Do not use removed-copies, use copied value instead | 243 // Do not use removed-copies, use copied value instead |
244 uint ncnt = n->req(); | 244 uint ncnt = n->req(); |
245 for( uint k = 1; k<ncnt; k++ ) { | 245 for( uint k = 1; k<ncnt; k++ ) { |
246 Node *copy = n->in(k); | 246 Node *copy = n->in(k); |
258 if( cidx ) { | 258 if( cidx ) { |
259 Node *def = n->in(cidx); | 259 Node *def = n->in(cidx); |
260 if (_phc._lrg_map.find(n) == _phc._lrg_map.find(def)) { | 260 if (_phc._lrg_map.find(n) == _phc._lrg_map.find(def)) { |
261 n->replace_by(def); | 261 n->replace_by(def); |
262 n->set_req(cidx,NULL); | 262 n->set_req(cidx,NULL); |
263 b->_nodes.remove(l); | 263 b->remove_node(l); |
264 l--; | 264 l--; |
265 continue; | 265 continue; |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
319 // Rematerialize only constants as we do for Phi above. | 319 // Rematerialize only constants as we do for Phi above. |
320 if(m->is_Mach() && m->as_Mach()->is_Con() && | 320 if(m->is_Mach() && m->as_Mach()->is_Con() && |
321 m->as_Mach()->rematerialize()) { | 321 m->as_Mach()->rematerialize()) { |
322 copy = m->clone(); | 322 copy = m->clone(); |
323 // Insert the copy in the basic block, just before us | 323 // Insert the copy in the basic block, just before us |
324 b->_nodes.insert(l++, copy); | 324 b->insert_node(copy, l++); |
325 l += _phc.clone_projs(b, l, m, copy, _phc._lrg_map); | 325 l += _phc.clone_projs(b, l, m, copy, _phc._lrg_map); |
326 } else { | 326 } else { |
327 const RegMask *rm = C->matcher()->idealreg2spillmask[m->ideal_reg()]; | 327 const RegMask *rm = C->matcher()->idealreg2spillmask[m->ideal_reg()]; |
328 copy = new (C) MachSpillCopyNode(m, *rm, *rm); | 328 copy = new (C) MachSpillCopyNode(m, *rm, *rm); |
329 // Insert the copy in the basic block, just before us | 329 // Insert the copy in the basic block, just before us |
330 b->_nodes.insert(l++, copy); | 330 b->insert_node(copy, l++); |
331 } | 331 } |
332 // Insert the copy in the use-def chain | 332 // Insert the copy in the use-def chain |
333 n->set_req(idx, copy); | 333 n->set_req(idx, copy); |
334 // Extend ("register allocate") the names array for the copy. | 334 // Extend ("register allocate") the names array for the copy. |
335 _phc._lrg_map.extend(copy->_idx, name); | 335 _phc._lrg_map.extend(copy->_idx, name); |
374 const RegMask *rm = C->matcher()->idealreg2spillmask[inp->ideal_reg()]; | 374 const RegMask *rm = C->matcher()->idealreg2spillmask[inp->ideal_reg()]; |
375 Node *copy = new (C) MachSpillCopyNode( inp, *rm, *rm ); | 375 Node *copy = new (C) MachSpillCopyNode( inp, *rm, *rm ); |
376 // Insert the copy in the use-def chain | 376 // Insert the copy in the use-def chain |
377 n->set_req(inpidx, copy ); | 377 n->set_req(inpidx, copy ); |
378 // Insert the copy in the basic block, just before us | 378 // Insert the copy in the basic block, just before us |
379 b->_nodes.insert( l++, copy ); | 379 b->insert_node(copy, l++); |
380 // Extend ("register allocate") the names array for the copy. | 380 // Extend ("register allocate") the names array for the copy. |
381 uint max_lrg_id = _phc._lrg_map.max_lrg_id(); | 381 uint max_lrg_id = _phc._lrg_map.max_lrg_id(); |
382 _phc.new_lrg(copy, max_lrg_id); | 382 _phc.new_lrg(copy, max_lrg_id); |
383 _phc._lrg_map.set_max_lrg_id(max_lrg_id + 1); | 383 _phc._lrg_map.set_max_lrg_id(max_lrg_id + 1); |
384 _phc._cfg.map_node_to_block(copy, b); | 384 _phc._cfg.map_node_to_block(copy, b); |
429 while (_phc._cfg.get_block_for_node(bs->pred(j)) != b) { | 429 while (_phc._cfg.get_block_for_node(bs->pred(j)) != b) { |
430 j++; | 430 j++; |
431 } | 431 } |
432 | 432 |
433 // Visit all the Phis in successor block | 433 // Visit all the Phis in successor block |
434 for( uint k = 1; k<bs->_nodes.size(); k++ ) { | 434 for( uint k = 1; k<bs->number_of_nodes(); k++ ) { |
435 Node *n = bs->_nodes[k]; | 435 Node *n = bs->get_node(k); |
436 if( !n->is_Phi() ) break; | 436 if( !n->is_Phi() ) break; |
437 combine_these_two( n, n->in(j) ); | 437 combine_these_two( n, n->in(j) ); |
438 } | 438 } |
439 } // End of for all successor blocks | 439 } // End of for all successor blocks |
440 | 440 |
441 | 441 |
442 // Check _this_ block for 2-address instructions and copies. | 442 // Check _this_ block for 2-address instructions and copies. |
443 uint cnt = b->end_idx(); | 443 uint cnt = b->end_idx(); |
444 for( i = 1; i<cnt; i++ ) { | 444 for( i = 1; i<cnt; i++ ) { |
445 Node *n = b->_nodes[i]; | 445 Node *n = b->get_node(i); |
446 uint idx; | 446 uint idx; |
447 // 2-address instructions have a virtual Copy matching their input | 447 // 2-address instructions have a virtual Copy matching their input |
448 // to their output | 448 // to their output |
449 if (n->is_Mach() && (idx = n->as_Mach()->two_adr())) { | 449 if (n->is_Mach() && (idx = n->as_Mach()->two_adr())) { |
450 MachNode *mach = n->as_Mach(); | 450 MachNode *mach = n->as_Mach(); |
488 // the dst_copy becomes useless. | 488 // the dst_copy becomes useless. |
489 int didx = dst_copy->is_Copy(); | 489 int didx = dst_copy->is_Copy(); |
490 dst_copy->set_req( didx, src_def ); | 490 dst_copy->set_req( didx, src_def ); |
491 // Add copy to free list | 491 // Add copy to free list |
492 // _phc.free_spillcopy(b->_nodes[bindex]); | 492 // _phc.free_spillcopy(b->_nodes[bindex]); |
493 assert( b->_nodes[bindex] == dst_copy, "" ); | 493 assert( b->get_node(bindex) == dst_copy, "" ); |
494 dst_copy->replace_by( dst_copy->in(didx) ); | 494 dst_copy->replace_by( dst_copy->in(didx) ); |
495 dst_copy->set_req( didx, NULL); | 495 dst_copy->set_req( didx, NULL); |
496 b->_nodes.remove(bindex); | 496 b->remove_node(bindex); |
497 if( bindex < b->_ihrp_index ) b->_ihrp_index--; | 497 if( bindex < b->_ihrp_index ) b->_ihrp_index--; |
498 if( bindex < b->_fhrp_index ) b->_fhrp_index--; | 498 if( bindex < b->_fhrp_index ) b->_fhrp_index--; |
499 | 499 |
500 // Stretched lr1; add it to liveness of intermediate blocks | 500 // Stretched lr1; add it to liveness of intermediate blocks |
501 Block *b2 = _phc._cfg.get_block_for_node(src_copy); | 501 Block *b2 = _phc._cfg.get_block_for_node(src_copy); |
521 assert( b2->num_preds() == 2, "cannot double coalesce across c-flow" ); | 521 assert( b2->num_preds() == 2, "cannot double coalesce across c-flow" ); |
522 b2 = _phc._cfg.get_block_for_node(b2->pred(1)); | 522 b2 = _phc._cfg.get_block_for_node(b2->pred(1)); |
523 bindex2 = b2->end_idx()-1; | 523 bindex2 = b2->end_idx()-1; |
524 } | 524 } |
525 // Get prior instruction | 525 // Get prior instruction |
526 assert(bindex2 < b2->_nodes.size(), "index out of bounds"); | 526 assert(bindex2 < b2->number_of_nodes(), "index out of bounds"); |
527 Node *x = b2->_nodes[bindex2]; | 527 Node *x = b2->get_node(bindex2); |
528 if( x == prev_copy ) { // Previous copy in copy chain? | 528 if( x == prev_copy ) { // Previous copy in copy chain? |
529 if( prev_copy == src_copy)// Found end of chain and all interferences | 529 if( prev_copy == src_copy)// Found end of chain and all interferences |
530 break; // So break out of loop | 530 break; // So break out of loop |
531 // Else work back one in copy chain | 531 // Else work back one in copy chain |
532 prev_copy = prev_copy->in(prev_copy->is_Copy()); | 532 prev_copy = prev_copy->in(prev_copy->is_Copy()); |
774 } | 774 } |
775 // Check this block for copies. | 775 // Check this block for copies. |
776 for( uint i = 1; i<b->end_idx(); i++ ) { | 776 for( uint i = 1; i<b->end_idx(); i++ ) { |
777 // Check for actual copies on inputs. Coalesce a copy into its | 777 // Check for actual copies on inputs. Coalesce a copy into its |
778 // input if use and copy's input are compatible. | 778 // input if use and copy's input are compatible. |
779 Node *copy1 = b->_nodes[i]; | 779 Node *copy1 = b->get_node(i); |
780 uint idx1 = copy1->is_Copy(); | 780 uint idx1 = copy1->is_Copy(); |
781 if( !idx1 ) continue; // Not a copy | 781 if( !idx1 ) continue; // Not a copy |
782 | 782 |
783 if( copy_copy(copy1,copy1,b,i) ) { | 783 if( copy_copy(copy1,copy1,b,i) ) { |
784 i--; // Retry, same location in block | 784 i--; // Retry, same location in block |