Search in sources :

Example 1 with OptimizedBlockNode

use of org.graalvm.compiler.truffle.runtime.OptimizedBlockNode in project graal by oracle.

the class OptimizedBlockNodeTest method createBlock.

private static OptimizedBlockNode<TestElement> createBlock(int blockSize, int depth, Object returnValue, ElementExecutor<TestElement> executor, int extraChildrenOfFirstElement) {
    if (depth == 0) {
        return null;
    }
    TestElement[] elements = new TestElement[blockSize];
    for (int i = 0; i < blockSize; i++) {
        Node[] extraDummyChildren;
        if (i == 0 && extraChildrenOfFirstElement > 0) {
            extraDummyChildren = new Node[extraChildrenOfFirstElement];
            for (int j = 0; j < extraDummyChildren.length; j++) {
                extraDummyChildren[j] = new Node() {
                };
            }
        } else {
            extraDummyChildren = new Node[0];
        }
        elements[i] = new TestElement(createBlock(blockSize, depth - 1, returnValue), returnValue == null ? i : returnValue, i, extraDummyChildren);
    }
    return (OptimizedBlockNode<TestElement>) BlockNode.create(elements, executor);
}
Also used : OptimizedBlockNode(org.graalvm.compiler.truffle.runtime.OptimizedBlockNode) BlockNode(com.oracle.truffle.api.nodes.BlockNode) OptimizedBlockNode(org.graalvm.compiler.truffle.runtime.OptimizedBlockNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node)

Example 2 with OptimizedBlockNode

use of org.graalvm.compiler.truffle.runtime.OptimizedBlockNode in project graal by oracle.

the class OptimizedBlockNodeTest method testSimpleLanguageExample.

@Test
public void testSimpleLanguageExample() {
    final int testBlockSize = 128;
    final int targetBlocks = 4;
    setup(testBlockSize);
    int emptyNodeCount = generateSLFunction(context, "empty", BlockNode.NO_ARGUMENT).getNonTrivialNodeCount();
    int singleNodeCount = generateSLFunction(context, "single", 1).getNonTrivialNodeCount();
    int twoNodeCount = generateSLFunction(context, "two", 2).getNonTrivialNodeCount();
    int singleStatementNodeCount = twoNodeCount - singleNodeCount;
    int blockOverhead = singleNodeCount - emptyNodeCount - singleStatementNodeCount;
    context.initialize("sl");
    int statements = Math.floorDiv(((testBlockSize * targetBlocks) - (blockOverhead)), singleStatementNodeCount);
    OptimizedCallTarget target = generateSLFunction(context, "test", statements);
    target.computeBlockCompilations();
    assertEquals((statements - 1) * singleStatementNodeCount + singleNodeCount, target.getNonTrivialNodeCount());
    Value v = context.getBindings("sl").getMember("test");
    // make it compile with threshold
    for (int i = 0; i < TEST_COMPILATION_THRESHOLD; i++) {
        assertEquals(statements, v.execute().asInt());
    }
    assertTrue(target.isValid());
    List<OptimizedBlockNode<TestElement>> blocks = new ArrayList<>();
    target.getRootNode().accept(new NodeVisitor() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean visit(Node node) {
            if (node instanceof OptimizedBlockNode<?>) {
                blocks.add((OptimizedBlockNode<TestElement>) node);
            }
            return true;
        }
    });
    assertEquals(1, blocks.size());
    OptimizedBlockNode<TestElement> block = blocks.iterator().next();
    PartialBlocks<TestElement> partialBlocks = block.getPartialBlocks();
    assertNotNull(partialBlocks);
    assertEquals(targetBlocks, partialBlocks.getBlockTargets().length);
}
Also used : BlockNode(com.oracle.truffle.api.nodes.BlockNode) OptimizedBlockNode(org.graalvm.compiler.truffle.runtime.OptimizedBlockNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) ArrayList(java.util.ArrayList) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) OptimizedBlockNode(org.graalvm.compiler.truffle.runtime.OptimizedBlockNode) Value(org.graalvm.polyglot.Value) Test(org.junit.Test)

Aggregations

BlockNode (com.oracle.truffle.api.nodes.BlockNode)2 Node (com.oracle.truffle.api.nodes.Node)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 OptimizedBlockNode (org.graalvm.compiler.truffle.runtime.OptimizedBlockNode)2 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)1 ArrayList (java.util.ArrayList)1 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)1 Value (org.graalvm.polyglot.Value)1 Test (org.junit.Test)1