Search in sources :

Example 6 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class OptimizedCallTargetTest method testInCompilationRootDirective.

@Ignore
@Test
public void testInCompilationRootDirective() {
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    int[] outerExecute = { 0 };
    int[] outerMethod = { 0 };
    int[] outerBoundary = { 0 };
    int[] innerExecute = { 0 };
    int[] innerMethod = { 0 };
    int[] innerBoundary = { 0 };
    final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public String toString() {
            return "inner";
        }

        @Override
        public Object execute(VirtualFrame frame) {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                innerExecute[0]++;
            }
            innerMethod();
            return null;
        }

        @CompilerDirectives.TruffleBoundary
        void innerMethod() {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                innerMethod[0]++;
            }
        }

        @CompilerDirectives.TruffleBoundary
        void innerBoundary() {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                innerBoundary[0] = 1;
            }
        }
    });
    final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public String toString() {
            return "outer";
        }

        @Child
        private DirectCallNode child = runtime.createDirectCallNode(innerTarget);

        @Override
        public Object execute(VirtualFrame frame) {
            // TRUE
            if (CompilerDirectives.inCompilationRoot()) {
                outerExecute[0]++;
            }
            outerMethod();
            return child.call(new Object[0]);
        }

        void outerMethod() {
            // TRUE
            if (CompilerDirectives.inCompilationRoot()) {
                outerMethod[0]++;
                outerBoundary();
            }
        }

        @CompilerDirectives.TruffleBoundary
        void outerBoundary() {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                outerBoundary[0]++;
            }
        }
    });
    for (int i = 0; i < compilationThreshold; i++) {
        outerTarget.call();
    }
    assertCompiled(outerTarget);
    final int executionCount = 10;
    for (int i = 0; i < executionCount; i++) {
        outerTarget.call();
    }
    Assert.assertEquals(executionCount, outerExecute[0]);
    Assert.assertEquals(executionCount, outerMethod[0]);
    Assert.assertEquals(0, outerBoundary[0]);
    Assert.assertEquals(0, innerExecute[0]);
    Assert.assertEquals(0, innerMethod[0]);
    Assert.assertEquals(0, innerBoundary[0]);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class InteropAccessNode method createInlinedCallNode.

protected static DirectCallNode createInlinedCallNode(CallTarget target) {
    if (target == null) {
        return null;
    }
    DirectCallNode callNode = DirectCallNode.create(target);
    callNode.forceInlining();
    return callNode;
}
Also used : DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode)

Example 8 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class TruffleDirectCallNodeTest method testCanBeClonedWithoutParent.

@Test
public void testCanBeClonedWithoutParent() {
    final RootNode rootNode = new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            return 42;
        }

        @Override
        public boolean isCloningAllowed() {
            return true;
        }
    };
    final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    final DirectCallNode callNode = Truffle.getRuntime().createDirectCallNode(callTarget);
    assertTrue(callNode.isCallTargetCloningAllowed());
    assertTrue(callNode.cloneCallTarget());
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Test(org.junit.Test)

Example 9 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class SplittingStrategyTest method testDefaultStrategyStabilises.

@Test
@SuppressWarnings("try")
public void testDefaultStrategyStabilises() {
    try (TruffleCompilerOptions.TruffleOptionsOverrideScope s = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleSplittingMaxNumberOfSplitNodes, fallbackSplitInfo.getSplitLimit() + 1000)) {
        createDummyTargetsToBoostGrowingSplitLimit();
        class InnerRootNode extends SplittableRootNode {

            OptimizedCallTarget target;

            @Child
            private DirectCallNode callNode1;

            @Child
            private Node polymorphic = new Node() {

                @Override
                public NodeCost getCost() {
                    return NodeCost.POLYMORPHIC;
                }
            };

            protected InnerRootNode() {
                super();
            }

            @Override
            public Object execute(VirtualFrame frame) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                if (callNode1 == null) {
                    callNode1 = runtime.createDirectCallNode(target);
                    adoptChildren();
                }
                if (frame.getArguments().length > 0) {
                    if ((Integer) frame.getArguments()[0] < 100) {
                        callNode1.call(frame.getArguments());
                    }
                }
                return null;
            }

            @Override
            public String toString() {
                return "INNER";
            }
        }
        final InnerRootNode innerRootNode = new InnerRootNode();
        final OptimizedCallTarget inner = (OptimizedCallTarget) runtime.createCallTarget(innerRootNode);
        final OptimizedCallTarget mid = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {

            @Child
            private DirectCallNode callNode = null;

            @Child
            private Node polymorphic = new Node() {

                @Override
                public NodeCost getCost() {
                    return NodeCost.POLYMORPHIC;
                }
            };

            @Override
            public Object execute(VirtualFrame frame) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                if (callNode == null) {
                    callNode = runtime.createDirectCallNode(inner);
                    adoptChildren();
                }
                Object[] arguments = frame.getArguments();
                if ((Integer) arguments[0] < 100) {
                    callNode.call(new Object[] { ((Integer) arguments[0]) + 1 });
                }
                return null;
            }

            @Override
            public String toString() {
                return "MID";
            }
        });
        OptimizedCallTarget outside = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {

            // runtime.createDirectCallNode(mid);
            @Child
            private DirectCallNode outsideCallNode = null;

            @Override
            public Object execute(VirtualFrame frame) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                // Emulates builtin i.e. Split immediately
                if (outsideCallNode == null) {
                    outsideCallNode = runtime.createDirectCallNode(mid);
                    adoptChildren();
                    outsideCallNode.cloneCallTarget();
                }
                return outsideCallNode.call(frame.getArguments());
            }

            @Override
            public String toString() {
                return "OUTSIDE";
            }
        });
        innerRootNode.target = outside;
        createDummyTargetsToBoostGrowingSplitLimit();
        final int baseSplitCount = listener.splitCount;
        outside.call(1);
        // Expected 14
        // OUTSIDE MID
        // MID <split> INNER
        // INNER <split> OUTSIDE
        // OUTSIDE <split> MID
        // INNER OUTSIDE
        // OUTSIDE <split> MID
        // MID <split> INNER
        // MID <split> INNER
        // INNER <split> OUTSIDE
        // OUTSIDE <split> MID
        // INNER <split> OUTSIDE
        // OUTSIDE <split> MID
        // MID <split> INNER
        Assert.assertEquals("Not the right number of splits.", baseSplitCount + 13, listener.splitCount);
    }
}
Also used : Node(com.oracle.truffle.api.nodes.Node) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) NodeCost(com.oracle.truffle.api.nodes.NodeCost) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleCompilerOptions(org.graalvm.compiler.truffle.common.TruffleCompilerOptions) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) Test(org.junit.Test)

Example 10 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class SLGraalRuntimeBuiltin method findCallsTo.

/**
 * Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in a
 * given {@link RootNode}.
 */
@TruffleBoundary
protected static final Set<DirectCallNode> findCallsTo(RootNode root, OptimizedCallTarget originalCallTarget) {
    final Set<DirectCallNode> allCallNodes = new HashSet<>();
    root.accept(new NodeVisitor() {

        @Override
        public boolean visit(Node node) {
            if (node instanceof DirectCallNode) {
                DirectCallNode callNode = (DirectCallNode) node;
                if (callNode.getCallTarget() == originalCallTarget || callNode.getClonedCallTarget() == originalCallTarget) {
                    allCallNodes.add(callNode);
                }
            }
            return true;
        }
    });
    return allCallNodes;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) SLBuiltinNode(com.oracle.truffle.sl.builtins.SLBuiltinNode) RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) HashSet(java.util.HashSet) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)14 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)6 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)5 Test (org.junit.Test)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)4 RootNode (com.oracle.truffle.api.nodes.RootNode)4 CallTarget (com.oracle.truffle.api.CallTarget)3 Node (com.oracle.truffle.api.nodes.Node)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 NodeCost (com.oracle.truffle.api.nodes.NodeCost)1 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)1 Source (com.oracle.truffle.api.source.Source)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 NativeSource (com.oracle.truffle.nfi.types.NativeSource)1 SLBuiltinNode (com.oracle.truffle.sl.builtins.SLBuiltinNode)1 HashSet (java.util.HashSet)1 SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)1 TruffleCompilerOptions (org.graalvm.compiler.truffle.common.TruffleCompilerOptions)1 Ignore (org.junit.Ignore)1