333 |
333 |
334 // Pre-size the new_node table to avoid the need for range checks. |
334 // Pre-size the new_node table to avoid the need for range checks. |
335 grow_new_node_array(C->unique()); |
335 grow_new_node_array(C->unique()); |
336 |
336 |
337 // Reset node counter so MachNodes start with _idx at 0 |
337 // Reset node counter so MachNodes start with _idx at 0 |
338 int nodes = C->unique(); // save value |
338 int live_nodes = C->live_nodes(); |
339 C->set_unique(0); |
339 C->set_unique(0); |
340 C->reset_dead_node_list(); |
340 C->reset_dead_node_list(); |
341 |
341 |
342 // Recursively match trees from old space into new space. |
342 // Recursively match trees from old space into new space. |
343 // Correct leaves of new-space Nodes; they point to old-space. |
343 // Correct leaves of new-space Nodes; they point to old-space. |
344 _visited.Clear(); // Clear visit bits for xform call |
344 _visited.Clear(); // Clear visit bits for xform call |
345 C->set_cached_top_node(xform( C->top(), nodes )); |
345 C->set_cached_top_node(xform( C->top(), live_nodes)); |
346 if (!C->failing()) { |
346 if (!C->failing()) { |
347 Node* xroot = xform( C->root(), 1 ); |
347 Node* xroot = xform( C->root(), 1 ); |
348 if (xroot == NULL) { |
348 if (xroot == NULL) { |
349 Matcher::soft_match_failure(); // recursive matching process failed |
349 Matcher::soft_match_failure(); // recursive matching process failed |
350 C->record_method_not_compilable("instruction match failed"); |
350 C->record_method_not_compilable("instruction match failed"); |
993 // Given a Node in old-space, Match him (Label/Reduce) to produce a machine |
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. |
994 // Node in new-space. Given a new-space Node, recursively walk his children. |
995 Node *Matcher::transform( Node *n ) { ShouldNotCallThis(); return n; } |
995 Node *Matcher::transform( Node *n ) { ShouldNotCallThis(); return n; } |
996 Node *Matcher::xform( Node *n, int max_stack ) { |
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 |
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 |
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 |
999 mstack.push(n, Visit, NULL, -1); // set NULL as parent to indicate root |
1000 |
1000 |
1001 while (mstack.is_nonempty()) { |
1001 while (mstack.is_nonempty()) { |
1002 C->check_node_count(NodeLimitFudgeFactor, "too many nodes matching instructions"); |
1002 C->check_node_count(NodeLimitFudgeFactor, "too many nodes matching instructions"); |
1003 if (C->failing()) return NULL; |
1003 if (C->failing()) return NULL; |
2019 |
2019 |
2020 |
2020 |
2021 //------------------------------find_shared------------------------------------ |
2021 //------------------------------find_shared------------------------------------ |
2022 // Set bits if Node is shared or otherwise a root |
2022 // Set bits if Node is shared or otherwise a root |
2023 void Matcher::find_shared( Node *n ) { |
2023 void Matcher::find_shared( Node *n ) { |
2024 // Allocate stack of size C->unique() * 2 to avoid frequent realloc |
2024 // Allocate stack of size C->live_nodes() * 2 to avoid frequent realloc |
2025 MStack mstack(C->unique() * 2); |
2025 MStack mstack(C->live_nodes() * 2); |
2026 // Mark nodes as address_visited if they are inputs to an address expression |
2026 // Mark nodes as address_visited if they are inputs to an address expression |
2027 VectorSet address_visited(Thread::current()->resource_area()); |
2027 VectorSet address_visited(Thread::current()->resource_area()); |
2028 mstack.push(n, Visit); // Don't need to pre-visit root node |
2028 mstack.push(n, Visit); // Don't need to pre-visit root node |
2029 while (mstack.is_nonempty()) { |
2029 while (mstack.is_nonempty()) { |
2030 n = mstack.node(); // Leave node on stack |
2030 n = mstack.node(); // Leave node on stack |