Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 14564:5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 17 Mar 2014 14:29:45 +0100 |
parents | c5411233cdf8 |
children | 9c01fabfb167 |
comparison
equal
deleted
inserted
replaced
14108:98d38009bb2b | 14564:5d1308c78ddc |
---|---|
32 import sun.misc.*; | 32 import sun.misc.*; |
33 | 33 |
34 import com.oracle.truffle.api.*; | 34 import com.oracle.truffle.api.*; |
35 import com.oracle.truffle.api.nodes.Node.Child; | 35 import com.oracle.truffle.api.nodes.Node.Child; |
36 import com.oracle.truffle.api.nodes.Node.Children; | 36 import com.oracle.truffle.api.nodes.Node.Children; |
37 import com.oracle.truffle.api.nodes.NodeInfo.Kind; | |
38 | 37 |
39 /** | 38 /** |
40 * Utility class that manages the special access methods for node instances. | 39 * Utility class that manages the special access methods for node instances. |
41 */ | 40 */ |
42 public final class NodeUtil { | 41 public final class NodeUtil { |
615 | 614 |
616 public static int countNodes(Node root) { | 615 public static int countNodes(Node root) { |
617 return countNodes(root, null, null, false); | 616 return countNodes(root, null, null, false); |
618 } | 617 } |
619 | 618 |
620 public static int countNodes(Node root, Class<?> clazz, Kind nodeKind, boolean countInlinedCallNodes) { | 619 public static int countNodes(Node root, Class<?> clazz, NodeCost nodeKind, boolean countInlinedCallNodes) { |
621 NodeCountVisitor nodeCount = new NodeCountVisitor(clazz, nodeKind, countInlinedCallNodes); | 620 NodeCountVisitor nodeCount = new NodeCountVisitor(clazz, nodeKind, countInlinedCallNodes); |
622 root.accept(nodeCount); | 621 root.accept(nodeCount); |
623 return nodeCount.nodeCount; | 622 return nodeCount.nodeCount; |
624 } | 623 } |
625 | 624 |
629 | 628 |
630 private static final class NodeCountVisitor implements NodeVisitor { | 629 private static final class NodeCountVisitor implements NodeVisitor { |
631 | 630 |
632 private final boolean inspectInlinedCalls; | 631 private final boolean inspectInlinedCalls; |
633 int nodeCount; | 632 int nodeCount; |
634 private final Kind kind; | 633 private final NodeCost cost; |
635 private final Class<?> clazz; | 634 private final Class<?> clazz; |
636 | 635 |
637 private NodeCountVisitor(Class<?> clazz, Kind kind, boolean inspectInlinedCalls) { | 636 private NodeCountVisitor(Class<?> clazz, NodeCost cost, boolean inspectInlinedCalls) { |
638 this.clazz = clazz; | 637 this.clazz = clazz; |
639 this.kind = kind; | 638 this.cost = cost; |
640 this.inspectInlinedCalls = inspectInlinedCalls; | 639 this.inspectInlinedCalls = inspectInlinedCalls; |
641 } | 640 } |
642 | 641 |
643 @Override | 642 @Override |
644 public boolean visit(Node node) { | 643 public boolean visit(Node node) { |
645 if ((clazz == null || clazz.isInstance(node)) && (kind == null || isKind(node))) { | 644 if ((clazz == null || clazz.isInstance(node)) && (cost == null || isKind(node))) { |
646 nodeCount++; | 645 nodeCount++; |
647 } | 646 } |
648 | 647 |
649 if (inspectInlinedCalls && node instanceof CallNode) { | 648 if (inspectInlinedCalls && node instanceof CallNode) { |
650 CallNode call = (CallNode) node; | 649 CallNode call = (CallNode) node; |
658 | 657 |
659 return true; | 658 return true; |
660 } | 659 } |
661 | 660 |
662 private boolean isKind(Node n) { | 661 private boolean isKind(Node n) { |
663 return kind == n.getKind(); | 662 return cost == n.getCost(); |
664 } | 663 } |
665 } | 664 } |
666 | 665 |
667 public static void printInliningTree(final PrintStream stream, RootNode root) { | 666 public static void printInliningTree(final PrintStream stream, RootNode root) { |
668 printRootNode(stream, 0, root); | 667 printRootNode(stream, 0, root); |