Search in sources :

Example 1 with LLVMFunctionDescriptor

use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.

the class LLVMParserRuntime method registerFunctionAlias.

private void registerFunctionAlias(GlobalAlias alias, FunctionDefinition existingFunction) {
    LLVMFunctionDescriptor existingDescriptor = scope.getFunctionDescriptor(existingFunction.getName());
    LLVMFunctionDescriptor aliasDescriptor = scope.lookupOrCreateFunction(context, alias.getName(), !Linkage.isFileLocal(alias.getLinkage()), index -> LLVMFunctionDescriptor.createDescriptor(context, library, alias.getName(), existingFunction.getType(), index));
    boolean replaceExistingFunction = checkReplaceExistingFunction(aliasDescriptor);
    aliasDescriptor.declareInSulong(existingDescriptor.getFunction(), Linkage.isWeak(alias.getLinkage()), replaceExistingFunction);
}
Also used : LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)

Example 2 with LLVMFunctionDescriptor

use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.

the class LLVMParserRuntime method checkReplaceExistingFunction.

private boolean checkReplaceExistingFunction(LLVMFunctionDescriptor functionDescriptor) {
    if (library.getLibrariesToReplace() != null) {
        for (ExternalLibrary lib : library.getLibrariesToReplace()) {
            if (functionDescriptor.getLibrary().equals(lib)) {
                // We already have a symbol defined in another library but now we are
                // overwriting it. We rename the already existing symbol by prefixing it with
                // "__libName_", e.g., "@__clock_gettime" would be renamed to
                // "@__libc___clock_gettime".
                String functionName = functionDescriptor.getName();
                assert functionName.charAt(0) == '@';
                String renamedFunctionName = "@__" + functionDescriptor.getLibrary().getName() + "_" + functionName.substring(1);
                LLVMFunctionDescriptor renamedFunctionDescriptor = scope.lookupOrCreateFunction(functionDescriptor.getContext(), renamedFunctionName, true, index -> LLVMFunctionDescriptor.createDescriptor(functionDescriptor.getContext(), functionDescriptor.getLibrary(), renamedFunctionName, functionDescriptor.getType(), index));
                renamedFunctionDescriptor.declareInSulong(functionDescriptor.getFunction(), functionDescriptor.isWeak(), false);
                functionDescriptor.setLibrary(library);
                return true;
            }
        }
    }
    return false;
}
Also used : ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)

Example 3 with LLVMFunctionDescriptor

use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.

the class LLVMFunctionArrayLiteralNode method handleTruffleObject.

@Specialization(guards = "array.isManaged()")
@ExplodeLoop
protected LLVMTruffleObject handleTruffleObject(VirtualFrame frame, LLVMTruffleObject array, @Cached("createForeignWrites()") LLVMForeignWriteNode[] foreignWrites) {
    LLVMTruffleObject currentPtr = array;
    for (int i = 0; i < values.length; i++) {
        try {
            LLVMFunctionDescriptor currentValue = (LLVMFunctionDescriptor) values[i].executeTruffleObject(frame);
            foreignWrites[i].execute(currentPtr, currentValue);
            currentPtr = currentPtr.increment(stride);
        } catch (UnexpectedResultException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
    }
    return array;
}
Also used : UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 4 with LLVMFunctionDescriptor

use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.

the class LLVMFunctionArrayLiteralNode method handleAddress.

@Specialization
@ExplodeLoop
protected LLVMAddress handleAddress(VirtualFrame frame, LLVMAddress array, @Cached("createToNativeWithTarget()") LLVMToNativeNode toNative, @Cached("getLLVMMemory()") LLVMMemory memory) {
    long currentPtr = array.getVal();
    for (int i = 0; i < values.length; i++) {
        try {
            LLVMFunctionDescriptor currentValue = (LLVMFunctionDescriptor) values[i].executeTruffleObject(frame);
            memory.putFunctionPointer(currentPtr, toNative.executeWithTarget(currentValue).getVal());
            currentPtr += stride;
        } catch (UnexpectedResultException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
    }
    return array;
}
Also used : UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 5 with LLVMFunctionDescriptor

use of com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor in project sulong by graalvm.

the class BasicNodeFactory method createInlineAssemblerExpression.

@Override
public LLVMExpressionNode createInlineAssemblerExpression(LLVMParserRuntime runtime, String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type[] argTypes, Type retType, LLVMSourceLocation sourceSection) {
    Type[] retTypes = null;
    int[] retOffsets = null;
    if (retType instanceof StructureType) {
        // multiple out values
        assert args[1] instanceof LLVMAllocaConstInstruction;
        LLVMAllocaConstInstruction alloca = (LLVMAllocaConstInstruction) args[1];
        retTypes = alloca.getTypes();
        retOffsets = alloca.getOffsets();
    }
    Parser asmParser = new Parser(runtime.getLanguage(), sourceSection, asmExpression, asmFlags, argTypes, retType, retTypes, retOffsets);
    LLVMInlineAssemblyRootNode assemblyRoot = asmParser.Parse();
    LLVMFunctionDescriptor asm = LLVMFunctionDescriptor.createDescriptor(runtime.getContext(), runtime.getLibrary(), "<asm>", new FunctionType(MetaType.UNKNOWN, new Type[0], false), -1);
    asm.declareInSulong(Truffle.getRuntime().createCallTarget(assemblyRoot), false);
    LLVMFunctionLiteralNode asmFunction = LLVMFunctionLiteralNodeGen.create(asm);
    return new LLVMCallNode(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, sourceSection);
}
Also used : LLVMInlineAssemblyRootNode(com.oracle.truffle.llvm.nodes.func.LLVMInlineAssemblyRootNode) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) 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) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) LLVMCallNode(com.oracle.truffle.llvm.nodes.func.LLVMCallNode) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMFunctionLiteralNode(com.oracle.truffle.llvm.nodes.literals.LLVMFunctionLiteralNode) LLVMAllocaConstInstruction(com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction) Parser(com.oracle.truffle.llvm.asm.amd64.Parser)

Aggregations

LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)7 Specialization (com.oracle.truffle.api.dsl.Specialization)2 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)2 ExternalLibrary (com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary)2 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)2 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)2 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)2 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)2 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)2 Type (com.oracle.truffle.llvm.runtime.types.Type)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 Truffle (com.oracle.truffle.api.Truffle)1 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 Source (com.oracle.truffle.api.source.Source)1 Parser (com.oracle.truffle.llvm.asm.amd64.Parser)1 LLVMCallNode (com.oracle.truffle.llvm.nodes.func.LLVMCallNode)1 LLVMInlineAssemblyRootNode (com.oracle.truffle.llvm.nodes.func.LLVMInlineAssemblyRootNode)1 LLVMFunctionLiteralNode (com.oracle.truffle.llvm.nodes.literals.LLVMFunctionLiteralNode)1