Search in sources :

Example 61 with Type

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

the class BasicNodeFactory method createArrayLiteral.

@Override
public LLVMExpressionNode createArrayLiteral(LLVMParserRuntime runtime, List<LLVMExpressionNode> arrayValues, ArrayType arrayType) {
    assert arrayType.getNumberOfElements() == arrayValues.size();
    LLVMExpressionNode arrayAlloc = createAlloca(runtime, arrayType);
    int nrElements = arrayValues.size();
    Type elementType = arrayType.getElementType();
    int elementSize = runtime.getContext().getByteSize(elementType);
    if (elementSize == 0) {
        throw new AssertionError(elementType + " has size of 0!");
    }
    if (elementType instanceof PrimitiveType) {
        switch(((PrimitiveType) elementType).getPrimitiveKind()) {
            case I8:
                return LLVMI8ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case I16:
                return LLVMI16ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case I32:
                return LLVMI32ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case I64:
                return LLVMI64ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case FLOAT:
                return LLVMFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case DOUBLE:
                return LLVMDoubleArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            case X86_FP80:
                return LLVM80BitFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
            default:
                throw new AssertionError(elementType);
        }
    } else if (Type.isFunctionOrFunctionPointer(elementType)) {
        return LLVMFunctionArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
    } else if (elementType instanceof PointerType) {
        return LLVMAddressArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
    } else if (elementType instanceof ArrayType || elementType instanceof StructureType) {
        return LLVMStructArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), createMemMove(), elementSize, arrayAlloc);
    }
    throw new AssertionError(elementType);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Example 62 with Type

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

Example 63 with Type

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(ExtractValueInstruction extract) {
    if (!(extract.getAggregate().getType() instanceof ArrayType || extract.getAggregate().getType() instanceof StructureType || extract.getAggregate().getType() instanceof PointerType)) {
        throw new IllegalStateException("\'extractvalue\' can only extract elements of arrays and structs!");
    }
    final LLVMExpressionNode baseAddress = symbols.resolve(extract.getAggregate());
    final Type baseType = extract.getAggregate().getType();
    final int targetIndex = extract.getIndex();
    final Type resultType = extract.getType();
    LLVMExpressionNode targetAddress = baseAddress;
    final AggregateType aggregateType = (AggregateType) baseType;
    long offset = runtime.getContext().getIndexOffset(targetIndex, aggregateType);
    final Type targetType = aggregateType.getElementType(targetIndex);
    if (targetType != null && !((targetType instanceof StructureType) && (((StructureType) targetType).isPacked()))) {
        offset += runtime.getContext().getBytePadding(offset, targetType);
    }
    if (offset != 0) {
        final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(runtime, 1, PrimitiveType.I32);
        targetAddress = nodeFactory.createTypedElementPointer(runtime, targetAddress, oneLiteralNode, offset, extract.getType());
    }
    final LLVMExpressionNode result = nodeFactory.createExtractValue(runtime, resultType, targetAddress);
    createFrameWrite(result, extract);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType)

Example 64 with Type

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(CompareExchangeInstruction cmpxchg) {
    final LLVMExpressionNode ptrNode = symbols.resolve(cmpxchg.getPtr());
    final LLVMExpressionNode cmpNode = symbols.resolve(cmpxchg.getCmp());
    final LLVMExpressionNode newNode = symbols.resolve(cmpxchg.getReplace());
    final Type elementType = cmpxchg.getCmp().getType();
    createFrameWrite(nodeFactory.createCompareExchangeInstruction(runtime, cmpxchg.getType(), elementType, ptrNode, cmpNode, newNode), cmpxchg);
}
Also used : LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Example 65 with Type

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

the class LLVMBitcodeInstructionVisitor method convertToPhiWriteNodes.

private LLVMExpressionNode[] convertToPhiWriteNodes(ArrayList<Phi>[] phisPerSuccessor) {
    if (phisPerSuccessor.length == 0) {
        return LLVMExpressionNode.NO_EXPRESSIONS;
    }
    LLVMExpressionNode[] result = new LLVMExpressionNode[phisPerSuccessor.length];
    for (int i = 0; i < result.length; i++) {
        LLVMExpressionNode[] from = new LLVMExpressionNode[phisPerSuccessor[i].size()];
        FrameSlot[] to = new FrameSlot[phisPerSuccessor[i].size()];
        Type[] types = new Type[phisPerSuccessor[i].size()];
        for (int j = 0; j < phisPerSuccessor[i].size(); j++) {
            Phi phi = phisPerSuccessor[i].get(j);
            to[j] = getSlot(phi.getPhiValue().getName());
            from[j] = symbols.resolve(phi.getValue());
            types[j] = phi.getValue().getType();
        }
        result[i] = nodeFactory.createPhi(runtime, from, to, types);
    }
    return result;
}
Also used : Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Aggregations

Type (com.oracle.truffle.llvm.runtime.types.Type)76 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)68 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)64 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)63 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)57 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)54 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)50 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)43 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)33 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)32 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)28 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)28 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)13 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)9 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)8 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)8 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType)6 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)6 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)5 LLVMUnsupportedInlineAssemblerNode (com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)5