Search in sources :

Example 1 with LLVMFunctionCode

use of com.oracle.truffle.llvm.runtime.LLVMFunctionCode 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 LLVMFunctionCode

use of com.oracle.truffle.llvm.runtime.LLVMFunctionCode 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)

Example 3 with LLVMFunctionCode

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

the class AllocExternalSymbolNode method execute.

public LLVMPointer execute(LLVMScopeChain localScope, LLVMScopeChain globalScope, LLVMIntrinsicProvider intrinsicProvider, NativeContextExtension nativeContextExtension, LLVMContext context, LLVMDLOpen.RTLDFlags rtldFlags, LLVMSymbol symbol) {
    LLVMPointer pointerFromLocal = lookupFromScope(localScope, symbol, context);
    // The default case for active default flag is to search the local scope first.
    if (pointerFromLocal != null && isDefaultFlagActive(rtldFlags)) {
        return pointerFromLocal;
    }
    LLVMPointer pointerFromGlobal = lookupFromScope(globalScope, symbol, context);
    // the default flag, global scope takes priority if the default flag is not active.)
    if (pointerFromGlobal != null) {
        return pointerFromGlobal;
    }
    // flag is not active).
    if (pointerFromLocal != null) {
        return pointerFromLocal;
    }
    // Allocating a native global symbol to the symbol table as provided by the nfi context.
    if (symbol.isGlobalVariable()) {
        if (symbol.isExternalWeak()) {
            return LLVMNativePointer.createNull();
        } else if (nativeContextExtension != null) {
            NativeContextExtension.NativePointerIntoLibrary pointer = getNativePointer(nativeContextExtension, symbol);
            if (pointer != null) {
                return LLVMNativePointer.create(pointer.getAddress());
            }
            return null;
        }
    }
    // native function and intrinsic function.
    if (symbol.isFunction()) {
        if (symbol.isExternalWeak()) {
            return LLVMNativePointer.createNull();
        } else if (intrinsicProvider != null && intrinsicProvider.isIntrinsified(symbol.getName())) {
            LLVMFunctionCode functionCode = new LLVMFunctionCode(symbol.asFunction());
            LLVMFunctionDescriptor functionDescriptor = context.createFunctionDescriptor(symbol.asFunction(), functionCode);
            functionDescriptor.getFunctionCode().define(intrinsicProvider, nodeFactory);
            return LLVMManagedPointer.create(functionDescriptor);
        } else if (intrinsicProvider != null && !intrinsicProvider.isIntrinsified(symbol.getName()) && nativeContextExtension != null) {
            /*
                 * Currently native functions/globals that are not in the nfi context are not
                 * written into the symbol table. For function, another lookup will happen when
                 * something tries to call the function. (see {@link
                 * LLVMDispatchNode#doCachedNative}) The function will be taken from the filescope
                 * directly. Ideally the filescope and symbol table is in sync, and any lazy look up
                 * will resolve from the function code in the symbol table.
                 */
            NativeLookupResult nativeFunction = getNativeFunction(nativeContextExtension, symbol);
            if (nativeFunction != null) {
                LLVMFunctionDescriptor functionDescriptor = context.createFunctionDescriptor(symbol.asFunction(), new LLVMFunctionCode(symbol.asFunction()));
                functionDescriptor.getFunctionCode().define(new LLVMFunctionCode.NativeFunction(nativeFunction.getObject()));
                symbol.asFunction().setNFISymbol(nativeFunction.getObject());
                return LLVMManagedPointer.create(functionDescriptor);
            }
            return null;
        }
    }
    /*
         * Fallback for when the same symbol is being overwritten. There exists code where the
         * symbol is not there.
         */
    return null;
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMFunctionCode(com.oracle.truffle.llvm.runtime.LLVMFunctionCode) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) NativePointerIntoLibrary(com.oracle.truffle.llvm.runtime.NativeContextExtension.NativePointerIntoLibrary) NativeLookupResult(com.oracle.truffle.llvm.runtime.NativeContextExtension.NativeLookupResult)

Aggregations

LLVMFunctionCode (com.oracle.truffle.llvm.runtime.LLVMFunctionCode)3 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)3 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)2 LLVMIRFunction (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LLVMIRFunction)2 AsmFactory (com.oracle.truffle.llvm.asm.amd64.AsmFactory)1 AsmParseException (com.oracle.truffle.llvm.asm.amd64.AsmParseException)1 NativeLookupResult (com.oracle.truffle.llvm.runtime.NativeContextExtension.NativeLookupResult)1 NativePointerIntoLibrary (com.oracle.truffle.llvm.runtime.NativeContextExtension.NativePointerIntoLibrary)1 LLVMInlineAssemblyRootNode (com.oracle.truffle.llvm.runtime.nodes.func.LLVMInlineAssemblyRootNode)1 LLVMManagedPointerLiteralNode (com.oracle.truffle.llvm.runtime.nodes.literals.LLVMSimpleLiteralNode.LLVMManagedPointerLiteralNode)1 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)1 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)1 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)1 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)1 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)1 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)1 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)1 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)1 Type (com.oracle.truffle.llvm.runtime.types.Type)1 TypeOverflowException (com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException)1