< prev index next >

src/hotspot/share/opto/lcm.cpp

Print this page




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/macroAssembler.inline.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/ad.hpp"
  29 #include "opto/block.hpp"
  30 #include "opto/c2compiler.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/cfgnode.hpp"
  33 #include "opto/machnode.hpp"
  34 #include "opto/runtime.hpp"
  35 #include "opto/chaitin.hpp"
  36 #include "runtime/sharedRuntime.hpp"




  37 
  38 // Optimization - Graph Style
  39 
  40 // Check whether val is not-null-decoded compressed oop,
  41 // i.e. will grab into the base of the heap if it represents NULL.
  42 static bool accesses_heap_base_zone(Node *val) {
  43   if (Universe::narrow_oop_base() != NULL) { // Implies UseCompressedOops.
  44     if (val && val->is_Mach()) {
  45       if (val->as_Mach()->ideal_Opcode() == Op_DecodeN) {
  46         // This assumes all Decodes with TypePtr::NotNull are matched to nodes that
  47         // decode NULL to point to the heap base (Decode_NN).
  48         if (val->bottom_type()->is_oopptr()->ptr() == TypePtr::NotNull) {
  49           return true;
  50         }
  51       }
  52       // Must recognize load operation with Decode matched in memory operand.
  53       // We should not reach here exept for PPC/AIX, as os::zero_page_read_protected()
  54       // returns true everywhere else. On PPC, no such memory operands
  55       // exist, therefore we did not yet implement a check for such operands.
  56       NOT_AIX(Unimplemented());


 161     was_store = false;
 162     int iop = mach->ideal_Opcode();
 163     switch( iop ) {
 164     case Op_LoadB:
 165     case Op_LoadUB:
 166     case Op_LoadUS:
 167     case Op_LoadD:
 168     case Op_LoadF:
 169     case Op_LoadI:
 170     case Op_LoadL:
 171     case Op_LoadP:
 172     case Op_LoadBarrierSlowReg:
 173     case Op_LoadBarrierWeakSlowReg:
 174     case Op_LoadN:
 175     case Op_LoadS:
 176     case Op_LoadKlass:
 177     case Op_LoadNKlass:
 178     case Op_LoadRange:
 179     case Op_LoadD_unaligned:
 180     case Op_LoadL_unaligned:

 181       assert(mach->in(2) == val, "should be address");
 182       break;
 183     case Op_StoreB:
 184     case Op_StoreC:
 185     case Op_StoreCM:
 186     case Op_StoreD:
 187     case Op_StoreF:
 188     case Op_StoreI:
 189     case Op_StoreL:
 190     case Op_StoreP:
 191     case Op_StoreN:
 192     case Op_StoreNKlass:
 193       was_store = true;         // Memory op is a store op
 194       // Stores will have their address in slot 2 (memory in slot 1).
 195       // If the value being nul-checked is in another slot, it means we
 196       // are storing the checked value, which does NOT check the value!
 197       if( mach->in(2) != val ) continue;
 198       break;                    // Found a memory op?
 199     case Op_StrComp:
 200     case Op_StrEquals:


 768 // carry lots of stuff live across a call.
 769 void PhaseCFG::needed_for_next_call(Block* block, Node* this_call, VectorSet& next_call) {
 770   // Find the next control-defining Node in this block
 771   Node* call = NULL;
 772   for (DUIterator_Fast imax, i = this_call->fast_outs(imax); i < imax; i++) {
 773     Node* m = this_call->fast_out(i);
 774     if (get_block_for_node(m) == block && // Local-block user
 775         m != this_call &&       // Not self-start node
 776         m->is_MachCall()) {
 777       call = m;
 778       break;
 779     }
 780   }
 781   if (call == NULL)  return;    // No next call (e.g., block end is near)
 782   // Set next-call for all inputs to this call
 783   set_next_call(block, call, next_call);
 784 }
 785 
 786 //------------------------------add_call_kills-------------------------------------
 787 // helper function that adds caller save registers to MachProjNode
 788 static void add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe) {
 789   // Fill in the kill mask for the call
 790   for( OptoReg::Name r = OptoReg::Name(0); r < _last_Mach_Reg; r=OptoReg::add(r,1) ) {



 791     if( !regs.Member(r) ) {     // Not already defined by the call
 792       // Save-on-call register?
 793       if ((save_policy[r] == 'C') ||
 794           (save_policy[r] == 'A') ||
 795           ((save_policy[r] == 'E') && exclude_soe)) {
 796         proj->_rout.Insert(r);
 797       }
 798     }
 799   }
 800 }
 801 
 802 
 803 //------------------------------sched_call-------------------------------------
 804 uint PhaseCFG::sched_call(Block* block, uint node_cnt, Node_List& worklist, GrowableArray<int>& ready_cnt, MachCallNode* mcall, VectorSet& next_call) {
 805   RegMask regs;
 806 
 807   // Schedule all the users of the call right now.  All the users are
 808   // projection Nodes, so they must be scheduled next to the call.
 809   // Collect all the defined registers.
 810   for (DUIterator_Fast imax, i = mcall->fast_outs(imax); i < imax; i++) {


 871   // When using CallRuntime mark SOE registers as killed by the call
 872   // so values that could show up in the RegisterMap aren't live in a
 873   // callee saved register since the register wouldn't know where to
 874   // find them.  CallLeaf and CallLeafNoFP are ok because they can't
 875   // have debug info on them.  Strictly speaking this only needs to be
 876   // done for oops since idealreg2debugmask takes care of debug info
 877   // references but there no way to handle oops differently than other
 878   // pointers as far as the kill mask goes.
 879   bool exclude_soe = op == Op_CallRuntime;
 880 
 881   // If the call is a MethodHandle invoke, we need to exclude the
 882   // register which is used to save the SP value over MH invokes from
 883   // the mask.  Otherwise this register could be used for
 884   // deoptimization information.
 885   if (op == Op_CallStaticJava) {
 886     MachCallStaticJavaNode* mcallstaticjava = (MachCallStaticJavaNode*) mcall;
 887     if (mcallstaticjava->_method_handle_invoke)
 888       proj->_rout.OR(Matcher::method_handle_invoke_SP_save_mask());
 889   }
 890 
 891   add_call_kills(proj, regs, save_policy, exclude_soe);
 892 








 893   return node_cnt;
 894 }
 895 
 896 
 897 //------------------------------schedule_local---------------------------------
 898 // Topological sort within a block.  Someday become a real scheduler.
 899 bool PhaseCFG::schedule_local(Block* block, GrowableArray<int>& ready_cnt, VectorSet& next_call, intptr_t *recalc_pressure_nodes) {
 900   // Already "sorted" are the block start Node (as the first entry), and
 901   // the block-ending Node and any trailing control projections.  We leave
 902   // these alone.  PhiNodes and ParmNodes are made to follow the block start
 903   // Node.  Everything else gets topo-sorted.
 904 
 905 #ifndef PRODUCT
 906     if (trace_opto_pipelining()) {
 907       tty->print_cr("# --- schedule_local B%d, before: ---", block->_pre_order);
 908       for (uint i = 0;i < block->number_of_nodes(); i++) {
 909         tty->print("# ");
 910         block->get_node(i)->fast_dump();
 911       }
 912       tty->print_cr("#");


1112         tty->cr();
1113       }
1114     }
1115 
1116 #endif
1117     if( n->is_MachCall() ) {
1118       MachCallNode *mcall = n->as_MachCall();
1119       phi_cnt = sched_call(block, phi_cnt, worklist, ready_cnt, mcall, next_call);
1120       continue;
1121     }
1122 
1123     if (n->is_Mach() && n->as_Mach()->has_call()) {
1124       RegMask regs;
1125       regs.Insert(_matcher.c_frame_pointer());
1126       regs.OR(n->out_RegMask());
1127 
1128       MachProjNode *proj = new MachProjNode( n, 1, RegMask::Empty, MachProjNode::fat_proj );
1129       map_node_to_block(proj, block);
1130       block->insert_node(proj, phi_cnt++);
1131 
1132       add_call_kills(proj, regs, _matcher._c_reg_save_policy, false);
1133     }
1134 
1135     // Children are now all ready
1136     for (DUIterator_Fast i5max, i5 = n->fast_outs(i5max); i5 < i5max; i5++) {
1137       Node* m = n->fast_out(i5); // Get user
1138       if (get_block_for_node(m) != block) {
1139         continue;
1140       }
1141       if( m->is_Phi() ) continue;
1142       if (m->_idx >= max_idx) { // new node, skip it
1143         assert(m->is_MachProj() && n->is_Mach() && n->as_Mach()->has_call(), "unexpected node types");
1144         continue;
1145       }
1146       int m_cnt = ready_cnt.at(m->_idx) - 1;
1147       ready_cnt.at_put(m->_idx, m_cnt);
1148       if( m_cnt == 0 )
1149         worklist.push(m);
1150     }
1151   }
1152 




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/macroAssembler.inline.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/ad.hpp"
  29 #include "opto/block.hpp"
  30 #include "opto/c2compiler.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/cfgnode.hpp"
  33 #include "opto/machnode.hpp"
  34 #include "opto/runtime.hpp"
  35 #include "opto/chaitin.hpp"
  36 #include "runtime/sharedRuntime.hpp"
  37 #include "utilities/macros.hpp"
  38 #if INCLUDE_SHENANDOAHGC
  39 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
  40 #endif
  41 
  42 // Optimization - Graph Style
  43 
  44 // Check whether val is not-null-decoded compressed oop,
  45 // i.e. will grab into the base of the heap if it represents NULL.
  46 static bool accesses_heap_base_zone(Node *val) {
  47   if (Universe::narrow_oop_base() != NULL) { // Implies UseCompressedOops.
  48     if (val && val->is_Mach()) {
  49       if (val->as_Mach()->ideal_Opcode() == Op_DecodeN) {
  50         // This assumes all Decodes with TypePtr::NotNull are matched to nodes that
  51         // decode NULL to point to the heap base (Decode_NN).
  52         if (val->bottom_type()->is_oopptr()->ptr() == TypePtr::NotNull) {
  53           return true;
  54         }
  55       }
  56       // Must recognize load operation with Decode matched in memory operand.
  57       // We should not reach here exept for PPC/AIX, as os::zero_page_read_protected()
  58       // returns true everywhere else. On PPC, no such memory operands
  59       // exist, therefore we did not yet implement a check for such operands.
  60       NOT_AIX(Unimplemented());


 165     was_store = false;
 166     int iop = mach->ideal_Opcode();
 167     switch( iop ) {
 168     case Op_LoadB:
 169     case Op_LoadUB:
 170     case Op_LoadUS:
 171     case Op_LoadD:
 172     case Op_LoadF:
 173     case Op_LoadI:
 174     case Op_LoadL:
 175     case Op_LoadP:
 176     case Op_LoadBarrierSlowReg:
 177     case Op_LoadBarrierWeakSlowReg:
 178     case Op_LoadN:
 179     case Op_LoadS:
 180     case Op_LoadKlass:
 181     case Op_LoadNKlass:
 182     case Op_LoadRange:
 183     case Op_LoadD_unaligned:
 184     case Op_LoadL_unaligned:
 185     case Op_ShenandoahReadBarrier:
 186       assert(mach->in(2) == val, "should be address");
 187       break;
 188     case Op_StoreB:
 189     case Op_StoreC:
 190     case Op_StoreCM:
 191     case Op_StoreD:
 192     case Op_StoreF:
 193     case Op_StoreI:
 194     case Op_StoreL:
 195     case Op_StoreP:
 196     case Op_StoreN:
 197     case Op_StoreNKlass:
 198       was_store = true;         // Memory op is a store op
 199       // Stores will have their address in slot 2 (memory in slot 1).
 200       // If the value being nul-checked is in another slot, it means we
 201       // are storing the checked value, which does NOT check the value!
 202       if( mach->in(2) != val ) continue;
 203       break;                    // Found a memory op?
 204     case Op_StrComp:
 205     case Op_StrEquals:


 773 // carry lots of stuff live across a call.
 774 void PhaseCFG::needed_for_next_call(Block* block, Node* this_call, VectorSet& next_call) {
 775   // Find the next control-defining Node in this block
 776   Node* call = NULL;
 777   for (DUIterator_Fast imax, i = this_call->fast_outs(imax); i < imax; i++) {
 778     Node* m = this_call->fast_out(i);
 779     if (get_block_for_node(m) == block && // Local-block user
 780         m != this_call &&       // Not self-start node
 781         m->is_MachCall()) {
 782       call = m;
 783       break;
 784     }
 785   }
 786   if (call == NULL)  return;    // No next call (e.g., block end is near)
 787   // Set next-call for all inputs to this call
 788   set_next_call(block, call, next_call);
 789 }
 790 
 791 //------------------------------add_call_kills-------------------------------------
 792 // helper function that adds caller save registers to MachProjNode
 793 static void add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe, bool exclude_fp) {
 794   // Fill in the kill mask for the call
 795   for( OptoReg::Name r = OptoReg::Name(0); r < _last_Mach_Reg; r=OptoReg::add(r,1) ) {
 796     if (exclude_fp && (register_save_type[r] == Op_RegF || register_save_type[r] == Op_RegD)) {
 797       continue;
 798     }
 799     if( !regs.Member(r) ) {     // Not already defined by the call
 800       // Save-on-call register?
 801       if ((save_policy[r] == 'C') ||
 802           (save_policy[r] == 'A') ||
 803           ((save_policy[r] == 'E') && exclude_soe)) {
 804         proj->_rout.Insert(r);
 805       }
 806     }
 807   }
 808 }
 809 
 810 
 811 //------------------------------sched_call-------------------------------------
 812 uint PhaseCFG::sched_call(Block* block, uint node_cnt, Node_List& worklist, GrowableArray<int>& ready_cnt, MachCallNode* mcall, VectorSet& next_call) {
 813   RegMask regs;
 814 
 815   // Schedule all the users of the call right now.  All the users are
 816   // projection Nodes, so they must be scheduled next to the call.
 817   // Collect all the defined registers.
 818   for (DUIterator_Fast imax, i = mcall->fast_outs(imax); i < imax; i++) {


 879   // When using CallRuntime mark SOE registers as killed by the call
 880   // so values that could show up in the RegisterMap aren't live in a
 881   // callee saved register since the register wouldn't know where to
 882   // find them.  CallLeaf and CallLeafNoFP are ok because they can't
 883   // have debug info on them.  Strictly speaking this only needs to be
 884   // done for oops since idealreg2debugmask takes care of debug info
 885   // references but there no way to handle oops differently than other
 886   // pointers as far as the kill mask goes.
 887   bool exclude_soe = op == Op_CallRuntime;
 888 
 889   // If the call is a MethodHandle invoke, we need to exclude the
 890   // register which is used to save the SP value over MH invokes from
 891   // the mask.  Otherwise this register could be used for
 892   // deoptimization information.
 893   if (op == Op_CallStaticJava) {
 894     MachCallStaticJavaNode* mcallstaticjava = (MachCallStaticJavaNode*) mcall;
 895     if (mcallstaticjava->_method_handle_invoke)
 896       proj->_rout.OR(Matcher::method_handle_invoke_SP_save_mask());
 897   }
 898 
 899 #if INCLUDE_SHENANDOAHGC
 900   if (UseShenandoahGC &&
 901       ShenandoahBarrierSetAssembler::is_shenandoah_wb_C_call(mcall->entry_point())) {
 902     assert(op == Op_CallLeafNoFP, "shenandoah_wb_C should be called with Op_CallLeafNoFP");
 903     add_call_kills(proj, regs, save_policy, exclude_soe, true);
 904   } else
 905 #endif
 906   {
 907     add_call_kills(proj, regs, save_policy, exclude_soe, false);
 908   }
 909   return node_cnt;
 910 }
 911 
 912 
 913 //------------------------------schedule_local---------------------------------
 914 // Topological sort within a block.  Someday become a real scheduler.
 915 bool PhaseCFG::schedule_local(Block* block, GrowableArray<int>& ready_cnt, VectorSet& next_call, intptr_t *recalc_pressure_nodes) {
 916   // Already "sorted" are the block start Node (as the first entry), and
 917   // the block-ending Node and any trailing control projections.  We leave
 918   // these alone.  PhiNodes and ParmNodes are made to follow the block start
 919   // Node.  Everything else gets topo-sorted.
 920 
 921 #ifndef PRODUCT
 922     if (trace_opto_pipelining()) {
 923       tty->print_cr("# --- schedule_local B%d, before: ---", block->_pre_order);
 924       for (uint i = 0;i < block->number_of_nodes(); i++) {
 925         tty->print("# ");
 926         block->get_node(i)->fast_dump();
 927       }
 928       tty->print_cr("#");


1128         tty->cr();
1129       }
1130     }
1131 
1132 #endif
1133     if( n->is_MachCall() ) {
1134       MachCallNode *mcall = n->as_MachCall();
1135       phi_cnt = sched_call(block, phi_cnt, worklist, ready_cnt, mcall, next_call);
1136       continue;
1137     }
1138 
1139     if (n->is_Mach() && n->as_Mach()->has_call()) {
1140       RegMask regs;
1141       regs.Insert(_matcher.c_frame_pointer());
1142       regs.OR(n->out_RegMask());
1143 
1144       MachProjNode *proj = new MachProjNode( n, 1, RegMask::Empty, MachProjNode::fat_proj );
1145       map_node_to_block(proj, block);
1146       block->insert_node(proj, phi_cnt++);
1147 
1148       add_call_kills(proj, regs, _matcher._c_reg_save_policy, false, false);
1149     }
1150 
1151     // Children are now all ready
1152     for (DUIterator_Fast i5max, i5 = n->fast_outs(i5max); i5 < i5max; i5++) {
1153       Node* m = n->fast_out(i5); // Get user
1154       if (get_block_for_node(m) != block) {
1155         continue;
1156       }
1157       if( m->is_Phi() ) continue;
1158       if (m->_idx >= max_idx) { // new node, skip it
1159         assert(m->is_MachProj() && n->is_Mach() && n->as_Mach()->has_call(), "unexpected node types");
1160         continue;
1161       }
1162       int m_cnt = ready_cnt.at(m->_idx) - 1;
1163       ready_cnt.at_put(m->_idx, m_cnt);
1164       if( m_cnt == 0 )
1165         worklist.push(m);
1166     }
1167   }
1168 


< prev index next >