comparison src/share/vm/opto/gcm.cpp @ 628:7bb995fbd3c0

Merge
author trims
date Thu, 12 Mar 2009 18:16:36 -0700
parents 0fbdb4381b99 19f25e603e7b
children fbc12e71c476
comparison
equal deleted inserted replaced
580:ce2272390558 628:7bb995fbd3c0
55 } 55 }
56 } 56 }
57 } 57 }
58 } 58 }
59 59
60 //----------------------------replace_block_proj_ctrl-------------------------
61 // Nodes that have is_block_proj() nodes as their control need to use
62 // the appropriate Region for their actual block as their control since
63 // the projection will be in a predecessor block.
64 void PhaseCFG::replace_block_proj_ctrl( Node *n ) {
65 const Node *in0 = n->in(0);
66 assert(in0 != NULL, "Only control-dependent");
67 const Node *p = in0->is_block_proj();
68 if (p != NULL && p != n) { // Control from a block projection?
69 assert(!n->pinned() || n->is_SafePointScalarObject(), "only SafePointScalarObject pinned node is expected here");
70 // Find trailing Region
71 Block *pb = _bbs[in0->_idx]; // Block-projection already has basic block
72 uint j = 0;
73 if (pb->_num_succs != 1) { // More then 1 successor?
74 // Search for successor
75 uint max = pb->_nodes.size();
76 assert( max > 1, "" );
77 uint start = max - pb->_num_succs;
78 // Find which output path belongs to projection
79 for (j = start; j < max; j++) {
80 if( pb->_nodes[j] == in0 )
81 break;
82 }
83 assert( j < max, "must find" );
84 // Change control to match head of successor basic block
85 j -= start;
86 }
87 n->set_req(0, pb->_succs[j]->head());
88 }
89 }
90
60 91
61 //------------------------------schedule_pinned_nodes-------------------------- 92 //------------------------------schedule_pinned_nodes--------------------------
62 // Set the basic block for Nodes pinned into blocks 93 // Set the basic block for Nodes pinned into blocks
63 void PhaseCFG::schedule_pinned_nodes( VectorSet &visited ) { 94 void PhaseCFG::schedule_pinned_nodes( VectorSet &visited ) {
64 // Allocate node stack of size C->unique()+8 to avoid frequent realloc 95 // Allocate node stack of size C->unique()+8 to avoid frequent realloc
66 spstack.push(_root); 97 spstack.push(_root);
67 while ( spstack.is_nonempty() ) { 98 while ( spstack.is_nonempty() ) {
68 Node *n = spstack.pop(); 99 Node *n = spstack.pop();
69 if( !visited.test_set(n->_idx) ) { // Test node and flag it as visited 100 if( !visited.test_set(n->_idx) ) { // Test node and flag it as visited
70 if( n->pinned() && !_bbs.lookup(n->_idx) ) { // Pinned? Nail it down! 101 if( n->pinned() && !_bbs.lookup(n->_idx) ) { // Pinned? Nail it down!
102 assert( n->in(0), "pinned Node must have Control" );
103 // Before setting block replace block_proj control edge
104 replace_block_proj_ctrl(n);
71 Node *input = n->in(0); 105 Node *input = n->in(0);
72 assert( input, "pinned Node must have Control" );
73 while( !input->is_block_start() ) 106 while( !input->is_block_start() )
74 input = input->in(0); 107 input = input->in(0);
75 Block *b = _bbs[input->_idx]; // Basic block of controlling input 108 Block *b = _bbs[input->_idx]; // Basic block of controlling input
76 schedule_node_into_block(n, b); 109 schedule_node_into_block(n, b);
77 } 110 }
156 // Get parent node and next input's index from stack's top. 189 // Get parent node and next input's index from stack's top.
157 Node *n = nstack_top_n; 190 Node *n = nstack_top_n;
158 uint i = nstack_top_i; 191 uint i = nstack_top_i;
159 192
160 if (i == 0) { 193 if (i == 0) {
161 // Special control input processing. 194 // Fixup some control. Constants without control get attached
162 // While I am here, go ahead and look for Nodes which are taking control 195 // to root and nodes that use is_block_proj() nodes should be attached
163 // from a is_block_proj Node. After I inserted RegionNodes to make proper 196 // to the region that starts their block.
164 // blocks, the control at a is_block_proj more properly comes from the
165 // Region being controlled by the block_proj Node.
166 const Node *in0 = n->in(0); 197 const Node *in0 = n->in(0);
167 if (in0 != NULL) { // Control-dependent? 198 if (in0 != NULL) { // Control-dependent?
168 const Node *p = in0->is_block_proj(); 199 replace_block_proj_ctrl(n);
169 if (p != NULL && p != n) { // Control from a block projection?
170 // Find trailing Region
171 Block *pb = _bbs[in0->_idx]; // Block-projection already has basic block
172 uint j = 0;
173 if (pb->_num_succs != 1) { // More then 1 successor?
174 // Search for successor
175 uint max = pb->_nodes.size();
176 assert( max > 1, "" );
177 uint start = max - pb->_num_succs;
178 // Find which output path belongs to projection
179 for (j = start; j < max; j++) {
180 if( pb->_nodes[j] == in0 )
181 break;
182 }
183 assert( j < max, "must find" );
184 // Change control to match head of successor basic block
185 j -= start;
186 }
187 n->set_req(0, pb->_succs[j]->head());
188 }
189 } else { // n->in(0) == NULL 200 } else { // n->in(0) == NULL
190 if (n->req() == 1) { // This guy is a constant with NO inputs? 201 if (n->req() == 1) { // This guy is a constant with NO inputs?
191 n->set_req(0, _root); 202 n->set_req(0, _root);
192 } 203 }
193 } 204 }
224 // Phi, Start, Return, and other control-dependent instructions and 235 // Phi, Start, Return, and other control-dependent instructions and
225 // any projections which depend on them. 236 // any projections which depend on them.
226 if (!n->pinned()) { 237 if (!n->pinned()) {
227 // Set earliest legal block. 238 // Set earliest legal block.
228 _bbs.map(n->_idx, find_deepest_input(n, _bbs)); 239 _bbs.map(n->_idx, find_deepest_input(n, _bbs));
240 } else {
241 assert(_bbs[n->_idx] == _bbs[n->in(0)->_idx], "Pinned Node should be at the same block as its control edge");
229 } 242 }
230 243
231 if (nstack.is_empty()) { 244 if (nstack.is_empty()) {
232 // Finished all nodes on stack. 245 // Finished all nodes on stack.
233 // Process next node on the worklist 'roots'. 246 // Process next node on the worklist 'roots'.
591 DEBUG_ONLY(found_match = true); 604 DEBUG_ONLY(found_match = true);
592 Block* pred_block = _bbs[store_block->pred(j)->_idx]; 605 Block* pred_block = _bbs[store_block->pred(j)->_idx];
593 if (pred_block != early) { 606 if (pred_block != early) {
594 // If any predecessor of the Phi matches the load's "early block", 607 // If any predecessor of the Phi matches the load's "early block",
595 // we do not need a precedence edge between the Phi and 'load' 608 // we do not need a precedence edge between the Phi and 'load'
596 // since the load will be forced into a block preceeding the Phi. 609 // since the load will be forced into a block preceding the Phi.
597 pred_block->set_raise_LCA_mark(load_index); 610 pred_block->set_raise_LCA_mark(load_index);
598 assert(!LCA_orig->dominates(pred_block) || 611 assert(!LCA_orig->dominates(pred_block) ||
599 early->dominates(pred_block), "early is high enough"); 612 early->dominates(pred_block), "early is high enough");
600 must_raise_LCA = true; 613 must_raise_LCA = true;
601 } 614 }
1384 } 1397 }
1385 1398
1386 #ifdef ASSERT 1399 #ifdef ASSERT
1387 for (uint i = 0; i < _num_blocks; i++ ) { 1400 for (uint i = 0; i < _num_blocks; i++ ) {
1388 Block *b = _blocks[i]; 1401 Block *b = _blocks[i];
1389 assert(b->_freq >= MIN_BLOCK_FREQUENCY, "Register Allocator requiers meaningful block frequency"); 1402 assert(b->_freq >= MIN_BLOCK_FREQUENCY, "Register Allocator requires meaningful block frequency");
1390 } 1403 }
1391 #endif 1404 #endif
1392 1405
1393 #ifndef PRODUCT 1406 #ifndef PRODUCT
1394 if (PrintCFGBlockFreq) { 1407 if (PrintCFGBlockFreq) {
1637 // Can only reach here if called after lcm. The original Op_If is gone, 1650 // Can only reach here if called after lcm. The original Op_If is gone,
1638 // so we attempt to infer the probability from one or both of the 1651 // so we attempt to infer the probability from one or both of the
1639 // successor blocks. 1652 // successor blocks.
1640 assert(_num_succs == 2, "expecting 2 successors of a null check"); 1653 assert(_num_succs == 2, "expecting 2 successors of a null check");
1641 // If either successor has only one predecessor, then the 1654 // If either successor has only one predecessor, then the
1642 // probabiltity estimate can be derived using the 1655 // probability estimate can be derived using the
1643 // relative frequency of the successor and this block. 1656 // relative frequency of the successor and this block.
1644 if (_succs[i]->num_preds() == 2) { 1657 if (_succs[i]->num_preds() == 2) {
1645 return _succs[i]->_freq / _freq; 1658 return _succs[i]->_freq / _freq;
1646 } else if (_succs[1-i]->num_preds() == 2) { 1659 } else if (_succs[1-i]->num_preds() == 2) {
1647 return 1 - (_succs[1-i]->_freq / _freq); 1660 return 1 - (_succs[1-i]->_freq / _freq);
1839 1852
1840 n->as_MachIf()->_prob = p; 1853 n->as_MachIf()->_prob = p;
1841 } 1854 }
1842 1855
1843 //------------------------------update_succ_freq------------------------------- 1856 //------------------------------update_succ_freq-------------------------------
1844 // Update the appropriate frequency associated with block 'b', a succesor of 1857 // Update the appropriate frequency associated with block 'b', a successor of
1845 // a block in this loop. 1858 // a block in this loop.
1846 void CFGLoop::update_succ_freq(Block* b, float freq) { 1859 void CFGLoop::update_succ_freq(Block* b, float freq) {
1847 if (b->_loop == this) { 1860 if (b->_loop == this) {
1848 if (b == head()) { 1861 if (b == head()) {
1849 // back branch within the loop 1862 // back branch within the loop
1886 void CFGLoop::scale_freq() { 1899 void CFGLoop::scale_freq() {
1887 float loop_freq = _freq * trip_count(); 1900 float loop_freq = _freq * trip_count();
1888 for (int i = 0; i < _members.length(); i++) { 1901 for (int i = 0; i < _members.length(); i++) {
1889 CFGElement* s = _members.at(i); 1902 CFGElement* s = _members.at(i);
1890 float block_freq = s->_freq * loop_freq; 1903 float block_freq = s->_freq * loop_freq;
1891 if (block_freq < MIN_BLOCK_FREQUENCY) block_freq = MIN_BLOCK_FREQUENCY; 1904 if (g_isnan(block_freq) || block_freq < MIN_BLOCK_FREQUENCY)
1905 block_freq = MIN_BLOCK_FREQUENCY;
1892 s->_freq = block_freq; 1906 s->_freq = block_freq;
1893 } 1907 }
1894 CFGLoop* ch = _child; 1908 CFGLoop* ch = _child;
1895 while (ch != NULL) { 1909 while (ch != NULL) {
1896 ch->scale_freq(); 1910 ch->scale_freq();