src/share/vm/opto/matcher.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6604014 Sdiff src/share/vm/opto

src/share/vm/opto/matcher.cpp

Print this page




  34   Node::NotAMachineReg, Node::NotAMachineReg, /* tuple, array */
  35   Op_RegP, Op_RegP, Op_RegP, Op_RegP, Op_RegP, Op_RegP, /* the pointers */
  36   0, 0/*abio*/,
  37   Op_RegP /* Return address */, 0, /* the memories */
  38   Op_RegF, Op_RegF, Op_RegF, Op_RegD, Op_RegD, Op_RegD,
  39   0  /*bottom*/
  40 };
  41 
  42 const RegMask *Matcher::idealreg2regmask[_last_machine_leaf];
  43 RegMask Matcher::mreg2regmask[_last_Mach_Reg];
  44 RegMask Matcher::STACK_ONLY_mask;
  45 RegMask Matcher::c_frame_ptr_mask;
  46 const uint Matcher::_begin_rematerialize = _BEGIN_REMATERIALIZE;
  47 const uint Matcher::_end_rematerialize   = _END_REMATERIALIZE;
  48 
  49 //---------------------------Matcher-------------------------------------------
  50 Matcher::Matcher( Node_List &proj_list ) :
  51   PhaseTransform( Phase::Ins_Select ),
  52 #ifdef ASSERT
  53   _old2new_map(C->comp_arena()),

  54 #endif
  55   _shared_nodes(C->comp_arena()),
  56   _reduceOp(reduceOp), _leftOp(leftOp), _rightOp(rightOp),
  57   _swallowed(swallowed),
  58   _begin_inst_chain_rule(_BEGIN_INST_CHAIN_RULE),
  59   _end_inst_chain_rule(_END_INST_CHAIN_RULE),
  60   _must_clone(must_clone), _proj_list(proj_list),
  61   _register_save_policy(register_save_policy),
  62   _c_reg_save_policy(c_reg_save_policy),
  63   _register_save_type(register_save_type),
  64   _ruleName(ruleName),
  65   _allocation_started(false),
  66   _states_arena(Chunk::medium_size),
  67   _visited(&_states_arena),
  68   _shared(&_states_arena),
  69   _dontcare(&_states_arena) {
  70   C->set_matcher(this);
  71 
  72   idealreg2spillmask[Op_RegI] = NULL;
  73   idealreg2spillmask[Op_RegN] = NULL;


 817     if (nstate == Visit) {
 818       mstack.set_state(Post_Visit);
 819       Node *oldn = n;
 820       // Old-space or new-space check
 821       if (!C->node_arena()->contains(n)) {
 822         // Old space!
 823         Node* m;
 824         if (has_new_node(n)) {  // Not yet Label/Reduced
 825           m = new_node(n);
 826         } else {
 827           if (!is_dontcare(n)) { // Matcher can match this guy
 828             // Calls match special.  They match alone with no children.
 829             // Their children, the incoming arguments, match normally.
 830             m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
 831             if (C->failing())  return NULL;
 832             if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
 833           } else {                  // Nothing the matcher cares about
 834             if( n->is_Proj() && n->in(0)->is_Multi()) {       // Projections?
 835               // Convert to machine-dependent projection
 836               m = n->in(0)->as_Multi()->match( n->as_Proj(), this );



 837               if (m->in(0) != NULL) // m might be top
 838                 collect_null_checks(m);
 839             } else {                // Else just a regular 'ol guy
 840               m = n->clone();       // So just clone into new-space



 841               // Def-Use edges will be added incrementally as Uses
 842               // of this node are matched.
 843               assert(m->outcnt() == 0, "no Uses of this clone yet");
 844             }
 845           }
 846 
 847           set_new_node(n, m);       // Map old to new
 848           if (_old_node_note_array != NULL) {
 849             Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
 850                                                   n->_idx);
 851             C->set_node_notes_at(m->_idx, nn);
 852           }
 853           debug_only(match_alias_type(C, n, m));
 854         }
 855         n = m;    // n is now a new-space node
 856         mstack.set_node(n);
 857       }
 858 
 859       // New space!
 860       if (_visited.test_set(n->_idx)) continue; // while(mstack.is_nonempty())


 869       }
 870 
 871       // For constant debug info, I'd rather have unmatched constants.
 872       int cnt = n->req();
 873       JVMState* jvms = n->jvms();
 874       int debug_cnt = jvms ? jvms->debug_start() : cnt;
 875 
 876       // Now do only debug info.  Clone constants rather than matching.
 877       // Constants are represented directly in the debug info without
 878       // the need for executable machine instructions.
 879       // Monitor boxes are also represented directly.
 880       for (i = cnt - 1; i >= debug_cnt; --i) { // For all debug inputs do
 881         Node *m = n->in(i);          // Get input
 882         int op = m->Opcode();
 883         assert((op == Op_BoxLock) == jvms->is_monitor_use(i), "boxes only at monitor sites");
 884         if( op == Op_ConI || op == Op_ConP || op == Op_ConN ||
 885             op == Op_ConF || op == Op_ConD || op == Op_ConL
 886             // || op == Op_BoxLock  // %%%% enable this and remove (+++) in chaitin.cpp
 887             ) {
 888           m = m->clone();



 889           mstack.push(m, Post_Visit, n, i); // Don't neet to visit
 890           mstack.push(m->in(0), Visit, m, 0);
 891         } else {
 892           mstack.push(m, Visit, n, i);
 893         }
 894       }
 895 
 896       // And now walk his children, and convert his inputs to new-space.
 897       for( ; i >= 0; --i ) { // For all normal inputs do
 898         Node *m = n->in(i);  // Get input
 899         if(m != NULL)
 900           mstack.push(m, Visit, n, i);
 901       }
 902 
 903     }
 904     else if (nstate == Post_Visit) {
 905       // Set xformed input
 906       Node *p = mstack.parent();
 907       if (p != NULL) { // root doesn't have parent
 908         int i = (int)mstack.index();


1169   uint cost = max_juint;
1170   uint i;
1171   for( i = 0; i < NUM_OPERANDS; i++ ) {
1172     if( s->valid(i) &&                // valid entry and
1173         s->_cost[i] < cost &&         // low cost and
1174         s->_rule[i] >= NUM_OPERANDS ) // not an operand
1175       cost = s->_cost[mincost=i];
1176   }
1177   if (mincost == max_juint) {
1178 #ifndef PRODUCT
1179     tty->print("No matching rule for:");
1180     s->dump();
1181 #endif
1182     Matcher::soft_match_failure();
1183     return NULL;
1184   }
1185   // Reduce input tree based upon the state labels to machine Nodes
1186   MachNode *m = ReduceInst( s, s->_rule[mincost], mem );
1187 #ifdef ASSERT
1188   _old2new_map.map(n->_idx, m);

1189 #endif
1190 
1191   // Add any Matcher-ignored edges
1192   uint cnt = n->req();
1193   uint start = 1;
1194   if( mem != (Node*)1 ) start = MemNode::Memory+1;
1195   if( n->is_AddP() ) {
1196     assert( mem == (Node*)1, "" );
1197     start = AddPNode::Base+1;
1198   }
1199   for( i = start; i < cnt; i++ ) {
1200     if( !n->match_edge(i) ) {
1201       if( i < m->req() )
1202         m->ins_req( i, n->in(i) );
1203       else
1204         m->add_req( n->in(i) );
1205     }
1206   }
1207 
1208   return m;


1447   // If a Memory was used, insert a Memory edge
1448   if( mem != (Node*)1 )
1449     mach->ins_req(MemNode::Memory,mem);
1450 
1451   // If the _leaf is an AddP, insert the base edge
1452   if( leaf->is_AddP() )
1453     mach->ins_req(AddPNode::Base,leaf->in(AddPNode::Base));
1454 
1455   uint num_proj = _proj_list.size();
1456 
1457   // Perform any 1-to-many expansions required
1458   MachNode *ex = mach->Expand(s,_proj_list);
1459   if( ex != mach ) {
1460     assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match");
1461     if( ex->in(1)->is_Con() )
1462       ex->in(1)->set_req(0, C->root());
1463     // Remove old node from the graph
1464     for( uint i=0; i<mach->req(); i++ ) {
1465       mach->set_req(i,NULL);
1466     }



1467   }
1468 
1469   // PhaseChaitin::fixup_spills will sometimes generate spill code
1470   // via the matcher.  By the time, nodes have been wired into the CFG,
1471   // and any further nodes generated by expand rules will be left hanging
1472   // in space, and will not get emitted as output code.  Catch this.
1473   // Also, catch any new register allocation constraints ("projections")
1474   // generated belatedly during spill code generation.
1475   if (_allocation_started) {
1476     guarantee(ex == mach, "no expand rules during spill generation");
1477     guarantee(_proj_list.size() == num_proj, "no allocation during spill generation");
1478   }
1479 
1480   if (leaf->is_Con() || leaf->is_DecodeN()) {
1481     // Record the con for sharing
1482     _shared_nodes.map(leaf->_idx, ex);
1483   }
1484 
1485   return ex;
1486 }




  34   Node::NotAMachineReg, Node::NotAMachineReg, /* tuple, array */
  35   Op_RegP, Op_RegP, Op_RegP, Op_RegP, Op_RegP, Op_RegP, /* the pointers */
  36   0, 0/*abio*/,
  37   Op_RegP /* Return address */, 0, /* the memories */
  38   Op_RegF, Op_RegF, Op_RegF, Op_RegD, Op_RegD, Op_RegD,
  39   0  /*bottom*/
  40 };
  41 
  42 const RegMask *Matcher::idealreg2regmask[_last_machine_leaf];
  43 RegMask Matcher::mreg2regmask[_last_Mach_Reg];
  44 RegMask Matcher::STACK_ONLY_mask;
  45 RegMask Matcher::c_frame_ptr_mask;
  46 const uint Matcher::_begin_rematerialize = _BEGIN_REMATERIALIZE;
  47 const uint Matcher::_end_rematerialize   = _END_REMATERIALIZE;
  48 
  49 //---------------------------Matcher-------------------------------------------
  50 Matcher::Matcher( Node_List &proj_list ) :
  51   PhaseTransform( Phase::Ins_Select ),
  52 #ifdef ASSERT
  53   _old2new_map(C->comp_arena()),
  54   _new2old_map(C->comp_arena()),
  55 #endif
  56   _shared_nodes(C->comp_arena()),
  57   _reduceOp(reduceOp), _leftOp(leftOp), _rightOp(rightOp),
  58   _swallowed(swallowed),
  59   _begin_inst_chain_rule(_BEGIN_INST_CHAIN_RULE),
  60   _end_inst_chain_rule(_END_INST_CHAIN_RULE),
  61   _must_clone(must_clone), _proj_list(proj_list),
  62   _register_save_policy(register_save_policy),
  63   _c_reg_save_policy(c_reg_save_policy),
  64   _register_save_type(register_save_type),
  65   _ruleName(ruleName),
  66   _allocation_started(false),
  67   _states_arena(Chunk::medium_size),
  68   _visited(&_states_arena),
  69   _shared(&_states_arena),
  70   _dontcare(&_states_arena) {
  71   C->set_matcher(this);
  72 
  73   idealreg2spillmask[Op_RegI] = NULL;
  74   idealreg2spillmask[Op_RegN] = NULL;


 818     if (nstate == Visit) {
 819       mstack.set_state(Post_Visit);
 820       Node *oldn = n;
 821       // Old-space or new-space check
 822       if (!C->node_arena()->contains(n)) {
 823         // Old space!
 824         Node* m;
 825         if (has_new_node(n)) {  // Not yet Label/Reduced
 826           m = new_node(n);
 827         } else {
 828           if (!is_dontcare(n)) { // Matcher can match this guy
 829             // Calls match special.  They match alone with no children.
 830             // Their children, the incoming arguments, match normally.
 831             m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
 832             if (C->failing())  return NULL;
 833             if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
 834           } else {                  // Nothing the matcher cares about
 835             if( n->is_Proj() && n->in(0)->is_Multi()) {       // Projections?
 836               // Convert to machine-dependent projection
 837               m = n->in(0)->as_Multi()->match( n->as_Proj(), this );
 838 #ifdef ASSERT
 839               _new2old_map.map(m->_idx, n);
 840 #endif
 841               if (m->in(0) != NULL) // m might be top
 842                 collect_null_checks(m);
 843             } else {                // Else just a regular 'ol guy
 844               m = n->clone();       // So just clone into new-space
 845 #ifdef ASSERT
 846               _new2old_map.map(m->_idx, n);
 847 #endif
 848               // Def-Use edges will be added incrementally as Uses
 849               // of this node are matched.
 850               assert(m->outcnt() == 0, "no Uses of this clone yet");
 851             }
 852           }
 853 
 854           set_new_node(n, m);       // Map old to new
 855           if (_old_node_note_array != NULL) {
 856             Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
 857                                                   n->_idx);
 858             C->set_node_notes_at(m->_idx, nn);
 859           }
 860           debug_only(match_alias_type(C, n, m));
 861         }
 862         n = m;    // n is now a new-space node
 863         mstack.set_node(n);
 864       }
 865 
 866       // New space!
 867       if (_visited.test_set(n->_idx)) continue; // while(mstack.is_nonempty())


 876       }
 877 
 878       // For constant debug info, I'd rather have unmatched constants.
 879       int cnt = n->req();
 880       JVMState* jvms = n->jvms();
 881       int debug_cnt = jvms ? jvms->debug_start() : cnt;
 882 
 883       // Now do only debug info.  Clone constants rather than matching.
 884       // Constants are represented directly in the debug info without
 885       // the need for executable machine instructions.
 886       // Monitor boxes are also represented directly.
 887       for (i = cnt - 1; i >= debug_cnt; --i) { // For all debug inputs do
 888         Node *m = n->in(i);          // Get input
 889         int op = m->Opcode();
 890         assert((op == Op_BoxLock) == jvms->is_monitor_use(i), "boxes only at monitor sites");
 891         if( op == Op_ConI || op == Op_ConP || op == Op_ConN ||
 892             op == Op_ConF || op == Op_ConD || op == Op_ConL
 893             // || op == Op_BoxLock  // %%%% enable this and remove (+++) in chaitin.cpp
 894             ) {
 895           m = m->clone();
 896 #ifdef ASSERT
 897           _new2old_map.map(m->_idx, n);
 898 #endif
 899           mstack.push(m, Post_Visit, n, i); // Don't neet to visit
 900           mstack.push(m->in(0), Visit, m, 0);
 901         } else {
 902           mstack.push(m, Visit, n, i);
 903         }
 904       }
 905 
 906       // And now walk his children, and convert his inputs to new-space.
 907       for( ; i >= 0; --i ) { // For all normal inputs do
 908         Node *m = n->in(i);  // Get input
 909         if(m != NULL)
 910           mstack.push(m, Visit, n, i);
 911       }
 912 
 913     }
 914     else if (nstate == Post_Visit) {
 915       // Set xformed input
 916       Node *p = mstack.parent();
 917       if (p != NULL) { // root doesn't have parent
 918         int i = (int)mstack.index();


1179   uint cost = max_juint;
1180   uint i;
1181   for( i = 0; i < NUM_OPERANDS; i++ ) {
1182     if( s->valid(i) &&                // valid entry and
1183         s->_cost[i] < cost &&         // low cost and
1184         s->_rule[i] >= NUM_OPERANDS ) // not an operand
1185       cost = s->_cost[mincost=i];
1186   }
1187   if (mincost == max_juint) {
1188 #ifndef PRODUCT
1189     tty->print("No matching rule for:");
1190     s->dump();
1191 #endif
1192     Matcher::soft_match_failure();
1193     return NULL;
1194   }
1195   // Reduce input tree based upon the state labels to machine Nodes
1196   MachNode *m = ReduceInst( s, s->_rule[mincost], mem );
1197 #ifdef ASSERT
1198   _old2new_map.map(n->_idx, m);
1199   _new2old_map.map(m->_idx, (Node*)n);
1200 #endif
1201 
1202   // Add any Matcher-ignored edges
1203   uint cnt = n->req();
1204   uint start = 1;
1205   if( mem != (Node*)1 ) start = MemNode::Memory+1;
1206   if( n->is_AddP() ) {
1207     assert( mem == (Node*)1, "" );
1208     start = AddPNode::Base+1;
1209   }
1210   for( i = start; i < cnt; i++ ) {
1211     if( !n->match_edge(i) ) {
1212       if( i < m->req() )
1213         m->ins_req( i, n->in(i) );
1214       else
1215         m->add_req( n->in(i) );
1216     }
1217   }
1218 
1219   return m;


1458   // If a Memory was used, insert a Memory edge
1459   if( mem != (Node*)1 )
1460     mach->ins_req(MemNode::Memory,mem);
1461 
1462   // If the _leaf is an AddP, insert the base edge
1463   if( leaf->is_AddP() )
1464     mach->ins_req(AddPNode::Base,leaf->in(AddPNode::Base));
1465 
1466   uint num_proj = _proj_list.size();
1467 
1468   // Perform any 1-to-many expansions required
1469   MachNode *ex = mach->Expand(s,_proj_list);
1470   if( ex != mach ) {
1471     assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match");
1472     if( ex->in(1)->is_Con() )
1473       ex->in(1)->set_req(0, C->root());
1474     // Remove old node from the graph
1475     for( uint i=0; i<mach->req(); i++ ) {
1476       mach->set_req(i,NULL);
1477     }
1478 #ifdef ASSERT
1479     _new2old_map.map(ex->_idx, s->_leaf);
1480 #endif
1481   }
1482 
1483   // PhaseChaitin::fixup_spills will sometimes generate spill code
1484   // via the matcher.  By the time, nodes have been wired into the CFG,
1485   // and any further nodes generated by expand rules will be left hanging
1486   // in space, and will not get emitted as output code.  Catch this.
1487   // Also, catch any new register allocation constraints ("projections")
1488   // generated belatedly during spill code generation.
1489   if (_allocation_started) {
1490     guarantee(ex == mach, "no expand rules during spill generation");
1491     guarantee(_proj_list.size() == num_proj, "no allocation during spill generation");
1492   }
1493 
1494   if (leaf->is_Con() || leaf->is_DecodeN()) {
1495     // Record the con for sharing
1496     _shared_nodes.map(leaf->_idx, ex);
1497   }
1498 
1499   return ex;
1500 }


src/share/vm/opto/matcher.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File