Search in sources :

Example 1 with AggregateType

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

the class LLVMSymbolReadResolver method resolveElementPointer.

public LLVMExpressionNode resolveElementPointer(SymbolImpl base, List<SymbolImpl> indices) {
    LLVMExpressionNode currentAddress = resolve(base);
    Type currentType = base.getType();
    for (int i = 0, indicesSize = indices.size(); i < indicesSize; i++) {
        final SymbolImpl indexSymbol = indices.get(i);
        final Type indexType = indexSymbol.getType();
        final Long indexInteger = evaluateLongIntegerConstant(indexSymbol);
        if (indexInteger == null) {
            // the index is determined at runtime
            if (currentType instanceof StructureType) {
                // according to http://llvm.org/docs/LangRef.html#getelementptr-instruction
                throw new IllegalStateException("Indices on structs must be constant integers!");
            }
            AggregateType aggregate = (AggregateType) currentType;
            final long indexedTypeLength = runtime.getContext().getIndexOffset(1, aggregate);
            currentType = aggregate.getElementType(1);
            final LLVMExpressionNode indexNode = resolve(indexSymbol);
            currentAddress = runtime.getNodeFactory().createTypedElementPointer(runtime, currentAddress, indexNode, indexedTypeLength, currentType);
        } else {
            // the index is a constant integer
            AggregateType aggregate = (AggregateType) currentType;
            final long addressOffset = runtime.getContext().getIndexOffset(indexInteger, aggregate);
            currentType = aggregate.getElementType(indexInteger);
            // computed by getelementptr even if it is the same as the basepointer
            if (addressOffset != 0 || i == indicesSize - 1) {
                final LLVMExpressionNode indexNode;
                if (indexType == PrimitiveType.I32) {
                    indexNode = runtime.getNodeFactory().createLiteral(runtime, 1, PrimitiveType.I32);
                } else if (indexType == PrimitiveType.I64) {
                    indexNode = runtime.getNodeFactory().createLiteral(runtime, 1L, PrimitiveType.I64);
                } else {
                    throw new AssertionError(indexType);
                }
                currentAddress = runtime.getNodeFactory().createTypedElementPointer(runtime, currentAddress, indexNode, addressOffset, currentType);
            }
        }
    }
    return currentAddress;
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) OpaqueType(com.oracle.truffle.llvm.runtime.types.OpaqueType) 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) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType)

Example 2 with AggregateType

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

the class Function method createExtractValue.

private void createExtractValue(long[] args) {
    int i = 0;
    int aggregate = getIndex(args[i++]);
    Type aggregateType = null;
    if (scope.isValueForwardRef(aggregate)) {
        aggregateType = types.get(args[i++]);
    }
    int index = (int) args[i++];
    if (aggregateType == null) {
        aggregateType = scope.getValueType(aggregate);
    }
    if (i != args.length) {
        throw new UnsupportedOperationException("Multiple indices are not yet supported!");
    }
    final Type elementType = ((AggregateType) aggregateType).getElementType(index);
    emit(ExtractValueInstruction.fromSymbols(scope.getSymbols(), elementType, aggregate, index));
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType)

Example 3 with AggregateType

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

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(InsertValueInstruction insert) {
    if (!(insert.getAggregate().getType() instanceof StructureType || insert.getAggregate().getType() instanceof ArrayType)) {
        throw new IllegalStateException("\'insertvalue\' can only insert values into arrays and structs!");
    }
    final AggregateType sourceType = (AggregateType) insert.getAggregate().getType();
    final LLVMExpressionNode sourceAggregate = symbols.resolve(insert.getAggregate());
    final LLVMExpressionNode valueToInsert = symbols.resolve(insert.getValue());
    final Type valueType = insert.getValue().getType();
    final int targetIndex = insert.getIndex();
    final LLVMExpressionNode resultAggregate = nodeFactory.createAlloca(runtime, sourceType);
    final long offset = runtime.getContext().getIndexOffset(targetIndex, sourceType);
    final LLVMExpressionNode result = nodeFactory.createInsertValue(runtime, resultAggregate, sourceAggregate, runtime.getContext().getByteSize(sourceType), offset, valueToInsert, valueType);
    createFrameWrite(result, insert);
}
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) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType)

Aggregations

AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)4 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)4 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)4 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)4 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)4 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)4 Type (com.oracle.truffle.llvm.runtime.types.Type)4 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)3 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)3 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)3 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)2 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)2 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)1 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)1 OpaqueType (com.oracle.truffle.llvm.runtime.types.OpaqueType)1 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)1