Search in sources :

Example 81 with RootNode

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

the class ContextThreadLocalTest method testCompilation.

@Test
public void testCompilation() {
    ThreadLocal<Object> tl = createContextThreadLocal();
    Object context1 = createContext();
    CallTarget compiled = Truffle.getRuntime().createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            Object result = tl.get();
            return result;
        }
    });
    tl.set(context1);
    for (int i = 0; i < 10000; i++) {
        compiled.call();
    }
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 82 with RootNode

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

the class RootNodeTest method testNotReplacable3.

@Test(expected = IllegalStateException.class)
@Ignore
public void testNotReplacable3() {
    TestRootNode2 rootNode = new TestRootNode2();
    rootNode.rootNodeAsChild = new Node() {
    };
    rootNode.adoptChildren();
    rootNode.rootNodeAsChild.replace(new TestRootNode());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 83 with RootNode

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

the class ChildrenNodesTest method testMultipleChildrenFields.

@Test
public void testMultipleChildrenFields() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildNode firstChild = new TestChildNode();
    TestChildNode secondChild = new TestChildNode();
    TestChildNode thirdChild = new TestChildNode();
    TestChildNode forthChild = new TestChildNode();
    TestRootNode rootNode = new TestRoot2Node(new TestChildNode[] { firstChild, secondChild }, new TestChildNode[] { thirdChild, forthChild });
    CallTarget target = runtime.createCallTarget(rootNode);
    Assert.assertEquals(rootNode, firstChild.getParent());
    Assert.assertEquals(rootNode, secondChild.getParent());
    Assert.assertEquals(rootNode, thirdChild.getParent());
    Assert.assertEquals(rootNode, forthChild.getParent());
    Iterator<Node> iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(firstChild, iterator.next());
    Assert.assertEquals(secondChild, iterator.next());
    Assert.assertEquals(thirdChild, iterator.next());
    Assert.assertEquals(forthChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(2 * 42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 84 with RootNode

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

the class InterfaceChildFieldTest method testChild.

@Test
public void testChild() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildInterface leftChild = new TestLeafNode();
    TestChildInterface rightChild = new TestLeafNode();
    TestChildNode parent = new TestChildNode(leftChild, rightChild);
    TestRootNode rootNode = new TestRootNode(parent);
    CallTarget target = runtime.createCallTarget(rootNode);
    Iterator<Node> iterator = parent.getChildren().iterator();
    Assert.assertEquals(leftChild, iterator.next());
    Assert.assertEquals(rightChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(42, result);
    Assert.assertEquals(4, NodeUtil.countNodes(rootNode));
    Assert.assertEquals(4, NodeUtil.countNodes(NodeUtil.cloneNode(rootNode)));
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 85 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project sulong by graalvm.

the class LLVMParserRuntime method parse.

public static LLVMParserResult parse(Source source, ExternalLibrary library, BitcodeParserResult parserResult, LLVMLanguage language, LLVMContext context, NodeFactory nodeFactory) {
    ModelModule model = parserResult.getModel();
    TargetDataLayout layout = model.getTargetDataLayout();
    assert layout != null;
    LLVMModelVisitor module = new LLVMModelVisitor();
    model.accept(module);
    DataLayoutConverter.DataSpecConverterImpl targetDataLayout = DataLayoutConverter.getConverter(layout.getDataLayout());
    context.setDataLayoutConverter(targetDataLayout);
    LLVMParserRuntime runtime = new LLVMParserRuntime(source, library, language, context, nodeFactory, module.getAliases());
    runtime.registerFunctions(model);
    LLVMSymbolReadResolver symbolResolver = new LLVMSymbolReadResolver(runtime, runtime.getGlobalFrameDescriptor());
    LLVMExpressionNode[] globals = runtime.createGlobalVariableInitializationNodes(symbolResolver, module.getGlobals());
    RootNode globalVarInits = nodeFactory.createStaticInitsRootNode(runtime, globals);
    RootCallTarget globalVarInitsTarget = Truffle.getRuntime().createCallTarget(globalVarInits);
    LLVMExpressionNode[] deallocs = runtime.getDeallocations();
    RootNode globalVarDeallocs = nodeFactory.createStaticInitsRootNode(runtime, deallocs);
    RootCallTarget globalVarDeallocsTarget = Truffle.getRuntime().createCallTarget(globalVarDeallocs);
    RootCallTarget constructorFunctions = runtime.getConstructors(module.getGlobals());
    RootCallTarget destructorFunctions = runtime.getDestructors(module.getGlobals());
    if (context.getEnv().getOptions().get(SulongEngineOption.ENABLE_LVI)) {
        final LLVMSourceContext sourceContext = context.getSourceContext();
        model.getSourceGlobals().forEach((symbol, irValue) -> {
            final LLVMExpressionNode node = symbolResolver.resolve(irValue);
            final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
            sourceContext.registerStatic(symbol, value);
        });
        model.getSourceStaticMembers().forEach(((type, symbol) -> {
            final LLVMExpressionNode node = symbolResolver.resolve(symbol);
            final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
            type.setValue(value);
        }));
    }
    RootCallTarget mainFunctionCallTarget = null;
    if (runtime.getScope().functionExists("@main")) {
        LLVMFunctionDescriptor mainDescriptor = runtime.getScope().getFunctionDescriptor("@main");
        LLVMFunctionDescriptor startDescriptor = runtime.getScope().getFunctionDescriptor("@_start");
        RootCallTarget startCallTarget = startDescriptor.getLLVMIRFunction();
        String applicationPath = source.getPath() == null ? "" : source.getPath().toString();
        RootNode globalFunction = nodeFactory.createGlobalRootNode(runtime, startCallTarget, mainDescriptor, applicationPath);
        RootCallTarget globalFunctionRoot = Truffle.getRuntime().createCallTarget(globalFunction);
        RootNode globalRootNode = nodeFactory.createGlobalRootNodeWrapping(runtime, globalFunctionRoot, startDescriptor.getType().getReturnType());
        mainFunctionCallTarget = Truffle.getRuntime().createCallTarget(globalRootNode);
    }
    return new LLVMParserResult(runtime.getScope(), mainFunctionCallTarget, globalVarInitsTarget, globalVarDeallocsTarget, constructorFunctions, destructorFunctions);
}
Also used : GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) DataLayoutConverter(com.oracle.truffle.llvm.runtime.datalayout.DataLayoutConverter) GlobalConstant(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) RootCallTarget(com.oracle.truffle.api.RootCallTarget) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) Pair(com.oracle.truffle.llvm.parser.util.Pair) Linkage(com.oracle.truffle.llvm.parser.model.enums.Linkage) LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) SulongEngineOption(com.oracle.truffle.llvm.runtime.options.SulongEngineOption) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ArrayList(java.util.ArrayList) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) Type(com.oracle.truffle.llvm.runtime.types.Type) ModelModule(com.oracle.truffle.llvm.parser.model.ModelModule) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext) LLVMLanguage(com.oracle.truffle.llvm.runtime.LLVMLanguage) Map(java.util.Map) RootNode(com.oracle.truffle.api.nodes.RootNode) ArrayConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.ArrayConstant) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) TargetDataLayout(com.oracle.truffle.llvm.parser.model.target.TargetDataLayout) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMScope(com.oracle.truffle.llvm.runtime.LLVMScope) List(java.util.List) Source(com.oracle.truffle.api.source.Source) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) StructureConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.StructureConstant) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) Truffle(com.oracle.truffle.api.Truffle) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Comparator(java.util.Comparator) RootNode(com.oracle.truffle.api.nodes.RootNode) TargetDataLayout(com.oracle.truffle.llvm.parser.model.target.TargetDataLayout) DataLayoutConverter(com.oracle.truffle.llvm.runtime.datalayout.DataLayoutConverter) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ModelModule(com.oracle.truffle.llvm.parser.model.ModelModule) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) RootCallTarget(com.oracle.truffle.api.RootCallTarget) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext)

Aggregations

RootNode (com.oracle.truffle.api.nodes.RootNode)86 Test (org.junit.Test)36 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)24 Node (com.oracle.truffle.api.nodes.Node)23 CallTarget (com.oracle.truffle.api.CallTarget)16 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)16 RootCallTarget (com.oracle.truffle.api.RootCallTarget)12 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)12 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)9 Source (com.oracle.truffle.api.source.Source)8 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)8 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 ArrayList (java.util.ArrayList)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)3