Search in sources :

Example 1 with LLVMInlineAssemblyRootNode

use of com.oracle.truffle.llvm.runtime.nodes.func.LLVMInlineAssemblyRootNode 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 2 with LLVMInlineAssemblyRootNode

use of com.oracle.truffle.llvm.runtime.nodes.func.LLVMInlineAssemblyRootNode in project graal by oracle.

the class BasicNodeFactory method getLazyUnsupportedInlineRootNode.

private LLVMInlineAssemblyRootNode getLazyUnsupportedInlineRootNode(String asmExpression, AsmParseException e) {
    LLVMInlineAssemblyRootNode assemblyRoot;
    String message = asmExpression + ": " + e.getMessage();
    FrameDescriptor.Builder builder = FrameDescriptor.newBuilder();
    addStackSlots(builder);
    assemblyRoot = new LLVMInlineAssemblyRootNode(language, builder.build(), createStackAccess(), Collections.singletonList(LLVMUnsupportedInstructionNode.create(UnsupportedReason.INLINE_ASSEMBLER, message)), Collections.emptyList(), null);
    return assemblyRoot;
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) LLVMInlineAssemblyRootNode(com.oracle.truffle.llvm.runtime.nodes.func.LLVMInlineAssemblyRootNode) Builder(com.oracle.truffle.api.frame.FrameDescriptor.Builder)

Aggregations

LLVMInlineAssemblyRootNode (com.oracle.truffle.llvm.runtime.nodes.func.LLVMInlineAssemblyRootNode)2 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 Builder (com.oracle.truffle.api.frame.FrameDescriptor.Builder)1 AsmFactory (com.oracle.truffle.llvm.asm.amd64.AsmFactory)1 AsmParseException (com.oracle.truffle.llvm.asm.amd64.AsmParseException)1 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)1 LLVMFunctionCode (com.oracle.truffle.llvm.runtime.LLVMFunctionCode)1 LLVMIRFunction (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LLVMIRFunction)1 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)1 LLVMManagedPointerLiteralNode (com.oracle.truffle.llvm.runtime.nodes.literals.LLVMSimpleLiteralNode.LLVMManagedPointerLiteralNode)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 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)1