Search in sources :

Example 1 with ArrayType

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

the class AggregateConstant method fromData.

public static AggregateConstant fromData(Type type, long[] data) {
    final AggregateConstant aggregateConstant;
    final Type elementType;
    if (type instanceof ArrayType) {
        final ArrayType arrayType = (ArrayType) type;
        elementType = arrayType.getElementType();
        aggregateConstant = new ArrayConstant(arrayType, data.length);
    } else if (type instanceof VectorType) {
        final VectorType vectorType = (VectorType) type;
        elementType = vectorType.getElementType();
        aggregateConstant = new VectorConstant((VectorType) type, data.length);
    } else {
        throw new RuntimeException("Cannot create constant from data: " + type);
    }
    for (int i = 0; i < data.length; i++) {
        aggregateConstant.elements[i] = Constant.createFromData(elementType, data[i]);
    }
    return aggregateConstant;
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Type(com.oracle.truffle.llvm.runtime.types.Type) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType)

Example 2 with ArrayType

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(AllocateInstruction allocate) {
    final Type type = allocate.getPointeeType();
    int alignment;
    if (allocate.getAlign() == 0) {
        alignment = runtime.getContext().getByteAlignment(type);
    } else {
        alignment = 1 << (allocate.getAlign() - 1);
    }
    if (alignment == 0) {
        alignment = LLVMStack.NO_ALIGNMENT_REQUIREMENTS;
    }
    final SymbolImpl count = allocate.getCount();
    final LLVMExpressionNode result;
    if (count instanceof NullConstant) {
        result = nodeFactory.createAlloca(runtime, type, alignment);
    } else if (count instanceof IntegerConstant) {
        long numElements = (int) ((IntegerConstant) count).getValue();
        if (numElements == 1) {
            result = nodeFactory.createAlloca(runtime, type, alignment);
        } else {
            assert numElements == (int) numElements;
            ArrayType arrayType = new ArrayType(type, (int) numElements);
            result = nodeFactory.createAlloca(runtime, arrayType, alignment);
        }
    } else {
        LLVMExpressionNode num = symbols.resolve(count);
        result = nodeFactory.createAllocaArray(runtime, type, num, alignment);
    }
    // we never want to step on allocations, only to actual assignments in the source
    createFrameWrite(result, allocate, null);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) 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) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) IntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant)

Example 3 with ArrayType

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

the class Types method record.

@Override
public void record(long id, long[] args) {
    TypesRecord record = TypesRecord.decode(id);
    Type type;
    switch(record) {
        case NUMBER_OF_ENTRIES:
            table = new Type[(int) args[0]];
            return;
        case VOID:
            type = VoidType.INSTANCE;
            break;
        case FLOAT:
            type = PrimitiveType.FLOAT;
            break;
        case DOUBLE:
            type = PrimitiveType.DOUBLE;
            break;
        case LABEL:
            type = MetaType.LABEL;
            break;
        case OPAQUE:
            if (structName != null) {
                type = new OpaqueType(LLVMIdentifier.toLocalIdentifier(structName));
                structName = null;
                module.addGlobalType(type);
            } else {
                type = new OpaqueType();
            }
            break;
        case INTEGER:
            type = Type.getIntegerType((int) args[0]);
            break;
        case POINTER:
            {
                final PointerType pointerType = new PointerType(null);
                setType((int) args[0], pointerType::setPointeeType);
                type = pointerType;
                break;
            }
        case FUNCTION_OLD:
            {
                final FunctionType functionType = new FunctionType(null, toTypes(args, 3, args.length), args[0] != 0);
                setType((int) args[2], functionType::setReturnType);
                type = functionType;
                break;
            }
        case HALF:
            type = PrimitiveType.HALF;
            break;
        case ARRAY:
            {
                final ArrayType arrayType = new ArrayType(null, (int) args[0]);
                setType((int) args[1], arrayType::setElementType);
                type = arrayType;
                break;
            }
        case VECTOR:
            {
                final VectorType vectorType = new VectorType(null, (int) args[0]);
                setType((int) args[1], vectorType::setElementType);
                type = vectorType;
                break;
            }
        case X86_FP80:
            type = PrimitiveType.X86_FP80;
            break;
        case FP128:
            type = PrimitiveType.F128;
            break;
        case PPC_FP128:
            type = PrimitiveType.PPC_FP128;
            break;
        case METADATA:
            type = MetaType.METADATA;
            break;
        case X86_MMX:
            type = MetaType.X86MMX;
            break;
        case STRUCT_NAME:
            {
                structName = Records.toString(args);
                return;
            }
        case STRUCT_ANON:
        case STRUCT_NAMED:
            {
                final boolean isPacked = args[0] != 0;
                final Type[] members = toTypes(args, 1, args.length);
                if (structName != null) {
                    type = new StructureType(LLVMIdentifier.toTypeIdentifier(structName), isPacked, members);
                    structName = null;
                    module.addGlobalType(type);
                } else {
                    type = new StructureType(isPacked, members);
                }
                break;
            }
        case FUNCTION:
            {
                final FunctionType functionType = new FunctionType(null, toTypes(args, 2, args.length), args[0] != 0);
                setType((int) args[1], functionType::setReturnType);
                type = functionType;
                break;
            }
        case TOKEN:
            type = MetaType.TOKEN;
            break;
        default:
            type = MetaType.UNKNOWN;
            break;
    }
    if (table[size] != null) {
        ((UnresolvedType) table[size]).dependent.accept(type);
    }
    table[size++] = type;
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) OpaqueType(com.oracle.truffle.llvm.runtime.types.OpaqueType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) OpaqueType(com.oracle.truffle.llvm.runtime.types.OpaqueType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) TypesRecord(com.oracle.truffle.llvm.parser.records.TypesRecord) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Example 4 with ArrayType

use of com.oracle.truffle.llvm.runtime.types.ArrayType 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 5 with ArrayType

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

Aggregations

ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)7 Type (com.oracle.truffle.llvm.runtime.types.Type)7 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)6 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)6 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)6 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)5 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)4 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)4 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)4 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)3 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)2 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)2 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)2 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)1 NullConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant)1 IntegerConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant)1 TypesRecord (com.oracle.truffle.llvm.parser.records.TypesRecord)1 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType)1 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)1