# HG changeset patch # User Christian Humer # Date 1396542828 -7200 # Node ID 1422f0bd55e36b461cf8da1da3980558d7a911eb # Parent b5fed092083ff421384d2890d597d0003fdf6d11 Truffle: Truffle API changes for context sensitive inlining. diff -r b5fed092083f -r 1422f0bd55e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/RootCallTarget.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/RootCallTarget.java Thu Apr 03 18:32:39 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/RootCallTarget.java Thu Apr 03 18:33:48 2014 +0200 @@ -45,7 +45,7 @@ return rootNode.toString(); } - public RootNode getRootNode() { + public final RootNode getRootNode() { return rootNode; } } diff -r b5fed092083f -r 1422f0bd55e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallNode.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallNode.java Thu Apr 03 18:32:39 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallNode.java Thu Apr 03 18:33:48 2014 +0200 @@ -36,7 +36,7 @@ @Override public Object call(PackedFrame caller, Arguments arguments) { - return getCallTarget().call(caller, arguments); + return getCurrentCallTarget().call(caller, arguments); } @Override @@ -70,6 +70,6 @@ @Override public String toString() { - return getParent() != null ? getParent().toString() : super.toString(); + return (getParent() != null ? getParent().toString() : super.toString()) + " call " + getCurrentCallTarget().toString(); } } diff -r b5fed092083f -r 1422f0bd55e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java Thu Apr 03 18:32:39 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java Thu Apr 03 18:33:48 2014 +0200 @@ -155,30 +155,4 @@ return null; } - @Override - protected void onReplace(Node newNode, CharSequence reason) { - super.onReplace(newNode, reason); - - /* - * Old call nodes are removed in the old target root node. - */ - CallNode oldCall = this; - RootNode oldRoot = getCurrentRootNode(); - if (oldRoot != null) { - oldRoot.removeCachedCallNode(oldCall); - } - - registerCallTarget((CallNode) newNode); - } - - /** - * Internal API for the runtime system. - */ - protected static final void registerCallTarget(CallNode newNode) { - RootNode newRoot = newNode.getCurrentRootNode(); - if (newRoot != null) { - newRoot.addCachedCallNode(newNode); - } - } - } diff -r b5fed092083f -r 1422f0bd55e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java Thu Apr 03 18:32:39 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java Thu Apr 03 18:33:48 2014 +0200 @@ -59,6 +59,8 @@ private Element nodesElement; private Element edgesElement; + private ChildSupplier childSupplier; + public GraphPrintVisitor() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { @@ -73,6 +75,14 @@ dom.appendChild(graphDocument); } + public void setChildSupplier(ChildSupplier callNodeVisitor) { + this.childSupplier = callNodeVisitor; + } + + public ChildSupplier getChildSupplier() { + return childSupplier; + } + public GraphPrintVisitor beginGroup(String groupName) { groupElement = dom.createElement("group"); graphDocument.appendChild(groupElement); @@ -328,6 +338,15 @@ // default handler createElementForNode(node); + if (childSupplier != null) { + Object result = childSupplier.startNode(node); + if (result != null) { + visit(result); + connectNodes(node, result, "inlined"); + } + childSupplier.endNode(node); + } + if (node instanceof Node) { for (Map.Entry child : findNamedNodeChildren((Node) node).entrySet()) { visit(child.getValue()); @@ -343,13 +362,6 @@ LinkedHashMap nodes = new LinkedHashMap<>(); NodeClass nodeClass = NodeClass.get(node.getClass()); - if (node instanceof CallNode) { - CallNode callNode = ((CallNode) node); - RootNode inlinedRoot = callNode.getCurrentRootNode(); - if (inlinedRoot != null && callNode.isInlined()) { - nodes.put("inlinedRoot", inlinedRoot); - } - } for (NodeField field : nodeClass.getFields()) { NodeFieldKind kind = field.getKind(); if (kind == NodeFieldKind.CHILD || kind == NodeFieldKind.CHILDREN) { @@ -396,6 +408,15 @@ void visit(Object node, GraphPrintAdapter gPrinter); } + public interface ChildSupplier { + + /** Supplies an additional child if available. */ + Object startNode(Object callNode); + + void endNode(Object callNode); + + } + @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface CustomGraphPrintHandler { diff -r b5fed092083f -r 1422f0bd55e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Apr 03 18:32:39 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Apr 03 18:33:48 2014 +0200 @@ -651,39 +651,6 @@ } - public static void printInliningTree(final PrintStream stream, RootNode root) { - printRootNode(stream, 0, root); - root.accept(new NodeVisitor() { - int depth = 1; - - public boolean visit(Node node) { - if (node instanceof CallNode) { - CallNode callNode = ((CallNode) node); - RootNode inlinedRoot = callNode.getCurrentRootNode(); - if (inlinedRoot != null && callNode.isInlined()) { - depth++; - printRootNode(stream, depth * 2, inlinedRoot); - inlinedRoot.accept(this); - depth--; - } - } - return true; - } - }); - } - - private static void printRootNode(PrintStream stream, int indent, RootNode root) { - for (int i = 0; i < indent; i++) { - stream.print(" "); - } - stream.print(root.toString()); - stream.print(" ("); - stream.print(countNodes(root)); - stream.print("/"); - stream.print(countNodes(root, null, true)); - stream.println(")"); - } - public static String printCompactTreeToString(Node node) { StringWriter out = new StringWriter(); printCompactTree(new PrintWriter(out), null, node, 1); diff -r b5fed092083f -r 1422f0bd55e3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java Thu Apr 03 18:32:39 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java Thu Apr 03 18:33:48 2014 +0200 @@ -24,8 +24,6 @@ */ package com.oracle.truffle.api.nodes; -import java.util.*; - import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; @@ -39,11 +37,6 @@ private RootCallTarget callTarget; private final FrameDescriptor frameDescriptor; - /* - * Internal set to keep back-references to the call-sites. - */ - private final Set cachedCallNodes = Collections.newSetFromMap(new WeakHashMap()); - protected RootNode() { this(null, null); } @@ -114,26 +107,4 @@ this.callTarget = callTarget; } - /* Internal API. Do not use. */ - final void addCachedCallNode(CallNode callSite) { - this.cachedCallNodes.add(callSite); - } - - /* Internal API. Do not use. */ - final void removeCachedCallNode(CallNode callSite) { - this.cachedCallNodes.remove(callSite); - } - - /** - * Returns a {@link Set} of {@link CallNode} nodes which are created to invoke this RootNode. - * This method does not make any guarantees to contain all the {@link CallNode} nodes that are - * invoking this method. Due to its weak nature the elements returned by this method may change - * with each consecutive call. - * - * @return a set of {@link CallNode} nodes - */ - public final Set getCachedCallNodes() { - return Collections.unmodifiableSet(cachedCallNodes); - } - }