267 const Node* base = mach->get_base_and_disp(offset, adr_type);
268 if (base == nullptr || base == NodeSentinel) {
269 // Narrow oop address doesn't have base, only index.
270 // Give up if offset is beyond page size or if heap base is not protected.
271 if (val->bottom_type()->isa_narrowoop() &&
272 (MacroAssembler::needs_explicit_null_check(offset) ||
273 !CompressedOops::use_implicit_null_checks()))
274 continue;
275 // cannot reason about it; is probably not implicit null exception
276 } else {
277 const TypePtr* tptr;
278 if ((UseCompressedOops || UseCompressedClassPointers) &&
279 (CompressedOops::shift() == 0 || CompressedKlassPointers::shift() == 0)) {
280 // 32-bits narrow oop can be the base of address expressions
281 tptr = base->get_ptr_type();
282 } else {
283 // only regular oops are expected here
284 tptr = base->bottom_type()->is_ptr();
285 }
286 // Give up if offset is not a compile-time constant.
287 if (offset == Type::OffsetBot || tptr->_offset == Type::OffsetBot)
288 continue;
289 offset += tptr->_offset; // correct if base is offsetted
290 // Give up if reference is beyond page size.
291 if (MacroAssembler::needs_explicit_null_check(offset))
292 continue;
293 // Give up if base is a decode node and the heap base is not protected.
294 if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
295 !CompressedOops::use_implicit_null_checks())
296 continue;
297 }
298 }
299
300 // Check ctrl input to see if the null-check dominates the memory op
301 Block *cb = get_block_for_node(mach);
302 cb = cb->_idom; // Always hoist at least 1 block
303 if( !was_store ) { // Stores can be hoisted only one block
304 while( cb->_dom_depth > (block->_dom_depth + 1))
305 cb = cb->_idom; // Hoist loads as far as we want
306 // The non-null-block should dominate the memory op, too. Live
307 // range spilling will insert a spill in the non-null-block if it is
308 // needs to spill the memory op for an implicit null check.
309 if (cb->_dom_depth == (block->_dom_depth + 1)) {
310 if (cb != not_null_block) continue;
311 cb = cb->_idom;
312 }
313 }
314 if( cb != block ) continue;
315
316 // Found a memory user; see if it can be hoisted to check-block
317 uint vidx = 0; // Capture index of value into memop
318 uint j;
319 for( j = mach->req()-1; j > 0; j-- ) {
320 if( mach->in(j) == val ) {
321 vidx = j;
322 // Ignore DecodeN val which could be hoisted to where needed.
323 if( is_decoden ) continue;
324 }
325 // Block of memory-op input
326 Block *inb = get_block_for_node(mach->in(j));
327 Block *b = block; // Start from nul check
328 while( b != inb && b->_dom_depth > inb->_dom_depth )
329 b = b->_idom; // search upwards for input
330 // See if input dominates null check
331 if( b != inb )
332 break;
333 }
334 if( j > 0 )
335 continue;
336 Block *mb = get_block_for_node(mach);
337 // Hoisting stores requires more checks for the anti-dependence case.
338 // Give up hoisting if we have to move the store past any load.
339 if (was_store) {
340 // Make sure control does not do a merge (would have to check allpaths)
341 if (mb->num_preds() != 2) {
342 continue;
343 }
344 // mach is a store, hence block is the immediate dominator of mb.
345 // Due to the null-check shape of block (where its successors cannot re-join),
346 // block must be the direct predecessor of mb.
399 tempb->find_remove(temp);
400 block->add_inst(temp);
401 map_node_to_block(temp, block);
402 }
403 }
404 valb->find_remove(val);
405 block->add_inst(val);
406 map_node_to_block(val, block);
407 // DecodeN on x86 may kill flags. Check for flag-killing projections
408 // that also need to be hoisted.
409 for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
410 Node* n = val->fast_out(j);
411 if( n->is_MachProj() ) {
412 get_block_for_node(n)->find_remove(n);
413 block->add_inst(n);
414 map_node_to_block(n, block);
415 }
416 }
417 }
418 }
419 // Hoist the memory candidate up to the end of the test block.
420 Block *old_block = get_block_for_node(best);
421 old_block->find_remove(best);
422 block->add_inst(best);
423 map_node_to_block(best, block);
424
425 // Move the control dependence if it is pinned to not-null block.
426 // Don't change it in other cases: null or dominating control.
427 Node* ctrl = best->in(0);
428 if (ctrl != nullptr && get_block_for_node(ctrl) == not_null_block) {
429 // Set it to control edge of null check.
430 best->set_req(0, proj->in(0)->in(0));
431 }
432
433 // Check for flag-killing projections that also need to be hoisted
434 // Should be DU safe because no edge updates.
435 for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
436 Node* n = best->fast_out(j);
437 if( n->is_MachProj() ) {
438 get_block_for_node(n)->find_remove(n);
869 // Children of projections are now all ready
870 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
871 Node* m = n->fast_out(j); // Get user
872 if(get_block_for_node(m) != block) {
873 continue;
874 }
875 if( m->is_Phi() ) continue;
876 int m_cnt = ready_cnt.at(m->_idx) - 1;
877 ready_cnt.at_put(m->_idx, m_cnt);
878 if( m_cnt == 0 )
879 worklist.push(m);
880 }
881
882 }
883
884 // Act as if the call defines the Frame Pointer.
885 // Certainly the FP is alive and well after the call.
886 regs.Insert(_matcher.c_frame_pointer());
887
888 // Set all registers killed and not already defined by the call.
889 uint r_cnt = mcall->tf()->range()->cnt();
890 int op = mcall->ideal_Opcode();
891 MachProjNode *proj = new MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
892 map_node_to_block(proj, block);
893 block->insert_node(proj, node_cnt++);
894
895 // Select the right register save policy.
896 const char *save_policy = nullptr;
897 switch (op) {
898 case Op_CallRuntime:
899 case Op_CallLeaf:
900 case Op_CallLeafNoFP:
901 case Op_CallLeafVector:
902 // Calling C code so use C calling convention
903 save_policy = _matcher._c_reg_save_policy;
904 break;
905
906 case Op_CallStaticJava:
907 case Op_CallDynamicJava:
908 // Calling Java code so use Java calling convention
909 save_policy = _matcher._register_save_policy;
|
267 const Node* base = mach->get_base_and_disp(offset, adr_type);
268 if (base == nullptr || base == NodeSentinel) {
269 // Narrow oop address doesn't have base, only index.
270 // Give up if offset is beyond page size or if heap base is not protected.
271 if (val->bottom_type()->isa_narrowoop() &&
272 (MacroAssembler::needs_explicit_null_check(offset) ||
273 !CompressedOops::use_implicit_null_checks()))
274 continue;
275 // cannot reason about it; is probably not implicit null exception
276 } else {
277 const TypePtr* tptr;
278 if ((UseCompressedOops || UseCompressedClassPointers) &&
279 (CompressedOops::shift() == 0 || CompressedKlassPointers::shift() == 0)) {
280 // 32-bits narrow oop can be the base of address expressions
281 tptr = base->get_ptr_type();
282 } else {
283 // only regular oops are expected here
284 tptr = base->bottom_type()->is_ptr();
285 }
286 // Give up if offset is not a compile-time constant.
287 if (offset == Type::OffsetBot || tptr->offset() == Type::OffsetBot)
288 continue;
289 offset += tptr->offset(); // correct if base is offsetted
290 // Give up if reference is beyond page size.
291 if (MacroAssembler::needs_explicit_null_check(offset))
292 continue;
293 // Give up if base is a decode node and the heap base is not protected.
294 if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
295 !CompressedOops::use_implicit_null_checks())
296 continue;
297 }
298 }
299
300 // Check ctrl input to see if the null-check dominates the memory op
301 Block *cb = get_block_for_node(mach);
302 cb = cb->_idom; // Always hoist at least 1 block
303 if( !was_store ) { // Stores can be hoisted only one block
304 while( cb->_dom_depth > (block->_dom_depth + 1))
305 cb = cb->_idom; // Hoist loads as far as we want
306 // The non-null-block should dominate the memory op, too. Live
307 // range spilling will insert a spill in the non-null-block if it is
308 // needs to spill the memory op for an implicit null check.
309 if (cb->_dom_depth == (block->_dom_depth + 1)) {
310 if (cb != not_null_block) continue;
311 cb = cb->_idom;
312 }
313 }
314 if( cb != block ) continue;
315
316 // Found a memory user; see if it can be hoisted to check-block
317 uint vidx = 0; // Capture index of value into memop
318 uint j;
319 for( j = mach->req()-1; j > 0; j-- ) {
320 if( mach->in(j) == val ) {
321 vidx = j;
322 // Ignore DecodeN val which could be hoisted to where needed.
323 if( is_decoden ) continue;
324 }
325 // Block of memory-op input
326 Block* inb = get_block_for_node(mach->in(j));
327 if (mach->in(j)->is_Con() && mach->in(j)->req() == 1 && inb == get_block_for_node(mach)) {
328 // Ignore constant loads scheduled in the same block (we can simply hoist them as well)
329 continue;
330 }
331 Block *b = block; // Start from nul check
332 while( b != inb && b->_dom_depth > inb->_dom_depth )
333 b = b->_idom; // search upwards for input
334 // See if input dominates null check
335 if( b != inb )
336 break;
337 }
338 if( j > 0 )
339 continue;
340 Block *mb = get_block_for_node(mach);
341 // Hoisting stores requires more checks for the anti-dependence case.
342 // Give up hoisting if we have to move the store past any load.
343 if (was_store) {
344 // Make sure control does not do a merge (would have to check allpaths)
345 if (mb->num_preds() != 2) {
346 continue;
347 }
348 // mach is a store, hence block is the immediate dominator of mb.
349 // Due to the null-check shape of block (where its successors cannot re-join),
350 // block must be the direct predecessor of mb.
403 tempb->find_remove(temp);
404 block->add_inst(temp);
405 map_node_to_block(temp, block);
406 }
407 }
408 valb->find_remove(val);
409 block->add_inst(val);
410 map_node_to_block(val, block);
411 // DecodeN on x86 may kill flags. Check for flag-killing projections
412 // that also need to be hoisted.
413 for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
414 Node* n = val->fast_out(j);
415 if( n->is_MachProj() ) {
416 get_block_for_node(n)->find_remove(n);
417 block->add_inst(n);
418 map_node_to_block(n, block);
419 }
420 }
421 }
422 }
423
424 // Hoist constant load inputs as well.
425 for (uint i = 1; i < best->req(); ++i) {
426 Node* n = best->in(i);
427 if (n->is_Con() && get_block_for_node(n) == get_block_for_node(best)) {
428 get_block_for_node(n)->find_remove(n);
429 block->add_inst(n);
430 map_node_to_block(n, block);
431 // Constant loads may kill flags (for example, when XORing a register).
432 // Check for flag-killing projections that also need to be hoisted.
433 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
434 Node* proj = n->fast_out(j);
435 if (proj->is_MachProj()) {
436 get_block_for_node(proj)->find_remove(proj);
437 block->add_inst(proj);
438 map_node_to_block(proj, block);
439 }
440 }
441 }
442 }
443
444 // Hoist the memory candidate up to the end of the test block.
445 Block *old_block = get_block_for_node(best);
446 old_block->find_remove(best);
447 block->add_inst(best);
448 map_node_to_block(best, block);
449
450 // Move the control dependence if it is pinned to not-null block.
451 // Don't change it in other cases: null or dominating control.
452 Node* ctrl = best->in(0);
453 if (ctrl != nullptr && get_block_for_node(ctrl) == not_null_block) {
454 // Set it to control edge of null check.
455 best->set_req(0, proj->in(0)->in(0));
456 }
457
458 // Check for flag-killing projections that also need to be hoisted
459 // Should be DU safe because no edge updates.
460 for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
461 Node* n = best->fast_out(j);
462 if( n->is_MachProj() ) {
463 get_block_for_node(n)->find_remove(n);
894 // Children of projections are now all ready
895 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
896 Node* m = n->fast_out(j); // Get user
897 if(get_block_for_node(m) != block) {
898 continue;
899 }
900 if( m->is_Phi() ) continue;
901 int m_cnt = ready_cnt.at(m->_idx) - 1;
902 ready_cnt.at_put(m->_idx, m_cnt);
903 if( m_cnt == 0 )
904 worklist.push(m);
905 }
906
907 }
908
909 // Act as if the call defines the Frame Pointer.
910 // Certainly the FP is alive and well after the call.
911 regs.Insert(_matcher.c_frame_pointer());
912
913 // Set all registers killed and not already defined by the call.
914 uint r_cnt = mcall->tf()->range_cc()->cnt();
915 int op = mcall->ideal_Opcode();
916 MachProjNode *proj = new MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
917 map_node_to_block(proj, block);
918 block->insert_node(proj, node_cnt++);
919
920 // Select the right register save policy.
921 const char *save_policy = nullptr;
922 switch (op) {
923 case Op_CallRuntime:
924 case Op_CallLeaf:
925 case Op_CallLeafNoFP:
926 case Op_CallLeafVector:
927 // Calling C code so use C calling convention
928 save_policy = _matcher._c_reg_save_policy;
929 break;
930
931 case Op_CallStaticJava:
932 case Op_CallDynamicJava:
933 // Calling Java code so use Java calling convention
934 save_policy = _matcher._register_save_policy;
|