changeset 13807:533b21375e58

SL: migration to Truffle CallNode.
author Christian Humer <christian.humer@gmail.com>
date Tue, 28 Jan 2014 13:37:07 +0100
parents 0a20f43a4a78
children 5dfc531a5af1
files graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionCallNode.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDirectDispatchNode.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinableDirectDispatchNode.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinedDirectDispatchNode.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUninitializedCallNode.java
diffstat 6 files changed, 7 insertions(+), 279 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionCallNode.java	Tue Jan 28 13:36:16 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.nodes;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.impl.*;
-import com.oracle.truffle.api.nodes.*;
-import com.oracle.truffle.sl.runtime.*;
-
-public abstract class FunctionCallNode extends TypedNode {
-
-    private static final int INLINE_CACHE_SIZE = 2;
-
-    @Child protected TypedNode functionNode;
-    @Child protected ArgumentsNode argumentsNode;
-
-    public FunctionCallNode(TypedNode functionNode, ArgumentsNode argumentsNode) {
-        this.functionNode = adoptChild(functionNode);
-        this.argumentsNode = adoptChild(argumentsNode);
-    }
-
-    @Override
-    public final Object executeGeneric(VirtualFrame frame) {
-        CallTarget function;
-        try {
-            function = functionNode.executeCallTarget(frame);
-        } catch (UnexpectedResultException e) {
-            throw new UnsupportedOperationException("Call to " + e.getMessage() + " not supported.");
-        }
-        Object[] arguments = argumentsNode.executeArray(frame);
-        return executeCall(frame, function, new SLArguments(arguments));
-    }
-
-    public abstract Object executeCall(VirtualFrame frame, CallTarget function, SLArguments arguments);
-
-    public static FunctionCallNode create(TypedNode function, TypedNode[] arguments) {
-        return new UninitializedCallNode(function, new ArgumentsNode(arguments), 0);
-    }
-
-    private static final class UninitializedCallNode extends FunctionCallNode {
-
-        protected final int depth;
-
-        UninitializedCallNode(TypedNode function, ArgumentsNode args, int depth) {
-            super(function, args);
-            this.depth = depth;
-        }
-
-        UninitializedCallNode(UninitializedCallNode copy) {
-            super(null, null);
-            this.depth = copy.depth + 1;
-        }
-
-        @Override
-        public Object executeCall(VirtualFrame frame, CallTarget function, SLArguments arguments) {
-            CompilerDirectives.transferToInterpreter();
-            return specialize(function).executeCall(frame, function, arguments);
-        }
-
-        private FunctionCallNode specialize(CallTarget function) {
-            CompilerAsserts.neverPartOfCompilation();
-            if (depth < INLINE_CACHE_SIZE) {
-                return replace(new CachedCallNode(functionNode, argumentsNode, function, new UninitializedCallNode(this)));
-            } else {
-                FunctionCallNode topMost = (FunctionCallNode) NodeUtil.getNthParent(this, depth);
-                return topMost.replace(new GenericCallNode(topMost.functionNode, topMost.argumentsNode));
-            }
-        }
-
-    }
-
-    private static final class CachedCallNode extends FunctionCallNode {
-
-        protected final CallTarget cachedFunction;
-
-        @Child protected CallNode callNode;
-        @Child protected FunctionCallNode nextNode;
-
-        public CachedCallNode(TypedNode function, ArgumentsNode arguments, CallTarget cachedFunction, FunctionCallNode next) {
-            super(function, arguments);
-            this.cachedFunction = cachedFunction;
-            this.callNode = adoptChild(CallNode.create(cachedFunction));
-            this.nextNode = adoptChild(next);
-
-            // inline usually known functions that should always be inlined
-            if (findSLFunctionRoot(cachedFunction).isInlineImmediatly()) {
-                callNode.inline();
-            }
-        }
-
-        @Override
-        public Object executeCall(VirtualFrame frame, CallTarget function, SLArguments arguments) {
-            if (this.cachedFunction == function) {
-                return callNode.call(frame.pack(), arguments);
-            }
-            return nextNode.executeCall(frame, function, arguments);
-        }
-
-        private static FunctionRootNode findSLFunctionRoot(CallTarget target) {
-            return (FunctionRootNode) ((DefaultCallTarget) target).getRootNode();
-        }
-
-    }
-
-    private static final class GenericCallNode extends FunctionCallNode {
-
-        GenericCallNode(TypedNode functionNode, ArgumentsNode arguments) {
-            super(functionNode, arguments);
-        }
-
-        @Override
-        public Object executeCall(VirtualFrame frame, CallTarget function, SLArguments arguments) {
-            return function.call(frame.pack(), arguments);
-        }
-    }
-
-}
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java	Tue Jan 28 13:36:16 2014 +0100
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java	Tue Jan 28 13:37:07 2014 +0100
@@ -75,7 +75,7 @@
 
     @Override
     public RootNode inline() {
-        return new FunctionRootNode(getFrameDescriptor().shallowCopy(), NodeUtil.cloneNode(uninitializedBody), name, inlineImmediatly);
+        return new SLRootNode(getFrameDescriptor().shallowCopy(), NodeUtil.cloneNode(uninitializedBody), name, inlineImmediatly);
     }
 
     @Override
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDirectDispatchNode.java	Tue Jan 28 13:36:16 2014 +0100
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDirectDispatchNode.java	Tue Jan 28 13:37:07 2014 +0100
@@ -27,27 +27,29 @@
 import com.oracle.truffle.api.nodes.*;
 import com.oracle.truffle.sl.runtime.*;
 
-abstract class SLDirectDispatchNode extends SLAbstractDispatchNode {
+final class SLDirectDispatchNode extends SLAbstractDispatchNode {
 
     protected final SLFunction cachedFunction;
     protected final RootCallTarget cachedCallTarget;
     protected final Assumption cachedCallTargetStable;
 
+    @Child protected CallNode callNode;
     @Child protected SLAbstractDispatchNode nextNode;
 
     protected SLDirectDispatchNode(SLAbstractDispatchNode next, SLFunction cachedFunction) {
         this.cachedFunction = cachedFunction;
         this.cachedCallTarget = cachedFunction.getCallTarget();
         this.cachedCallTargetStable = cachedFunction.getCallTargetStable();
+        this.callNode = CallNode.create(cachedCallTarget);
         this.nextNode = adoptChild(next);
     }
 
     @Override
-    protected final Object executeCall(VirtualFrame frame, SLFunction function, SLArguments arguments) {
+    protected Object executeCall(VirtualFrame frame, SLFunction function, SLArguments arguments) {
         if (this.cachedFunction == function) {
             try {
                 cachedCallTargetStable.check();
-                return executeCurrent(frame, arguments);
+                return callNode.call(frame.pack(), arguments);
             } catch (InvalidAssumptionException ex) {
                 /*
                  * Remove ourselfs from the polymorphic inline cache, so that we fail the check only
@@ -61,6 +63,4 @@
         }
         return nextNode.executeCall(frame, function, arguments);
     }
-
-    protected abstract Object executeCurrent(VirtualFrame frame, SLArguments arguments);
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinableDirectDispatchNode.java	Tue Jan 28 13:36:16 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.nodes.call;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.nodes.*;
-import com.oracle.truffle.sl.nodes.*;
-import com.oracle.truffle.sl.runtime.*;
-
-final class SLInlinableDirectDispatchNode extends SLDirectDispatchNode implements InlinableCallSite {
-
-    @CompilationFinal private int callCount;
-
-    protected SLInlinableDirectDispatchNode(SLAbstractDispatchNode next, SLFunction cachedFunction) {
-        super(next, cachedFunction);
-    }
-
-    @Override
-    protected Object executeCurrent(VirtualFrame frame, SLArguments arguments) {
-        if (CompilerDirectives.inInterpreter()) {
-            callCount++;
-        }
-        return cachedCallTarget.call(frame.pack(), arguments);
-    }
-
-    @Override
-    public boolean inline(FrameFactory factory) {
-        CompilerAsserts.neverPartOfCompilation();
-        RootNode root = cachedCallTarget.getRootNode();
-        SLExpressionNode inlinedNode = ((SLRootNode) root).inline();
-        assert inlinedNode != null;
-        replace(new SLInlinedDirectDispatchNode(this, inlinedNode), "Inlined " + root);
-        /* We are always able to inline if required. */
-        return true;
-    }
-
-    @Override
-    public int getCallCount() {
-        return callCount;
-    }
-
-    @Override
-    public void resetCallCount() {
-        callCount = 0;
-    }
-
-    @Override
-    public Node getInlineTree() {
-        RootNode root = cachedCallTarget.getRootNode();
-        if (root instanceof SLRootNode) {
-            return ((SLRootNode) root).getUninitializedBody();
-        }
-        return null;
-    }
-
-    @Override
-    public CallTarget getCallTarget() {
-        return cachedCallTarget;
-    }
-}
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinedDirectDispatchNode.java	Tue Jan 28 13:36:16 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.nodes.call;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.nodes.*;
-import com.oracle.truffle.sl.nodes.*;
-import com.oracle.truffle.sl.runtime.*;
-
-final class SLInlinedDirectDispatchNode extends SLDirectDispatchNode implements InlinedCallSite {
-
-    private final FrameDescriptor descriptor;
-    @Child private SLExpressionNode inlinedBody;
-
-    protected SLInlinedDirectDispatchNode(SLInlinableDirectDispatchNode prev, SLExpressionNode inlinedBody) {
-        super(prev.nextNode, prev.cachedFunction);
-        this.descriptor = cachedCallTarget.getRootNode().getFrameDescriptor();
-        this.inlinedBody = adoptChild(inlinedBody);
-    }
-
-    @Override
-    protected Object executeCurrent(VirtualFrame frame, SLArguments arguments) {
-        VirtualFrame newFrame = Truffle.getRuntime().createVirtualFrame(frame.pack(), arguments, descriptor);
-        return inlinedBody.executeGeneric(newFrame);
-    }
-
-    @Override
-    public CallTarget getCallTarget() {
-        return cachedCallTarget;
-    }
-}
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUninitializedCallNode.java	Tue Jan 28 13:36:16 2014 +0100
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUninitializedCallNode.java	Tue Jan 28 13:37:07 2014 +0100
@@ -43,7 +43,7 @@
         SLAbstractDispatchNode specialized;
         if (depth < INLINE_CACHE_SIZE) {
             SLAbstractDispatchNode next = new SLUninitializedCallNode();
-            SLAbstractDispatchNode direct = new SLInlinableDirectDispatchNode(next, function);
+            SLAbstractDispatchNode direct = new SLDirectDispatchNode(next, function);
             specialized = replace(direct);
         } else {
             SLAbstractDispatchNode generic = new SLGenericDispatchNode();