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

src/share/vm/opto/matcher.cpp

Print this page
rev 7539 : 8011858: Use Compile::live_nodes() instead of Compile::unique() in appropriate places
Reviewed-by: kvn, vlivanov
Contributed-by: vlad.ureche@gmail.com


 318   // to avoid false sharing if the corresponding mach node is not used.
 319   // The corresponding mach node is only used in rare cases for derived
 320   // pointers.
 321   Node* new_ideal_null = ConNode::make(C, TypePtr::NULL_PTR);
 322 
 323   // Swap out to old-space; emptying new-space
 324   Arena *old = C->node_arena()->move_contents(C->old_arena());
 325 
 326   // Save debug and profile information for nodes in old space:
 327   _old_node_note_array = C->node_note_array();
 328   if (_old_node_note_array != NULL) {
 329     C->set_node_note_array(new(C->comp_arena()) GrowableArray<Node_Notes*>
 330                            (C->comp_arena(), _old_node_note_array->length(),
 331                             0, NULL));
 332   }
 333 
 334   // Pre-size the new_node table to avoid the need for range checks.
 335   grow_new_node_array(C->unique());
 336 
 337   // Reset node counter so MachNodes start with _idx at 0
 338   int nodes = C->unique(); // save value
 339   C->set_unique(0);
 340   C->reset_dead_node_list();
 341 
 342   // Recursively match trees from old space into new space.
 343   // Correct leaves of new-space Nodes; they point to old-space.
 344   _visited.Clear();             // Clear visit bits for xform call
 345   C->set_cached_top_node(xform( C->top(), nodes ));
 346   if (!C->failing()) {
 347     Node* xroot =        xform( C->root(), 1 );
 348     if (xroot == NULL) {
 349       Matcher::soft_match_failure();  // recursive matching process failed
 350       C->record_method_not_compilable("instruction match failed");
 351     } else {
 352       // During matching shared constants were attached to C->root()
 353       // because xroot wasn't available yet, so transfer the uses to
 354       // the xroot.
 355       for( DUIterator_Fast jmax, j = C->root()->fast_outs(jmax); j < jmax; j++ ) {
 356         Node* n = C->root()->fast_out(j);
 357         if (C->node_arena()->contains(n)) {
 358           assert(n->in(0) == C->root(), "should be control user");
 359           n->set_req(0, xroot);
 360           --j;
 361           --jmax;
 362         }
 363       }
 364 
 365       // Generate new mach node for ConP #NULL


 978     }
 979     Node *parent() {
 980       pop();
 981       return node();
 982     }
 983     Node_State state() const {
 984       return (Node_State)index();
 985     }
 986     void set_state(Node_State ns) {
 987       set_index((uint)ns);
 988     }
 989 };
 990 
 991 
 992 //------------------------------xform------------------------------------------
 993 // Given a Node in old-space, Match him (Label/Reduce) to produce a machine
 994 // Node in new-space.  Given a new-space Node, recursively walk his children.
 995 Node *Matcher::transform( Node *n ) { ShouldNotCallThis(); return n; }
 996 Node *Matcher::xform( Node *n, int max_stack ) {
 997   // Use one stack to keep both: child's node/state and parent's node/index
 998   MStack mstack(max_stack * 2 * 2); // C->unique() * 2 * 2
 999   mstack.push(n, Visit, NULL, -1);  // set NULL as parent to indicate root
1000 
1001   while (mstack.is_nonempty()) {
1002     C->check_node_count(NodeLimitFudgeFactor, "too many nodes matching instructions");
1003     if (C->failing()) return NULL;
1004     n = mstack.node();          // Leave node on stack
1005     Node_State nstate = mstack.state();
1006     if (nstate == Visit) {
1007       mstack.set_state(Post_Visit);
1008       Node *oldn = n;
1009       // Old-space or new-space check
1010       if (!C->node_arena()->contains(n)) {
1011         // Old space!
1012         Node* m;
1013         if (has_new_node(n)) {  // Not yet Label/Reduced
1014           m = new_node(n);
1015         } else {
1016           if (!is_dontcare(n)) { // Matcher can match this guy
1017             // Calls match special.  They match alone with no children.
1018             // Their children, the incoming arguments, match normally.


2004              bmii.match(Op_XorI, -1, Op_AddI, -1, -1);
2005     } else if (m->Opcode() == Op_LoadL) {
2006       FusedPatternMatcher<TypeLong> bmil(n, m, Op_ConL);
2007       return bmil.match(Op_AndL, -1, Op_SubL,  1,  0) ||
2008              bmil.match(Op_AndL, -1, Op_AddL, -1, -1) ||
2009              bmil.match(Op_XorL, -1, Op_AddL, -1, -1);
2010     }
2011   }
2012   return false;
2013 }
2014 #endif // X86
2015 
2016 // A method-klass-holder may be passed in the inline_cache_reg
2017 // and then expanded into the inline_cache_reg and a method_oop register
2018 //   defined in ad_<arch>.cpp
2019 
2020 
2021 //------------------------------find_shared------------------------------------
2022 // Set bits if Node is shared or otherwise a root
2023 void Matcher::find_shared( Node *n ) {
2024   // Allocate stack of size C->unique() * 2 to avoid frequent realloc
2025   MStack mstack(C->unique() * 2);
2026   // Mark nodes as address_visited if they are inputs to an address expression
2027   VectorSet address_visited(Thread::current()->resource_area());
2028   mstack.push(n, Visit);     // Don't need to pre-visit root node
2029   while (mstack.is_nonempty()) {
2030     n = mstack.node();       // Leave node on stack
2031     Node_State nstate = mstack.state();
2032     uint nop = n->Opcode();
2033     if (nstate == Pre_Visit) {
2034       if (address_visited.test(n->_idx)) { // Visited in address already?
2035         // Flag as visited and shared now.
2036         set_visited(n);
2037       }
2038       if (is_visited(n)) {   // Visited already?
2039         // Node is shared and has no reason to clone.  Flag it as shared.
2040         // This causes it to match into a register for the sharing.
2041         set_shared(n);       // Flag as shared and
2042         mstack.pop();        // remove node from stack
2043         continue;
2044       }
2045       nstate = Visit; // Not already visited; so visit now




 318   // to avoid false sharing if the corresponding mach node is not used.
 319   // The corresponding mach node is only used in rare cases for derived
 320   // pointers.
 321   Node* new_ideal_null = ConNode::make(C, TypePtr::NULL_PTR);
 322 
 323   // Swap out to old-space; emptying new-space
 324   Arena *old = C->node_arena()->move_contents(C->old_arena());
 325 
 326   // Save debug and profile information for nodes in old space:
 327   _old_node_note_array = C->node_note_array();
 328   if (_old_node_note_array != NULL) {
 329     C->set_node_note_array(new(C->comp_arena()) GrowableArray<Node_Notes*>
 330                            (C->comp_arena(), _old_node_note_array->length(),
 331                             0, NULL));
 332   }
 333 
 334   // Pre-size the new_node table to avoid the need for range checks.
 335   grow_new_node_array(C->unique());
 336 
 337   // Reset node counter so MachNodes start with _idx at 0
 338   int live_nodes = C->live_nodes();
 339   C->set_unique(0);
 340   C->reset_dead_node_list();
 341 
 342   // Recursively match trees from old space into new space.
 343   // Correct leaves of new-space Nodes; they point to old-space.
 344   _visited.Clear();             // Clear visit bits for xform call
 345   C->set_cached_top_node(xform( C->top(), live_nodes));
 346   if (!C->failing()) {
 347     Node* xroot =        xform( C->root(), 1 );
 348     if (xroot == NULL) {
 349       Matcher::soft_match_failure();  // recursive matching process failed
 350       C->record_method_not_compilable("instruction match failed");
 351     } else {
 352       // During matching shared constants were attached to C->root()
 353       // because xroot wasn't available yet, so transfer the uses to
 354       // the xroot.
 355       for( DUIterator_Fast jmax, j = C->root()->fast_outs(jmax); j < jmax; j++ ) {
 356         Node* n = C->root()->fast_out(j);
 357         if (C->node_arena()->contains(n)) {
 358           assert(n->in(0) == C->root(), "should be control user");
 359           n->set_req(0, xroot);
 360           --j;
 361           --jmax;
 362         }
 363       }
 364 
 365       // Generate new mach node for ConP #NULL


 978     }
 979     Node *parent() {
 980       pop();
 981       return node();
 982     }
 983     Node_State state() const {
 984       return (Node_State)index();
 985     }
 986     void set_state(Node_State ns) {
 987       set_index((uint)ns);
 988     }
 989 };
 990 
 991 
 992 //------------------------------xform------------------------------------------
 993 // Given a Node in old-space, Match him (Label/Reduce) to produce a machine
 994 // Node in new-space.  Given a new-space Node, recursively walk his children.
 995 Node *Matcher::transform( Node *n ) { ShouldNotCallThis(); return n; }
 996 Node *Matcher::xform( Node *n, int max_stack ) {
 997   // Use one stack to keep both: child's node/state and parent's node/index
 998   MStack mstack(max_stack * 2 * 2); // usually: C->live_nodes() * 2 * 2
 999   mstack.push(n, Visit, NULL, -1);  // set NULL as parent to indicate root
1000 
1001   while (mstack.is_nonempty()) {
1002     C->check_node_count(NodeLimitFudgeFactor, "too many nodes matching instructions");
1003     if (C->failing()) return NULL;
1004     n = mstack.node();          // Leave node on stack
1005     Node_State nstate = mstack.state();
1006     if (nstate == Visit) {
1007       mstack.set_state(Post_Visit);
1008       Node *oldn = n;
1009       // Old-space or new-space check
1010       if (!C->node_arena()->contains(n)) {
1011         // Old space!
1012         Node* m;
1013         if (has_new_node(n)) {  // Not yet Label/Reduced
1014           m = new_node(n);
1015         } else {
1016           if (!is_dontcare(n)) { // Matcher can match this guy
1017             // Calls match special.  They match alone with no children.
1018             // Their children, the incoming arguments, match normally.


2004              bmii.match(Op_XorI, -1, Op_AddI, -1, -1);
2005     } else if (m->Opcode() == Op_LoadL) {
2006       FusedPatternMatcher<TypeLong> bmil(n, m, Op_ConL);
2007       return bmil.match(Op_AndL, -1, Op_SubL,  1,  0) ||
2008              bmil.match(Op_AndL, -1, Op_AddL, -1, -1) ||
2009              bmil.match(Op_XorL, -1, Op_AddL, -1, -1);
2010     }
2011   }
2012   return false;
2013 }
2014 #endif // X86
2015 
2016 // A method-klass-holder may be passed in the inline_cache_reg
2017 // and then expanded into the inline_cache_reg and a method_oop register
2018 //   defined in ad_<arch>.cpp
2019 
2020 
2021 //------------------------------find_shared------------------------------------
2022 // Set bits if Node is shared or otherwise a root
2023 void Matcher::find_shared( Node *n ) {
2024   // Allocate stack of size C->live_nodes() * 2 to avoid frequent realloc
2025   MStack mstack(C->live_nodes() * 2);
2026   // Mark nodes as address_visited if they are inputs to an address expression
2027   VectorSet address_visited(Thread::current()->resource_area());
2028   mstack.push(n, Visit);     // Don't need to pre-visit root node
2029   while (mstack.is_nonempty()) {
2030     n = mstack.node();       // Leave node on stack
2031     Node_State nstate = mstack.state();
2032     uint nop = n->Opcode();
2033     if (nstate == Pre_Visit) {
2034       if (address_visited.test(n->_idx)) { // Visited in address already?
2035         // Flag as visited and shared now.
2036         set_visited(n);
2037       }
2038       if (is_visited(n)) {   // Visited already?
2039         // Node is shared and has no reason to clone.  Flag it as shared.
2040         // This causes it to match into a register for the sharing.
2041         set_shared(n);       // Flag as shared and
2042         mstack.pop();        // remove node from stack
2043         continue;
2044       }
2045       nstate = Visit; // Not already visited; so visit now


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