Search in sources :

Example 1 with LLVMAllocaConstInstruction

use of com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction in project sulong by graalvm.

the class BasicNodeFactory method createAlloca.

protected static LLVMExpressionNode createAlloca(LLVMParserRuntime runtime, Type type, int byteSize, int alignment) {
    if (type instanceof StructureType) {
        StructureType struct = (StructureType) type;
        final int[] offsets = new int[struct.getNumberOfElements()];
        final Type[] types = new Type[struct.getNumberOfElements()];
        int currentOffset = 0;
        for (int i = 0; i < struct.getNumberOfElements(); i++) {
            final Type elemType = struct.getElementType(i);
            if (!struct.isPacked()) {
                currentOffset += runtime.getContext().getBytePadding(currentOffset, elemType);
            }
            offsets[i] = currentOffset;
            types[i] = elemType;
            currentOffset += runtime.getContext().getByteSize(elemType);
        }
        assert currentOffset <= byteSize : "currentOffset " + currentOffset + " vs. byteSize " + byteSize;
        LLVMAllocaConstInstruction alloc = LLVMAllocaConstInstructionNodeGen.create(byteSize, alignment, type);
        alloc.setTypes(types);
        alloc.setOffsets(offsets);
        return alloc;
    }
    return LLVMAllocaConstInstructionNodeGen.create(byteSize, alignment, type);
}
Also used : 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) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMAllocaConstInstruction(com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction)

Example 2 with LLVMAllocaConstInstruction

use of com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction 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

LLVMAllocaConstInstruction (com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction)2 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)2 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)2 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType)2 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)2 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)2 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)2 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)2 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)2 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)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 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)2 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)2 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)2 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