Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/chaitin.cpp @ 14422:2b8e28fdf503
Merge
author | kvn |
---|---|
date | Tue, 05 Nov 2013 17:38:04 -0800 |
parents | 8c83625e3a53 |
children | 303c352ba1a8 15120a36272d |
comparison
equal
deleted
inserted
replaced
14421:3068270ba476 | 14422:2b8e28fdf503 |
---|---|
120 return score + 1e10; // Likely no progress to spill | 120 return score + 1e10; // Likely no progress to spill |
121 | 121 |
122 return score; | 122 return score; |
123 } | 123 } |
124 | 124 |
125 LRG_List::LRG_List( uint max ) : _cnt(max), _max(max), _lidxs(NEW_RESOURCE_ARRAY(uint,max)) { | |
126 memset( _lidxs, 0, sizeof(uint)*max ); | |
127 } | |
128 | |
129 void LRG_List::extend( uint nidx, uint lidx ) { | |
130 _nesting.check(); | |
131 if( nidx >= _max ) { | |
132 uint size = 16; | |
133 while( size <= nidx ) size <<=1; | |
134 _lidxs = REALLOC_RESOURCE_ARRAY( uint, _lidxs, _max, size ); | |
135 _max = size; | |
136 } | |
137 while( _cnt <= nidx ) | |
138 _lidxs[_cnt++] = 0; | |
139 _lidxs[nidx] = lidx; | |
140 } | |
141 | |
142 #define NUMBUCKS 3 | 125 #define NUMBUCKS 3 |
143 | 126 |
144 // Straight out of Tarjan's union-find algorithm | 127 // Straight out of Tarjan's union-find algorithm |
145 uint LiveRangeMap::find_compress(uint lrg) { | 128 uint LiveRangeMap::find_compress(uint lrg) { |
146 uint cur = lrg; | 129 uint cur = lrg; |
147 uint next = _uf_map[cur]; | 130 uint next = _uf_map.at(cur); |
148 while (next != cur) { // Scan chain of equivalences | 131 while (next != cur) { // Scan chain of equivalences |
149 assert( next < cur, "always union smaller"); | 132 assert( next < cur, "always union smaller"); |
150 cur = next; // until find a fixed-point | 133 cur = next; // until find a fixed-point |
151 next = _uf_map[cur]; | 134 next = _uf_map.at(cur); |
152 } | 135 } |
153 | 136 |
154 // Core of union-find algorithm: update chain of | 137 // Core of union-find algorithm: update chain of |
155 // equivalences to be equal to the root. | 138 // equivalences to be equal to the root. |
156 while (lrg != next) { | 139 while (lrg != next) { |
157 uint tmp = _uf_map[lrg]; | 140 uint tmp = _uf_map.at(lrg); |
158 _uf_map.map(lrg, next); | 141 _uf_map.at_put(lrg, next); |
159 lrg = tmp; | 142 lrg = tmp; |
160 } | 143 } |
161 return lrg; | 144 return lrg; |
162 } | 145 } |
163 | 146 |
164 // Reset the Union-Find map to identity | 147 // Reset the Union-Find map to identity |
165 void LiveRangeMap::reset_uf_map(uint max_lrg_id) { | 148 void LiveRangeMap::reset_uf_map(uint max_lrg_id) { |
166 _max_lrg_id= max_lrg_id; | 149 _max_lrg_id= max_lrg_id; |
167 // Force the Union-Find mapping to be at least this large | 150 // Force the Union-Find mapping to be at least this large |
168 _uf_map.extend(_max_lrg_id, 0); | 151 _uf_map.at_put_grow(_max_lrg_id, 0); |
169 // Initialize it to be the ID mapping. | 152 // Initialize it to be the ID mapping. |
170 for (uint i = 0; i < _max_lrg_id; ++i) { | 153 for (uint i = 0; i < _max_lrg_id; ++i) { |
171 _uf_map.map(i, i); | 154 _uf_map.at_put(i, i); |
172 } | 155 } |
173 } | 156 } |
174 | 157 |
175 // Make all Nodes map directly to their final live range; no need for | 158 // Make all Nodes map directly to their final live range; no need for |
176 // the Union-Find mapping after this call. | 159 // the Union-Find mapping after this call. |
177 void LiveRangeMap::compress_uf_map_for_nodes() { | 160 void LiveRangeMap::compress_uf_map_for_nodes() { |
178 // For all Nodes, compress mapping | 161 // For all Nodes, compress mapping |
179 uint unique = _names.Size(); | 162 uint unique = _names.length(); |
180 for (uint i = 0; i < unique; ++i) { | 163 for (uint i = 0; i < unique; ++i) { |
181 uint lrg = _names[i]; | 164 uint lrg = _names.at(i); |
182 uint compressed_lrg = find(lrg); | 165 uint compressed_lrg = find(lrg); |
183 if (lrg != compressed_lrg) { | 166 if (lrg != compressed_lrg) { |
184 _names.map(i, compressed_lrg); | 167 _names.at_put(i, compressed_lrg); |
185 } | 168 } |
186 } | 169 } |
187 } | 170 } |
188 | 171 |
189 // Like Find above, but no path compress, so bad asymptotic behavior | 172 // Like Find above, but no path compress, so bad asymptotic behavior |
196 // brand new live ranges but have not told the allocator yet. | 179 // brand new live ranges but have not told the allocator yet. |
197 if (lrg >= _max_lrg_id) { | 180 if (lrg >= _max_lrg_id) { |
198 return lrg; | 181 return lrg; |
199 } | 182 } |
200 | 183 |
201 uint next = _uf_map[lrg]; | 184 uint next = _uf_map.at(lrg); |
202 while (next != lrg) { // Scan chain of equivalences | 185 while (next != lrg) { // Scan chain of equivalences |
203 assert(next < lrg, "always union smaller"); | 186 assert(next < lrg, "always union smaller"); |
204 lrg = next; // until find a fixed-point | 187 lrg = next; // until find a fixed-point |
205 next = _uf_map[lrg]; | 188 next = _uf_map.at(lrg); |
206 } | 189 } |
207 return next; | 190 return next; |
208 } | 191 } |
209 | 192 |
210 PhaseChaitin::PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher) | 193 PhaseChaitin::PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher) |
213 print_chaitin_statistics | 196 print_chaitin_statistics |
214 #else | 197 #else |
215 NULL | 198 NULL |
216 #endif | 199 #endif |
217 ) | 200 ) |
218 , _lrg_map(unique) | 201 , _lrg_map(Thread::current()->resource_area(), unique) |
219 , _live(0) | 202 , _live(0) |
220 , _spilled_once(Thread::current()->resource_area()) | 203 , _spilled_once(Thread::current()->resource_area()) |
221 , _spilled_twice(Thread::current()->resource_area()) | 204 , _spilled_twice(Thread::current()->resource_area()) |
222 , _lo_degree(0), _lo_stk_degree(0), _hi_degree(0), _simplified(0) | 205 , _lo_degree(0), _lo_stk_degree(0), _hi_degree(0), _simplified(0) |
223 , _oldphi(unique) | 206 , _oldphi(unique) |
299 assert(_cfg.get_block_for_node(proj) == borig, "incorrect block for kill projections"); | 282 assert(_cfg.get_block_for_node(proj) == borig, "incorrect block for kill projections"); |
300 found_projs++; | 283 found_projs++; |
301 // Copy kill projections after the cloned node | 284 // Copy kill projections after the cloned node |
302 Node* kills = proj->clone(); | 285 Node* kills = proj->clone(); |
303 kills->set_req(0, copy); | 286 kills->set_req(0, copy); |
304 b->_nodes.insert(idx++, kills); | 287 b->insert_node(kills, idx++); |
305 _cfg.map_node_to_block(kills, b); | 288 _cfg.map_node_to_block(kills, b); |
306 new_lrg(kills, max_lrg_id++); | 289 new_lrg(kills, max_lrg_id++); |
307 } | 290 } |
308 } | 291 } |
309 return found_projs; | 292 return found_projs; |
680 // get allocated, but instead rely on correct scheduling to ensure that | 663 // get allocated, but instead rely on correct scheduling to ensure that |
681 // only one instance is simultaneously live at a time. | 664 // only one instance is simultaneously live at a time. |
682 uint lr_counter = 1; | 665 uint lr_counter = 1; |
683 for( uint i = 0; i < _cfg.number_of_blocks(); i++ ) { | 666 for( uint i = 0; i < _cfg.number_of_blocks(); i++ ) { |
684 Block* block = _cfg.get_block(i); | 667 Block* block = _cfg.get_block(i); |
685 uint cnt = block->_nodes.size(); | 668 uint cnt = block->number_of_nodes(); |
686 | 669 |
687 // Handle all the normal Nodes in the block | 670 // Handle all the normal Nodes in the block |
688 for( uint j = 0; j < cnt; j++ ) { | 671 for( uint j = 0; j < cnt; j++ ) { |
689 Node *n = block->_nodes[j]; | 672 Node *n = block->get_node(j); |
690 // Pre-color to the zero live range, or pick virtual register | 673 // Pre-color to the zero live range, or pick virtual register |
691 const RegMask &rm = n->out_RegMask(); | 674 const RegMask &rm = n->out_RegMask(); |
692 _lrg_map.map(n->_idx, rm.is_NotEmpty() ? lr_counter++ : 0); | 675 _lrg_map.map(n->_idx, rm.is_NotEmpty() ? lr_counter++ : 0); |
693 } | 676 } |
694 } | 677 } |
678 | |
695 // Reset the Union-Find mapping to be identity | 679 // Reset the Union-Find mapping to be identity |
696 _lrg_map.reset_uf_map(lr_counter); | 680 _lrg_map.reset_uf_map(lr_counter); |
697 } | 681 } |
698 | 682 |
699 | 683 |
708 // For all blocks | 692 // For all blocks |
709 for (uint i = 0; i < _cfg.number_of_blocks(); i++) { | 693 for (uint i = 0; i < _cfg.number_of_blocks(); i++) { |
710 Block* block = _cfg.get_block(i); | 694 Block* block = _cfg.get_block(i); |
711 | 695 |
712 // For all instructions | 696 // For all instructions |
713 for (uint j = 1; j < block->_nodes.size(); j++) { | 697 for (uint j = 1; j < block->number_of_nodes(); j++) { |
714 Node* n = block->_nodes[j]; | 698 Node* n = block->get_node(j); |
715 uint input_edge_start =1; // Skip control most nodes | 699 uint input_edge_start =1; // Skip control most nodes |
716 if (n->is_Mach()) { | 700 if (n->is_Mach()) { |
717 input_edge_start = n->as_Mach()->oper_input_base(); | 701 input_edge_start = n->as_Mach()->oper_input_base(); |
718 } | 702 } |
719 uint idx = n->is_Copy(); | 703 uint idx = n->is_Copy(); |
1602 Block* block = _cfg.get_block(i); | 1586 Block* block = _cfg.get_block(i); |
1603 | 1587 |
1604 // For all instructions in block | 1588 // For all instructions in block |
1605 uint last_inst = block->end_idx(); | 1589 uint last_inst = block->end_idx(); |
1606 for (uint j = 1; j <= last_inst; j++) { | 1590 for (uint j = 1; j <= last_inst; j++) { |
1607 Node* n = block->_nodes[j]; | 1591 Node* n = block->get_node(j); |
1608 | 1592 |
1609 // Dead instruction??? | 1593 // Dead instruction??? |
1610 assert( n->outcnt() != 0 ||// Nothing dead after post alloc | 1594 assert( n->outcnt() != 0 ||// Nothing dead after post alloc |
1611 C->top() == n || // Or the random TOP node | 1595 C->top() == n || // Or the random TOP node |
1612 n->is_Proj(), // Or a fat-proj kill node | 1596 n->is_Proj(), // Or a fat-proj kill node |
1639 cisc->set_req(inp,fp); // Base register is frame pointer | 1623 cisc->set_req(inp,fp); // Base register is frame pointer |
1640 if( cisc->oper_input_base() > 1 && mach->oper_input_base() <= 1 ) { | 1624 if( cisc->oper_input_base() > 1 && mach->oper_input_base() <= 1 ) { |
1641 assert( cisc->oper_input_base() == 2, "Only adding one edge"); | 1625 assert( cisc->oper_input_base() == 2, "Only adding one edge"); |
1642 cisc->ins_req(1,src); // Requires a memory edge | 1626 cisc->ins_req(1,src); // Requires a memory edge |
1643 } | 1627 } |
1644 block->_nodes.map(j,cisc); // Insert into basic block | 1628 block->map_node(cisc, j); // Insert into basic block |
1645 n->subsume_by(cisc, C); // Correct graph | 1629 n->subsume_by(cisc, C); // Correct graph |
1646 // | 1630 // |
1647 ++_used_cisc_instructions; | 1631 ++_used_cisc_instructions; |
1648 #ifndef PRODUCT | 1632 #ifndef PRODUCT |
1649 if( TraceCISCSpill ) { | 1633 if( TraceCISCSpill ) { |
1696 // Initialize it once and make it shared: | 1680 // Initialize it once and make it shared: |
1697 // set control to _root and place it into Start block | 1681 // set control to _root and place it into Start block |
1698 // (where top() node is placed). | 1682 // (where top() node is placed). |
1699 base->init_req(0, _cfg.get_root_node()); | 1683 base->init_req(0, _cfg.get_root_node()); |
1700 Block *startb = _cfg.get_block_for_node(C->top()); | 1684 Block *startb = _cfg.get_block_for_node(C->top()); |
1701 startb->_nodes.insert(startb->find_node(C->top()), base ); | 1685 startb->insert_node(base, startb->find_node(C->top())); |
1702 _cfg.map_node_to_block(base, startb); | 1686 _cfg.map_node_to_block(base, startb); |
1703 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet"); | 1687 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet"); |
1704 } | 1688 } |
1705 if (_lrg_map.live_range_id(base) == 0) { | 1689 if (_lrg_map.live_range_id(base) == 0) { |
1706 new_lrg(base, maxlrg++); | 1690 new_lrg(base, maxlrg++); |
1741 base->as_Phi()->set_type(t); | 1725 base->as_Phi()->set_type(t); |
1742 | 1726 |
1743 // Search the current block for an existing base-Phi | 1727 // Search the current block for an existing base-Phi |
1744 Block *b = _cfg.get_block_for_node(derived); | 1728 Block *b = _cfg.get_block_for_node(derived); |
1745 for( i = 1; i <= b->end_idx(); i++ ) {// Search for matching Phi | 1729 for( i = 1; i <= b->end_idx(); i++ ) {// Search for matching Phi |
1746 Node *phi = b->_nodes[i]; | 1730 Node *phi = b->get_node(i); |
1747 if( !phi->is_Phi() ) { // Found end of Phis with no match? | 1731 if( !phi->is_Phi() ) { // Found end of Phis with no match? |
1748 b->_nodes.insert( i, base ); // Must insert created Phi here as base | 1732 b->insert_node(base, i); // Must insert created Phi here as base |
1749 _cfg.map_node_to_block(base, b); | 1733 _cfg.map_node_to_block(base, b); |
1750 new_lrg(base,maxlrg++); | 1734 new_lrg(base,maxlrg++); |
1751 break; | 1735 break; |
1752 } | 1736 } |
1753 // See if Phi matches. | 1737 // See if Phi matches. |
1784 // Note use of deep-copy constructor. I cannot hammer the original | 1768 // Note use of deep-copy constructor. I cannot hammer the original |
1785 // liveout bits, because they are needed by the following coalesce pass. | 1769 // liveout bits, because they are needed by the following coalesce pass. |
1786 IndexSet liveout(_live->live(block)); | 1770 IndexSet liveout(_live->live(block)); |
1787 | 1771 |
1788 for (uint j = block->end_idx() + 1; j > 1; j--) { | 1772 for (uint j = block->end_idx() + 1; j > 1; j--) { |
1789 Node* n = block->_nodes[j - 1]; | 1773 Node* n = block->get_node(j - 1); |
1790 | 1774 |
1791 // Pre-split compares of loop-phis. Loop-phis form a cycle we would | 1775 // Pre-split compares of loop-phis. Loop-phis form a cycle we would |
1792 // like to see in the same register. Compare uses the loop-phi and so | 1776 // like to see in the same register. Compare uses the loop-phi and so |
1793 // extends its live range BUT cannot be part of the cycle. If this | 1777 // extends its live range BUT cannot be part of the cycle. If this |
1794 // extended live range overlaps with the update of the loop-phi value | 1778 // extended live range overlaps with the update of the loop-phi value |
1977 | 1961 |
1978 void PhaseChaitin::dump(const Block *b) const { | 1962 void PhaseChaitin::dump(const Block *b) const { |
1979 b->dump_head(&_cfg); | 1963 b->dump_head(&_cfg); |
1980 | 1964 |
1981 // For all instructions | 1965 // For all instructions |
1982 for( uint j = 0; j < b->_nodes.size(); j++ ) | 1966 for( uint j = 0; j < b->number_of_nodes(); j++ ) |
1983 dump(b->_nodes[j]); | 1967 dump(b->get_node(j)); |
1984 // Print live-out info at end of block | 1968 // Print live-out info at end of block |
1985 if( _live ) { | 1969 if( _live ) { |
1986 tty->print("Liveout: "); | 1970 tty->print("Liveout: "); |
1987 IndexSet *live = _live->live(b); | 1971 IndexSet *live = _live->live(b); |
1988 IndexSetIterator elements(live); | 1972 IndexSetIterator elements(live); |
2269 for (uint i = 0; i < _cfg.number_of_blocks(); i++) { | 2253 for (uint i = 0; i < _cfg.number_of_blocks(); i++) { |
2270 Block* block = _cfg.get_block(i); | 2254 Block* block = _cfg.get_block(i); |
2271 int dump_once = 0; | 2255 int dump_once = 0; |
2272 | 2256 |
2273 // For all instructions | 2257 // For all instructions |
2274 for( uint j = 0; j < block->_nodes.size(); j++ ) { | 2258 for( uint j = 0; j < block->number_of_nodes(); j++ ) { |
2275 Node *n = block->_nodes[j]; | 2259 Node *n = block->get_node(j); |
2276 if (_lrg_map.find_const(n) == lidx) { | 2260 if (_lrg_map.find_const(n) == lidx) { |
2277 if (!dump_once++) { | 2261 if (!dump_once++) { |
2278 tty->cr(); | 2262 tty->cr(); |
2279 block->dump_head(&_cfg); | 2263 block->dump_head(&_cfg); |
2280 } | 2264 } |