Search in sources :

Example 1 with LLVMFunction

use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.

the class LLVMTruffleDecorateFunction method registerRoot.

private static Object registerRoot(String path, FunctionType newFunctionType, DecoratedRoot decoratedRoot) {
    LLVMIRFunction function = new LLVMIRFunction(decoratedRoot.getCallTarget(), null);
    LLVMFunction functionDetail = LLVMFunction.create("<wrapper>", function, newFunctionType, IDGenerater.INVALID_ID, LLVMSymbol.INVALID_INDEX, false, path, false);
    LLVMFunctionDescriptor wrappedFunction = new LLVMFunctionDescriptor(functionDetail, new LLVMFunctionCode(functionDetail));
    return LLVMManagedPointer.create(wrappedFunction);
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMIRFunction(com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LLVMIRFunction) LLVMFunctionCode(com.oracle.truffle.llvm.runtime.LLVMFunctionCode) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)

Example 2 with LLVMFunction

use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.

the class LLVMInteropNonvirtualCallNode method doResolve.

/**
 * @param receiver
 * @param method
 */
@Specialization
@GenerateAOT.Exclude
Object doResolve(LLVMPointer receiver, LLVMInteropType.Clazz type, String methodName, Method method, Object[] arguments, @Cached LLVMDynAccessSymbolNode dynAccessSymbolNode, @CachedLibrary(limit = "5") InteropLibrary interop, @Cached BranchProfile notFound) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
    Method newMethod = type.findMethodByArgumentsWithSelf(methodName, arguments);
    LLVMFunction newLLVMFunction = getLLVMFunction(newMethod, type, notFound);
    Object newReceiver = dynAccessSymbolNode.execute(newLLVMFunction);
    return interop.execute(newReceiver, arguments);
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) Method(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Method) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 3 with LLVMFunction

use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.

the class ParserDriver method createNewFunction.

private static void createNewFunction(LLVMScope scope, String originalName, LLVMParserResult parserResult, FunctionSymbol external, String lib, String name, ListIterator<FunctionSymbol> it) {
    LLVMFunction originalSymbol = scope.getFunction(originalName);
    if (originalSymbol == null) {
        throw new LLVMLinkerException(String.format("The symbol %s could not be imported because the symbol %s was not found in library %s", external.getName(), originalName, lib));
    }
    LLVMFunction newFunction = LLVMFunction.create(name, originalSymbol.getFunction(), originalSymbol.getType(), parserResult.getRuntime().getBitcodeID(), external.getIndex(), external.isExported(), parserResult.getRuntime().getFile().getPath(), external.isExternalWeak());
    parserResult.getRuntime().getFileScope().register(newFunction);
    if (external.isExported()) {
        parserResult.getRuntime().getPublicFileScope().register(newFunction);
    }
    it.remove();
    parserResult.getDefinedFunctions().add(external);
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

Example 4 with LLVMFunction

use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.

the class LoadModulesNode method execute.

@Override
public Object execute(VirtualFrame frame) {
    LLVMContext context = getContext();
    synchronized (context) {
        if (!hasInitialised) {
            CompilerDirectives.transferToInterpreterAndInvalidate();
            LLVMFunction mainFunction = findMainFunction();
            if (mainFunction != null) {
                main = new CachedMainFunction(mainFunction);
            } else {
                main = null;
            }
            initContext = this.insert(language.createInitializeContextNode());
            hasInitialised = true;
        }
        LLVMScopeChain firstScopeChain = loadModule(frame, context);
        context.addSourceForCache(bitcodeID, source);
        context.addCalltargetForCache(libraryName, this.getCallTarget());
        // Only the root library (not a dependency) will have a non-null scope.
        if (firstScopeChain != null) {
            SulongLibrary library = new SulongLibrary(this.libraryName, firstScopeChain, main, context, parserRuntime.getLocator(), parserRuntime.getBitcodeID());
            if (main != null) {
                context.setMainLibrary(library);
            }
            return library;
        }
    }
    return null;
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMScopeChain(com.oracle.truffle.llvm.runtime.LLVMScopeChain) SulongLibrary(com.oracle.truffle.llvm.runtime.SulongLibrary) CachedMainFunction(com.oracle.truffle.llvm.runtime.SulongLibrary.CachedMainFunction)

Example 5 with LLVMFunction

use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.

the class BasicNodeFactory method createInlineAssemblerExpression.

@Override
public LLVMExpressionNode createInlineAssemblerExpression(String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type.TypeArrayBuilder argTypes, Type retType) {
    Type[] retTypes = null;
    long[] retOffsets = null;
    if (retType instanceof StructureType) {
        // multiple out values
        StructureType struct = (StructureType) retType;
        retOffsets = new long[struct.getNumberOfElementsInt()];
        retTypes = new Type[struct.getNumberOfElementsInt()];
        long currentOffset = 0;
        try {
            for (int i = 0; i < struct.getNumberOfElements(); i++) {
                Type elemType = struct.getElementType(i);
                if (!struct.isPacked()) {
                    currentOffset = Type.addUnsignedExact(currentOffset, getBytePadding(currentOffset, elemType));
                }
                retOffsets[i] = currentOffset;
                retTypes[i] = elemType;
                currentOffset = Type.addUnsignedExact(currentOffset, getByteSize(elemType));
            }
            assert currentOffset <= getByteSize(retType) : "currentOffset " + currentOffset + " vs. byteSize " + getByteSize(retType);
        } catch (TypeOverflowException e) {
            return Type.handleOverflowExpression(e);
        }
    }
    LLVMInlineAssemblyRootNode assemblyRoot;
    try {
        assemblyRoot = InlineAssemblyParser.parseInlineAssembly(asmExpression, new AsmFactory(language, argTypes, asmFlags, retType, retTypes, retOffsets, this));
    } catch (AsmParseException e) {
        assemblyRoot = getLazyUnsupportedInlineRootNode(asmExpression, e);
    }
    LLVMIRFunction function = new LLVMIRFunction(assemblyRoot.getCallTarget(), null);
    LLVMFunction functionDetail = LLVMFunction.create("<asm>", function, new FunctionType(MetaType.UNKNOWN, 0, false), IDGenerater.INVALID_ID, LLVMSymbol.INVALID_INDEX, false, assemblyRoot.getName(), false);
    // The function descriptor for the inline assembly does not require a language.
    LLVMFunctionDescriptor asm = new LLVMFunctionDescriptor(functionDetail, new LLVMFunctionCode(functionDetail));
    LLVMManagedPointerLiteralNode asmFunction = LLVMManagedPointerLiteralNodeGen.create(LLVMManagedPointer.create(asm));
    return LLVMCallNode.create(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, false);
}
Also used : LLVMInlineAssemblyRootNode(com.oracle.truffle.llvm.runtime.nodes.func.LLVMInlineAssemblyRootNode) LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMIRFunction(com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LLVMIRFunction) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) AsmFactory(com.oracle.truffle.llvm.asm.amd64.AsmFactory) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) AsmParseException(com.oracle.truffle.llvm.asm.amd64.AsmParseException) LLVMManagedPointerLiteralNode(com.oracle.truffle.llvm.runtime.nodes.literals.LLVMSimpleLiteralNode.LLVMManagedPointerLiteralNode) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMFunctionCode(com.oracle.truffle.llvm.runtime.LLVMFunctionCode) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)

Aggregations

LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)9 LLVMFunctionCode (com.oracle.truffle.llvm.runtime.LLVMFunctionCode)3 LLVMScopeChain (com.oracle.truffle.llvm.runtime.LLVMScopeChain)3 LLVMIRFunction (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LLVMIRFunction)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)2 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1 AsmFactory (com.oracle.truffle.llvm.asm.amd64.AsmFactory)1 AsmParseException (com.oracle.truffle.llvm.asm.amd64.AsmParseException)1 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 Function (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.Function)1 LazyLLVMIRFunction (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LazyLLVMIRFunction)1 LLVMIntrinsicProvider (com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider)1 LLVMScope (com.oracle.truffle.llvm.runtime.LLVMScope)1 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)1 NativeContextExtension (com.oracle.truffle.llvm.runtime.NativeContextExtension)1 SulongLibrary (com.oracle.truffle.llvm.runtime.SulongLibrary)1 CachedMainFunction (com.oracle.truffle.llvm.runtime.SulongLibrary.CachedMainFunction)1