257 const Node* base = mach->get_base_and_disp(offset, adr_type);
258 if (base == NULL || base == NodeSentinel) {
259 // Narrow oop address doesn't have base, only index.
260 // Give up if offset is beyond page size or if heap base is not protected.
261 if (val->bottom_type()->isa_narrowoop() &&
262 (MacroAssembler::needs_explicit_null_check(offset) ||
263 !CompressedOops::use_implicit_null_checks()))
264 continue;
265 // cannot reason about it; is probably not implicit null exception
266 } else {
267 const TypePtr* tptr;
268 if ((UseCompressedOops || UseCompressedClassPointers) &&
269 (CompressedOops::shift() == 0 || CompressedKlassPointers::shift() == 0)) {
270 // 32-bits narrow oop can be the base of address expressions
271 tptr = base->get_ptr_type();
272 } else {
273 // only regular oops are expected here
274 tptr = base->bottom_type()->is_ptr();
275 }
276 // Give up if offset is not a compile-time constant.
277 if (offset == Type::OffsetBot || tptr->_offset == Type::OffsetBot)
278 continue;
279 offset += tptr->_offset; // correct if base is offseted
280 // Give up if reference is beyond page size.
281 if (MacroAssembler::needs_explicit_null_check(offset))
282 continue;
283 // Give up if base is a decode node and the heap base is not protected.
284 if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
285 !CompressedOops::use_implicit_null_checks())
286 continue;
287 }
288 }
289
290 // Check ctrl input to see if the null-check dominates the memory op
291 Block *cb = get_block_for_node(mach);
292 cb = cb->_idom; // Always hoist at least 1 block
293 if( !was_store ) { // Stores can be hoisted only one block
294 while( cb->_dom_depth > (block->_dom_depth + 1))
295 cb = cb->_idom; // Hoist loads as far as we want
296 // The non-null-block should dominate the memory op, too. Live
297 // range spilling will insert a spill in the non-null-block if it is
298 // needs to spill the memory op for an implicit null check.
299 if (cb->_dom_depth == (block->_dom_depth + 1)) {
300 if (cb != not_null_block) continue;
301 cb = cb->_idom;
302 }
303 }
304 if( cb != block ) continue;
305
306 // Found a memory user; see if it can be hoisted to check-block
307 uint vidx = 0; // Capture index of value into memop
308 uint j;
309 for( j = mach->req()-1; j > 0; j-- ) {
310 if( mach->in(j) == val ) {
311 vidx = j;
312 // Ignore DecodeN val which could be hoisted to where needed.
313 if( is_decoden ) continue;
314 }
315 // Block of memory-op input
316 Block *inb = get_block_for_node(mach->in(j));
317 Block *b = block; // Start from nul check
318 while( b != inb && b->_dom_depth > inb->_dom_depth )
319 b = b->_idom; // search upwards for input
320 // See if input dominates null check
321 if( b != inb )
322 break;
323 }
324 if( j > 0 )
325 continue;
326 Block *mb = get_block_for_node(mach);
327 // Hoisting stores requires more checks for the anti-dependence case.
328 // Give up hoisting if we have to move the store past any load.
329 if( was_store ) {
330 Block *b = mb; // Start searching here for a local load
331 // mach use (faulting) trying to hoist
332 // n might be blocker to hoisting
333 while( b != block ) {
334 uint k;
335 for( k = 1; k < b->number_of_nodes(); k++ ) {
336 Node *n = b->get_node(k);
387 tempb->find_remove(temp);
388 block->add_inst(temp);
389 map_node_to_block(temp, block);
390 }
391 }
392 valb->find_remove(val);
393 block->add_inst(val);
394 map_node_to_block(val, block);
395 // DecodeN on x86 may kill flags. Check for flag-killing projections
396 // that also need to be hoisted.
397 for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
398 Node* n = val->fast_out(j);
399 if( n->is_MachProj() ) {
400 get_block_for_node(n)->find_remove(n);
401 block->add_inst(n);
402 map_node_to_block(n, block);
403 }
404 }
405 }
406 }
407 // Hoist the memory candidate up to the end of the test block.
408 Block *old_block = get_block_for_node(best);
409 old_block->find_remove(best);
410 block->add_inst(best);
411 map_node_to_block(best, block);
412
413 // Move the control dependence if it is pinned to not-null block.
414 // Don't change it in other cases: NULL or dominating control.
415 Node* ctrl = best->in(0);
416 if (ctrl != NULL && get_block_for_node(ctrl) == not_null_block) {
417 // Set it to control edge of null check.
418 best->set_req(0, proj->in(0)->in(0));
419 }
420
421 // Check for flag-killing projections that also need to be hoisted
422 // Should be DU safe because no edge updates.
423 for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
424 Node* n = best->fast_out(j);
425 if( n->is_MachProj() ) {
426 get_block_for_node(n)->find_remove(n);
842 // Children of projections are now all ready
843 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
844 Node* m = n->fast_out(j); // Get user
845 if(get_block_for_node(m) != block) {
846 continue;
847 }
848 if( m->is_Phi() ) continue;
849 int m_cnt = ready_cnt.at(m->_idx) - 1;
850 ready_cnt.at_put(m->_idx, m_cnt);
851 if( m_cnt == 0 )
852 worklist.push(m);
853 }
854
855 }
856
857 // Act as if the call defines the Frame Pointer.
858 // Certainly the FP is alive and well after the call.
859 regs.Insert(_matcher.c_frame_pointer());
860
861 // Set all registers killed and not already defined by the call.
862 uint r_cnt = mcall->tf()->range()->cnt();
863 int op = mcall->ideal_Opcode();
864 MachProjNode *proj = new MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
865 map_node_to_block(proj, block);
866 block->insert_node(proj, node_cnt++);
867
868 // Select the right register save policy.
869 const char *save_policy = NULL;
870 switch (op) {
871 case Op_CallRuntime:
872 case Op_CallLeaf:
873 case Op_CallLeafNoFP:
874 case Op_CallLeafVector:
875 // Calling C code so use C calling convention
876 save_policy = _matcher._c_reg_save_policy;
877 break;
878
879 case Op_CallStaticJava:
880 case Op_CallDynamicJava:
881 // Calling Java code so use Java calling convention
882 save_policy = _matcher._register_save_policy;
|
257 const Node* base = mach->get_base_and_disp(offset, adr_type);
258 if (base == NULL || base == NodeSentinel) {
259 // Narrow oop address doesn't have base, only index.
260 // Give up if offset is beyond page size or if heap base is not protected.
261 if (val->bottom_type()->isa_narrowoop() &&
262 (MacroAssembler::needs_explicit_null_check(offset) ||
263 !CompressedOops::use_implicit_null_checks()))
264 continue;
265 // cannot reason about it; is probably not implicit null exception
266 } else {
267 const TypePtr* tptr;
268 if ((UseCompressedOops || UseCompressedClassPointers) &&
269 (CompressedOops::shift() == 0 || CompressedKlassPointers::shift() == 0)) {
270 // 32-bits narrow oop can be the base of address expressions
271 tptr = base->get_ptr_type();
272 } else {
273 // only regular oops are expected here
274 tptr = base->bottom_type()->is_ptr();
275 }
276 // Give up if offset is not a compile-time constant.
277 if (offset == Type::OffsetBot || tptr->offset() == Type::OffsetBot)
278 continue;
279 offset += tptr->offset(); // correct if base is offseted
280 // Give up if reference is beyond page size.
281 if (MacroAssembler::needs_explicit_null_check(offset))
282 continue;
283 // Give up if base is a decode node and the heap base is not protected.
284 if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
285 !CompressedOops::use_implicit_null_checks())
286 continue;
287 }
288 }
289
290 // Check ctrl input to see if the null-check dominates the memory op
291 Block *cb = get_block_for_node(mach);
292 cb = cb->_idom; // Always hoist at least 1 block
293 if( !was_store ) { // Stores can be hoisted only one block
294 while( cb->_dom_depth > (block->_dom_depth + 1))
295 cb = cb->_idom; // Hoist loads as far as we want
296 // The non-null-block should dominate the memory op, too. Live
297 // range spilling will insert a spill in the non-null-block if it is
298 // needs to spill the memory op for an implicit null check.
299 if (cb->_dom_depth == (block->_dom_depth + 1)) {
300 if (cb != not_null_block) continue;
301 cb = cb->_idom;
302 }
303 }
304 if( cb != block ) continue;
305
306 // Found a memory user; see if it can be hoisted to check-block
307 uint vidx = 0; // Capture index of value into memop
308 uint j;
309 for( j = mach->req()-1; j > 0; j-- ) {
310 if( mach->in(j) == val ) {
311 vidx = j;
312 // Ignore DecodeN val which could be hoisted to where needed.
313 if( is_decoden ) continue;
314 }
315 // Block of memory-op input
316 Block* inb = get_block_for_node(mach->in(j));
317 if (mach->in(j)->is_Con() && mach->in(j)->req() == 1 && inb == get_block_for_node(mach)) {
318 // Ignore constant loads scheduled in the same block (we can simply hoist them as well)
319 continue;
320 }
321 Block *b = block; // Start from nul check
322 while( b != inb && b->_dom_depth > inb->_dom_depth )
323 b = b->_idom; // search upwards for input
324 // See if input dominates null check
325 if( b != inb )
326 break;
327 }
328 if( j > 0 )
329 continue;
330 Block *mb = get_block_for_node(mach);
331 // Hoisting stores requires more checks for the anti-dependence case.
332 // Give up hoisting if we have to move the store past any load.
333 if( was_store ) {
334 Block *b = mb; // Start searching here for a local load
335 // mach use (faulting) trying to hoist
336 // n might be blocker to hoisting
337 while( b != block ) {
338 uint k;
339 for( k = 1; k < b->number_of_nodes(); k++ ) {
340 Node *n = b->get_node(k);
391 tempb->find_remove(temp);
392 block->add_inst(temp);
393 map_node_to_block(temp, block);
394 }
395 }
396 valb->find_remove(val);
397 block->add_inst(val);
398 map_node_to_block(val, block);
399 // DecodeN on x86 may kill flags. Check for flag-killing projections
400 // that also need to be hoisted.
401 for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
402 Node* n = val->fast_out(j);
403 if( n->is_MachProj() ) {
404 get_block_for_node(n)->find_remove(n);
405 block->add_inst(n);
406 map_node_to_block(n, block);
407 }
408 }
409 }
410 }
411
412 // Hoist constant load inputs as well.
413 for (uint i = 1; i < best->req(); ++i) {
414 Node* n = best->in(i);
415 if (n->is_Con() && get_block_for_node(n) == get_block_for_node(best)) {
416 get_block_for_node(n)->find_remove(n);
417 block->add_inst(n);
418 map_node_to_block(n, block);
419 // Constant loads may kill flags (for example, when XORing a register).
420 // Check for flag-killing projections that also need to be hoisted.
421 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
422 Node* proj = n->fast_out(j);
423 if (proj->is_MachProj()) {
424 get_block_for_node(proj)->find_remove(proj);
425 block->add_inst(proj);
426 map_node_to_block(proj, block);
427 }
428 }
429 }
430 }
431
432 // Hoist the memory candidate up to the end of the test block.
433 Block *old_block = get_block_for_node(best);
434 old_block->find_remove(best);
435 block->add_inst(best);
436 map_node_to_block(best, block);
437
438 // Move the control dependence if it is pinned to not-null block.
439 // Don't change it in other cases: NULL or dominating control.
440 Node* ctrl = best->in(0);
441 if (ctrl != NULL && get_block_for_node(ctrl) == not_null_block) {
442 // Set it to control edge of null check.
443 best->set_req(0, proj->in(0)->in(0));
444 }
445
446 // Check for flag-killing projections that also need to be hoisted
447 // Should be DU safe because no edge updates.
448 for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
449 Node* n = best->fast_out(j);
450 if( n->is_MachProj() ) {
451 get_block_for_node(n)->find_remove(n);
867 // Children of projections are now all ready
868 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
869 Node* m = n->fast_out(j); // Get user
870 if(get_block_for_node(m) != block) {
871 continue;
872 }
873 if( m->is_Phi() ) continue;
874 int m_cnt = ready_cnt.at(m->_idx) - 1;
875 ready_cnt.at_put(m->_idx, m_cnt);
876 if( m_cnt == 0 )
877 worklist.push(m);
878 }
879
880 }
881
882 // Act as if the call defines the Frame Pointer.
883 // Certainly the FP is alive and well after the call.
884 regs.Insert(_matcher.c_frame_pointer());
885
886 // Set all registers killed and not already defined by the call.
887 uint r_cnt = mcall->tf()->range_cc()->cnt();
888 int op = mcall->ideal_Opcode();
889 MachProjNode *proj = new MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
890 map_node_to_block(proj, block);
891 block->insert_node(proj, node_cnt++);
892
893 // Select the right register save policy.
894 const char *save_policy = NULL;
895 switch (op) {
896 case Op_CallRuntime:
897 case Op_CallLeaf:
898 case Op_CallLeafNoFP:
899 case Op_CallLeafVector:
900 // Calling C code so use C calling convention
901 save_policy = _matcher._c_reg_save_policy;
902 break;
903
904 case Op_CallStaticJava:
905 case Op_CallDynamicJava:
906 // Calling Java code so use Java calling convention
907 save_policy = _matcher._register_save_policy;
|