comparison src/share/vm/opto/node.cpp @ 24:953939ef62ab

6614330: Node::dump(n) does not print full graph for specified depth. Summary: A node is not processed in dump_nodes() if it was visited during processing previous inputs. Reviewed-by: rasbold
author kvn
date Wed, 20 Feb 2008 16:19:43 -0800
parents a61af66fc99e
children 7c1f32ae4a20
comparison
equal deleted inserted replaced
23:9bdad1bb1c31 24:953939ef62ab
1484 1484
1485 static void dump_nodes(const Node* start, int d, bool only_ctrl) { 1485 static void dump_nodes(const Node* start, int d, bool only_ctrl) {
1486 Node* s = (Node*)start; // remove const 1486 Node* s = (Node*)start; // remove const
1487 if (NotANode(s)) return; 1487 if (NotANode(s)) return;
1488 1488
1489 uint depth = (uint)ABS(d);
1490 int direction = d;
1489 Compile* C = Compile::current(); 1491 Compile* C = Compile::current();
1490 ResourceArea *area = Thread::current()->resource_area(); 1492 ResourceArea *area = Thread::current()->resource_area();
1491 Node_Stack stack(area, MIN2((uint)ABS(d), C->unique() >> 1)); 1493 Node_Stack stack(area, MIN2(depth, C->unique() >> 1));
1492 OldNewVectorSet visited(C->node_arena(), area); 1494 OldNewVectorSet dumped(C->node_arena(), area);
1493 OldNewVectorSet on_stack(C->node_arena(), area); 1495 OldNewVectorSet on_stack(C->node_arena(), area);
1494 1496
1495 visited.set(s);
1496 on_stack.set(s); 1497 on_stack.set(s);
1497 stack.push(s, 0); 1498 stack.push(s, 0);
1498 if (d < 0) s->dump(); 1499 if (direction < 0) {
1500 dumped.set(s);
1501 s->dump();
1502 }
1499 1503
1500 // Do a depth first walk over edges 1504 // Do a depth first walk over edges
1501 while (stack.is_nonempty()) { 1505 while (stack.is_nonempty()) {
1502 Node* tp = stack.node(); 1506 Node* tp = stack.node();
1503 uint idx = stack.index(); 1507 uint idx = stack.index();
1504 uint limit = d > 0 ? tp->len() : tp->outcnt(); 1508 uint limit;
1509 // Limit depth
1510 if (stack.size() < depth) {
1511 limit = direction > 0 ? tp->len() : tp->outcnt();
1512 } else {
1513 limit = 0; // reached depth limit.
1514 }
1505 if (idx >= limit) { 1515 if (idx >= limit) {
1506 // no more arcs to visit 1516 // no more arcs to visit
1507 if (d > 0) tp->dump(); 1517 if (direction > 0 && !dumped.test_set(tp)) tp->dump();
1508 on_stack.del(tp); 1518 on_stack.del(tp);
1509 stack.pop(); 1519 stack.pop();
1510 } else { 1520 } else {
1511 // process the "idx"th arc 1521 // process the "idx"th arc
1512 stack.set_index(idx + 1); 1522 stack.set_index(idx + 1);
1513 Node* n = d > 0 ? tp->in(idx) : tp->raw_out(idx); 1523 Node* n = direction > 0 ? tp->in(idx) : tp->raw_out(idx);
1514 1524
1515 if (NotANode(n)) continue; 1525 if (NotANode(n)) continue;
1516 // do not recurse through top or the root (would reach unrelated stuff) 1526 // do not recurse through top or the root (would reach unrelated stuff)
1517 if (n->is_Root() || n->is_top()) continue; 1527 if (n->is_Root() || n->is_top()) continue;
1518 if (only_ctrl && !n->is_CFG()) continue; 1528 if (only_ctrl && !n->is_CFG()) continue;
1519 1529
1520 if (!visited.test_set(n)) { // forward arc 1530 if (!on_stack.test(n)) { // forward arc
1521 // Limit depth 1531 if (direction < 0 && !dumped.test_set(n)) n->dump();
1522 if (stack.size() < (uint)ABS(d)) { 1532 stack.push(n, 0);
1523 if (d < 0) n->dump(); 1533 on_stack.set(n);
1524 stack.push(n, 0); 1534 } else { // back or cross arc
1525 on_stack.set(n); 1535 // print loop if there are no phis or regions in the mix
1536 bool found_loop_breaker = false;
1537 int k;
1538 for (k = stack.size() - 1; k >= 0; k--) {
1539 Node* m = stack.node_at(k);
1540 if (m->is_Phi() || m->is_Region() || m->is_Root() || m->is_Start()) {
1541 found_loop_breaker = true;
1542 break;
1543 }
1544 if (m == n) // Found loop head
1545 break;
1526 } 1546 }
1527 } else { // back or cross arc 1547 assert(k >= 0, "n must be on stack");
1528 if (on_stack.test(n)) { // back arc 1548
1529 // print loop if there are no phis or regions in the mix 1549 if (!found_loop_breaker) {
1530 bool found_loop_breaker = false; 1550 tty->print("# %s LOOP FOUND:", only_ctrl ? "CONTROL" : "DATA");
1531 int k; 1551 for (int i = stack.size() - 1; i >= k; i--) {
1532 for (k = stack.size() - 1; k >= 0; k--) { 1552 Node* m = stack.node_at(i);
1533 Node* m = stack.node_at(k); 1553 bool mnew = C->node_arena()->contains(m);
1534 if (m->is_Phi() || m->is_Region() || m->is_Root() || m->is_Start()) { 1554 tty->print(" %s%d:%s", (mnew? "": "o"), m->_idx, m->Name());
1535 found_loop_breaker = true; 1555 if (i != 0) tty->print(direction > 0? " <-": " ->");
1536 break;
1537 }
1538 if (m == n) // Found loop head
1539 break;
1540 } 1556 }
1541 assert(k >= 0, "n must be on stack"); 1557 tty->cr();
1542
1543 if (!found_loop_breaker) {
1544 tty->print("# %s LOOP FOUND:", only_ctrl ? "CONTROL" : "DATA");
1545 for (int i = stack.size() - 1; i >= k; i--) {
1546 Node* m = stack.node_at(i);
1547 bool mnew = C->node_arena()->contains(m);
1548 tty->print(" %s%d:%s", (mnew? "": "o"), m->_idx, m->Name());
1549 if (i != 0) tty->print(d > 0? " <-": " ->");
1550 }
1551 tty->cr();
1552 }
1553 } 1558 }
1554 } 1559 }
1555 } 1560 }
1556 } 1561 }
1557 } 1562 }