Mercurial > hg > truffle
comparison src/share/vm/opto/block.cpp @ 4137:04b9a2566eec
Merge with hsx23/hotspot.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 21:40:27 +0100 |
parents | 1bd45abaa507 |
children | e626685e9f6c |
comparison
equal
deleted
inserted
replaced
3737:9dc19b7d89a3 | 4137:04b9a2566eec |
---|---|
78 | 78 |
79 //============================================================================= | 79 //============================================================================= |
80 | 80 |
81 uint Block::code_alignment() { | 81 uint Block::code_alignment() { |
82 // Check for Root block | 82 // Check for Root block |
83 if( _pre_order == 0 ) return CodeEntryAlignment; | 83 if (_pre_order == 0) return CodeEntryAlignment; |
84 // Check for Start block | 84 // Check for Start block |
85 if( _pre_order == 1 ) return InteriorEntryAlignment; | 85 if (_pre_order == 1) return InteriorEntryAlignment; |
86 // Check for loop alignment | 86 // Check for loop alignment |
87 if (has_loop_alignment()) return loop_alignment(); | 87 if (has_loop_alignment()) return loop_alignment(); |
88 | 88 |
89 return 1; // no particular alignment | 89 return relocInfo::addr_unit(); // no particular alignment |
90 } | 90 } |
91 | 91 |
92 uint Block::compute_loop_alignment() { | 92 uint Block::compute_loop_alignment() { |
93 Node *h = head(); | 93 Node *h = head(); |
94 if( h->is_Loop() && h->as_Loop()->is_inner_loop() ) { | 94 int unit_sz = relocInfo::addr_unit(); |
95 if (h->is_Loop() && h->as_Loop()->is_inner_loop()) { | |
95 // Pre- and post-loops have low trip count so do not bother with | 96 // Pre- and post-loops have low trip count so do not bother with |
96 // NOPs for align loop head. The constants are hidden from tuning | 97 // NOPs for align loop head. The constants are hidden from tuning |
97 // but only because my "divide by 4" heuristic surely gets nearly | 98 // but only because my "divide by 4" heuristic surely gets nearly |
98 // all possible gain (a "do not align at all" heuristic has a | 99 // all possible gain (a "do not align at all" heuristic has a |
99 // chance of getting a really tiny gain). | 100 // chance of getting a really tiny gain). |
100 if( h->is_CountedLoop() && (h->as_CountedLoop()->is_pre_loop() || | 101 if (h->is_CountedLoop() && (h->as_CountedLoop()->is_pre_loop() || |
101 h->as_CountedLoop()->is_post_loop()) ) | 102 h->as_CountedLoop()->is_post_loop())) { |
102 return (OptoLoopAlignment > 4) ? (OptoLoopAlignment>>2) : 1; | 103 return (OptoLoopAlignment > 4*unit_sz) ? (OptoLoopAlignment>>2) : unit_sz; |
104 } | |
103 // Loops with low backedge frequency should not be aligned. | 105 // Loops with low backedge frequency should not be aligned. |
104 Node *n = h->in(LoopNode::LoopBackControl)->in(0); | 106 Node *n = h->in(LoopNode::LoopBackControl)->in(0); |
105 if( n->is_MachIf() && n->as_MachIf()->_prob < 0.01 ) { | 107 if (n->is_MachIf() && n->as_MachIf()->_prob < 0.01) { |
106 return 1; // Loop does not loop, more often than not! | 108 return unit_sz; // Loop does not loop, more often than not! |
107 } | 109 } |
108 return OptoLoopAlignment; // Otherwise align loop head | 110 return OptoLoopAlignment; // Otherwise align loop head |
109 } | 111 } |
110 | 112 |
111 return 1; // no particular alignment | 113 return unit_sz; // no particular alignment |
112 } | 114 } |
113 | 115 |
114 //----------------------------------------------------------------------------- | 116 //----------------------------------------------------------------------------- |
115 // Compute the size of first 'inst_cnt' instructions in this block. | 117 // Compute the size of first 'inst_cnt' instructions in this block. |
116 // Return the number of instructions left to compute if the block has | 118 // Return the number of instructions left to compute if the block has |
163 | 165 |
164 int success_result = completely_empty; | 166 int success_result = completely_empty; |
165 int end_idx = _nodes.size()-1; | 167 int end_idx = _nodes.size()-1; |
166 | 168 |
167 // Check for ending goto | 169 // Check for ending goto |
168 if ((end_idx > 0) && (_nodes[end_idx]->is_Goto())) { | 170 if ((end_idx > 0) && (_nodes[end_idx]->is_MachGoto())) { |
169 success_result = empty_with_goto; | 171 success_result = empty_with_goto; |
170 end_idx--; | 172 end_idx--; |
171 } | 173 } |
172 | 174 |
173 // Unreachable blocks are considered empty | 175 // Unreachable blocks are considered empty |
195 // executed infrequently. Check to see if the block ends in a Halt or | 197 // executed infrequently. Check to see if the block ends in a Halt or |
196 // a low probability call. | 198 // a low probability call. |
197 bool Block::has_uncommon_code() const { | 199 bool Block::has_uncommon_code() const { |
198 Node* en = end(); | 200 Node* en = end(); |
199 | 201 |
200 if (en->is_Goto()) | 202 if (en->is_MachGoto()) |
201 en = en->in(0); | 203 en = en->in(0); |
202 if (en->is_Catch()) | 204 if (en->is_Catch()) |
203 en = en->in(0); | 205 en = en->in(0); |
204 if (en->is_Proj() && en->in(0)->is_MachCall()) { | 206 if (en->is_MachProj() && en->in(0)->is_MachCall()) { |
205 MachCallNode* call = en->in(0)->as_MachCall(); | 207 MachCallNode* call = en->in(0)->as_MachCall(); |
206 if (call->cnt() != COUNT_UNKNOWN && call->cnt() <= PROB_UNLIKELY_MAG(4)) { | 208 if (call->cnt() != COUNT_UNKNOWN && call->cnt() <= PROB_UNLIKELY_MAG(4)) { |
207 // This is true for slow-path stubs like new_{instance,array}, | 209 // This is true for slow-path stubs like new_{instance,array}, |
208 // slow_arraycopy, complete_monitor_locking, uncommon_trap. | 210 // slow_arraycopy, complete_monitor_locking, uncommon_trap. |
209 // The magic number corresponds to the probability of an uncommon_trap, | 211 // The magic number corresponds to the probability of an uncommon_trap, |
269 return false; | 271 return false; |
270 } | 272 } |
271 | 273 |
272 //------------------------------dump------------------------------------------- | 274 //------------------------------dump------------------------------------------- |
273 #ifndef PRODUCT | 275 #ifndef PRODUCT |
274 void Block::dump_bidx(const Block* orig) const { | 276 void Block::dump_bidx(const Block* orig, outputStream* st) const { |
275 if (_pre_order) tty->print("B%d",_pre_order); | 277 if (_pre_order) st->print("B%d",_pre_order); |
276 else tty->print("N%d", head()->_idx); | 278 else st->print("N%d", head()->_idx); |
277 | 279 |
278 if (Verbose && orig != this) { | 280 if (Verbose && orig != this) { |
279 // Dump the original block's idx | 281 // Dump the original block's idx |
280 tty->print(" ("); | 282 st->print(" ("); |
281 orig->dump_bidx(orig); | 283 orig->dump_bidx(orig, st); |
282 tty->print(")"); | 284 st->print(")"); |
283 } | 285 } |
284 } | 286 } |
285 | 287 |
286 void Block::dump_pred(const Block_Array *bbs, Block* orig) const { | 288 void Block::dump_pred(const Block_Array *bbs, Block* orig, outputStream* st) const { |
287 if (is_connector()) { | 289 if (is_connector()) { |
288 for (uint i=1; i<num_preds(); i++) { | 290 for (uint i=1; i<num_preds(); i++) { |
289 Block *p = ((*bbs)[pred(i)->_idx]); | 291 Block *p = ((*bbs)[pred(i)->_idx]); |
290 p->dump_pred(bbs, orig); | 292 p->dump_pred(bbs, orig, st); |
291 } | 293 } |
292 } else { | 294 } else { |
293 dump_bidx(orig); | 295 dump_bidx(orig, st); |
294 tty->print(" "); | 296 st->print(" "); |
295 } | 297 } |
296 } | 298 } |
297 | 299 |
298 void Block::dump_head( const Block_Array *bbs ) const { | 300 void Block::dump_head( const Block_Array *bbs, outputStream* st ) const { |
299 // Print the basic block | 301 // Print the basic block |
300 dump_bidx(this); | 302 dump_bidx(this, st); |
301 tty->print(": #\t"); | 303 st->print(": #\t"); |
302 | 304 |
303 // Print the incoming CFG edges and the outgoing CFG edges | 305 // Print the incoming CFG edges and the outgoing CFG edges |
304 for( uint i=0; i<_num_succs; i++ ) { | 306 for( uint i=0; i<_num_succs; i++ ) { |
305 non_connector_successor(i)->dump_bidx(_succs[i]); | 307 non_connector_successor(i)->dump_bidx(_succs[i], st); |
306 tty->print(" "); | 308 st->print(" "); |
307 } | 309 } |
308 tty->print("<- "); | 310 st->print("<- "); |
309 if( head()->is_block_start() ) { | 311 if( head()->is_block_start() ) { |
310 for (uint i=1; i<num_preds(); i++) { | 312 for (uint i=1; i<num_preds(); i++) { |
311 Node *s = pred(i); | 313 Node *s = pred(i); |
312 if (bbs) { | 314 if (bbs) { |
313 Block *p = (*bbs)[s->_idx]; | 315 Block *p = (*bbs)[s->_idx]; |
314 p->dump_pred(bbs, p); | 316 p->dump_pred(bbs, p, st); |
315 } else { | 317 } else { |
316 while (!s->is_block_start()) | 318 while (!s->is_block_start()) |
317 s = s->in(0); | 319 s = s->in(0); |
318 tty->print("N%d ", s->_idx ); | 320 st->print("N%d ", s->_idx ); |
319 } | 321 } |
320 } | 322 } |
321 } else | 323 } else |
322 tty->print("BLOCK HEAD IS JUNK "); | 324 st->print("BLOCK HEAD IS JUNK "); |
323 | 325 |
324 // Print loop, if any | 326 // Print loop, if any |
325 const Block *bhead = this; // Head of self-loop | 327 const Block *bhead = this; // Head of self-loop |
326 Node *bh = bhead->head(); | 328 Node *bh = bhead->head(); |
327 if( bbs && bh->is_Loop() && !head()->is_Root() ) { | 329 if( bbs && bh->is_Loop() && !head()->is_Root() ) { |
328 LoopNode *loop = bh->as_Loop(); | 330 LoopNode *loop = bh->as_Loop(); |
329 const Block *bx = (*bbs)[loop->in(LoopNode::LoopBackControl)->_idx]; | 331 const Block *bx = (*bbs)[loop->in(LoopNode::LoopBackControl)->_idx]; |
330 while (bx->is_connector()) { | 332 while (bx->is_connector()) { |
331 bx = (*bbs)[bx->pred(1)->_idx]; | 333 bx = (*bbs)[bx->pred(1)->_idx]; |
332 } | 334 } |
333 tty->print("\tLoop: B%d-B%d ", bhead->_pre_order, bx->_pre_order); | 335 st->print("\tLoop: B%d-B%d ", bhead->_pre_order, bx->_pre_order); |
334 // Dump any loop-specific bits, especially for CountedLoops. | 336 // Dump any loop-specific bits, especially for CountedLoops. |
335 loop->dump_spec(tty); | 337 loop->dump_spec(st); |
336 } else if (has_loop_alignment()) { | 338 } else if (has_loop_alignment()) { |
337 tty->print(" top-of-loop"); | 339 st->print(" top-of-loop"); |
338 } | 340 } |
339 tty->print(" Freq: %g",_freq); | 341 st->print(" Freq: %g",_freq); |
340 if( Verbose || WizardMode ) { | 342 if( Verbose || WizardMode ) { |
341 tty->print(" IDom: %d/#%d", _idom ? _idom->_pre_order : 0, _dom_depth); | 343 st->print(" IDom: %d/#%d", _idom ? _idom->_pre_order : 0, _dom_depth); |
342 tty->print(" RegPressure: %d",_reg_pressure); | 344 st->print(" RegPressure: %d",_reg_pressure); |
343 tty->print(" IHRP Index: %d",_ihrp_index); | 345 st->print(" IHRP Index: %d",_ihrp_index); |
344 tty->print(" FRegPressure: %d",_freg_pressure); | 346 st->print(" FRegPressure: %d",_freg_pressure); |
345 tty->print(" FHRP Index: %d",_fhrp_index); | 347 st->print(" FHRP Index: %d",_fhrp_index); |
346 } | 348 } |
347 tty->print_cr(""); | 349 st->print_cr(""); |
348 } | 350 } |
349 | 351 |
350 void Block::dump() const { dump(0); } | 352 void Block::dump() const { dump(NULL); } |
351 | 353 |
352 void Block::dump( const Block_Array *bbs ) const { | 354 void Block::dump( const Block_Array *bbs ) const { |
353 dump_head(bbs); | 355 dump_head(bbs); |
354 uint cnt = _nodes.size(); | 356 uint cnt = _nodes.size(); |
355 for( uint i=0; i<cnt; i++ ) | 357 for( uint i=0; i<cnt; i++ ) |
439 | 441 |
440 // Put self in array of basic blocks | 442 // Put self in array of basic blocks |
441 Block *bb = new (_bbs._arena) Block(_bbs._arena,p); | 443 Block *bb = new (_bbs._arena) Block(_bbs._arena,p); |
442 _bbs.map(p->_idx,bb); | 444 _bbs.map(p->_idx,bb); |
443 _bbs.map(x->_idx,bb); | 445 _bbs.map(x->_idx,bb); |
444 if( x != p ) // Only for root is x == p | 446 if( x != p ) { // Only for root is x == p |
445 bb->_nodes.push((Node*)x); | 447 bb->_nodes.push((Node*)x); |
446 | 448 } |
447 // Now handle predecessors | 449 // Now handle predecessors |
448 ++sum; // Count 1 for self block | 450 ++sum; // Count 1 for self block |
449 uint cnt = bb->num_preds(); | 451 uint cnt = bb->num_preds(); |
450 for (int i = (cnt - 1); i > 0; i-- ) { // For all predecessors | 452 for (int i = (cnt - 1); i > 0; i-- ) { // For all predecessors |
451 Node *prevproj = p->in(i); // Get prior input | 453 Node *prevproj = p->in(i); // Get prior input |
835 insert_goto_at(i, 1); | 837 insert_goto_at(i, 1); |
836 } | 838 } |
837 | 839 |
838 // Make sure we TRUE branch to the target | 840 // Make sure we TRUE branch to the target |
839 if( proj0->Opcode() == Op_IfFalse ) { | 841 if( proj0->Opcode() == Op_IfFalse ) { |
840 iff->negate(); | 842 iff->as_MachIf()->negate(); |
841 } | 843 } |
842 | 844 |
843 b->_nodes.pop(); // Remove IfFalse & IfTrue projections | 845 b->_nodes.pop(); // Remove IfFalse & IfTrue projections |
844 b->_nodes.pop(); | 846 b->_nodes.pop(); |
845 | 847 |
894 } | 896 } |
895 | 897 |
896 void PhaseCFG::verify( ) const { | 898 void PhaseCFG::verify( ) const { |
897 #ifdef ASSERT | 899 #ifdef ASSERT |
898 // Verify sane CFG | 900 // Verify sane CFG |
899 for( uint i = 0; i < _num_blocks; i++ ) { | 901 for (uint i = 0; i < _num_blocks; i++) { |
900 Block *b = _blocks[i]; | 902 Block *b = _blocks[i]; |
901 uint cnt = b->_nodes.size(); | 903 uint cnt = b->_nodes.size(); |
902 uint j; | 904 uint j; |
903 for( j = 0; j < cnt; j++ ) { | 905 for (j = 0; j < cnt; j++) { |
904 Node *n = b->_nodes[j]; | 906 Node *n = b->_nodes[j]; |
905 assert( _bbs[n->_idx] == b, "" ); | 907 assert( _bbs[n->_idx] == b, "" ); |
906 if( j >= 1 && n->is_Mach() && | 908 if (j >= 1 && n->is_Mach() && |
907 n->as_Mach()->ideal_Opcode() == Op_CreateEx ) { | 909 n->as_Mach()->ideal_Opcode() == Op_CreateEx) { |
908 assert( j == 1 || b->_nodes[j-1]->is_Phi(), | 910 assert(j == 1 || b->_nodes[j-1]->is_Phi(), |
909 "CreateEx must be first instruction in block" ); | 911 "CreateEx must be first instruction in block"); |
910 } | 912 } |
911 for( uint k = 0; k < n->req(); k++ ) { | 913 for (uint k = 0; k < n->req(); k++) { |
912 Node *def = n->in(k); | 914 Node *def = n->in(k); |
913 if( def && def != n ) { | 915 if (def && def != n) { |
914 assert( _bbs[def->_idx] || def->is_Con(), | 916 assert(_bbs[def->_idx] || def->is_Con(), |
915 "must have block; constants for debug info ok" ); | 917 "must have block; constants for debug info ok"); |
916 // Verify that instructions in the block is in correct order. | 918 // Verify that instructions in the block is in correct order. |
917 // Uses must follow their definition if they are at the same block. | 919 // Uses must follow their definition if they are at the same block. |
918 // Mostly done to check that MachSpillCopy nodes are placed correctly | 920 // Mostly done to check that MachSpillCopy nodes are placed correctly |
919 // when CreateEx node is moved in build_ifg_physical(). | 921 // when CreateEx node is moved in build_ifg_physical(). |
920 if( _bbs[def->_idx] == b && | 922 if (_bbs[def->_idx] == b && |
921 !(b->head()->is_Loop() && n->is_Phi()) && | 923 !(b->head()->is_Loop() && n->is_Phi()) && |
922 // See (+++) comment in reg_split.cpp | 924 // See (+++) comment in reg_split.cpp |
923 !(n->jvms() != NULL && n->jvms()->is_monitor_use(k)) ) { | 925 !(n->jvms() != NULL && n->jvms()->is_monitor_use(k))) { |
924 bool is_loop = false; | 926 bool is_loop = false; |
925 if (n->is_Phi()) { | 927 if (n->is_Phi()) { |
926 for( uint l = 1; l < def->req(); l++ ) { | 928 for (uint l = 1; l < def->req(); l++) { |
927 if (n == def->in(l)) { | 929 if (n == def->in(l)) { |
928 is_loop = true; | 930 is_loop = true; |
929 break; // Some kind of loop | 931 break; // Some kind of loop |
930 } | 932 } |
931 } | 933 } |
932 } | 934 } |
933 assert( is_loop || b->find_node(def) < j, "uses must follow definitions" ); | 935 assert(is_loop || b->find_node(def) < j, "uses must follow definitions"); |
934 } | |
935 if( def->is_SafePointScalarObject() ) { | |
936 assert(_bbs[def->_idx] == b, "SafePointScalarObject Node should be at the same block as its SafePoint node"); | |
937 assert(_bbs[def->_idx] == _bbs[def->in(0)->_idx], "SafePointScalarObject Node should be at the same block as its control edge"); | |
938 } | 936 } |
939 } | 937 } |
940 } | 938 } |
941 } | 939 } |
942 | 940 |
943 j = b->end_idx(); | 941 j = b->end_idx(); |
944 Node *bp = (Node*)b->_nodes[b->_nodes.size()-1]->is_block_proj(); | 942 Node *bp = (Node*)b->_nodes[b->_nodes.size()-1]->is_block_proj(); |
945 assert( bp, "last instruction must be a block proj" ); | 943 assert( bp, "last instruction must be a block proj" ); |
946 assert( bp == b->_nodes[j], "wrong number of successors for this block" ); | 944 assert( bp == b->_nodes[j], "wrong number of successors for this block" ); |
947 if( bp->is_Catch() ) { | 945 if (bp->is_Catch()) { |
948 while( b->_nodes[--j]->Opcode() == Op_MachProj ) ; | 946 while (b->_nodes[--j]->is_MachProj()) ; |
949 assert( b->_nodes[j]->is_Call(), "CatchProj must follow call" ); | 947 assert(b->_nodes[j]->is_MachCall(), "CatchProj must follow call"); |
950 } | 948 } else if (bp->is_Mach() && bp->as_Mach()->ideal_Opcode() == Op_If) { |
951 else if( bp->is_Mach() && bp->as_Mach()->ideal_Opcode() == Op_If ) { | 949 assert(b->_num_succs == 2, "Conditional branch must have two targets"); |
952 assert( b->_num_succs == 2, "Conditional branch must have two targets"); | |
953 } | 950 } |
954 } | 951 } |
955 #endif | 952 #endif |
956 } | 953 } |
957 #endif | 954 #endif |
1103 return dist1 - dist0; | 1100 return dist1 - dist0; |
1104 } | 1101 } |
1105 | 1102 |
1106 //------------------------------trace_frequency_order-------------------------- | 1103 //------------------------------trace_frequency_order-------------------------- |
1107 // Comparison function for edges | 1104 // Comparison function for edges |
1108 static int trace_frequency_order(const void *p0, const void *p1) { | 1105 extern "C" int trace_frequency_order(const void *p0, const void *p1) { |
1109 Trace *tr0 = *(Trace **) p0; | 1106 Trace *tr0 = *(Trace **) p0; |
1110 Trace *tr1 = *(Trace **) p1; | 1107 Trace *tr1 = *(Trace **) p1; |
1111 Block *b0 = tr0->first_block(); | 1108 Block *b0 = tr0->first_block(); |
1112 Block *b1 = tr1->first_block(); | 1109 Block *b1 = tr1->first_block(); |
1113 | 1110 |