Search in sources :

Example 6 with TypeOverflowException

use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.

the class CommonNodeFactory method createNestedElementPointerNode.

public static LLVMExpressionNode createNestedElementPointerNode(NodeFactory nodeFactory, DataLayout dataLayout, LLVMExpressionNode[] indexNodes, Long[] indexConstants, Type[] indexTypes, LLVMExpressionNode curAddress, Type curType) {
    try {
        ElementPointerFactory factory = new ElementPointerFactory(nodeFactory, curAddress, curType);
        for (int i = 0; i < indexNodes.length; i++) {
            Type indexType = indexTypes[i];
            Long indexInteger = indexConstants[i];
            if (indexInteger == null) {
                // the index is determined at runtime
                if (factory.currentType instanceof StructureType) {
                    // according to http://llvm.org/docs/LangRef.html#getelementptr-instruction
                    throw new LLVMParserException("Indices on structs must be constant integers!");
                }
                AggregateType aggregate = (AggregateType) factory.currentType;
                long indexedTypeLength = aggregate.getOffsetOf(1, dataLayout);
                factory.currentType = aggregate.getElementType(1);
                factory.addIndex(indexedTypeLength, indexNodes[i], indexType);
            } else {
                // the index is a constant integer
                AggregateType aggregate = (AggregateType) factory.currentType;
                long addressOffset = aggregate.getOffsetOf(indexInteger, dataLayout);
                factory.currentType = aggregate.getElementType(indexInteger);
                // address computed by getelementptr even if it is the same as the basepointer
                if (addressOffset != 0 || i == indexNodes.length - 1) {
                    LLVMExpressionNode indexNode;
                    if (indexType == PrimitiveType.I32) {
                        indexNode = CommonNodeFactory.createLiteral(1, PrimitiveType.I32);
                    } else if (indexType == PrimitiveType.I64) {
                        indexNode = CommonNodeFactory.createLiteral(1L, PrimitiveType.I64);
                    } else {
                        throw new AssertionError(indexType);
                    }
                    factory.addIndex(addressOffset, indexNode, indexType);
                }
            }
        }
        return factory.currentAddress;
    } catch (TypeOverflowException e) {
        return Type.handleOverflowExpression(e);
    }
}
Also used : 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) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) 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) ForeignToLLVMType(com.oracle.truffle.llvm.runtime.interop.convert.ForeignToLLVM.ForeignToLLVMType) Type(com.oracle.truffle.llvm.runtime.types.Type) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 7 with TypeOverflowException

use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.

the class BasicNodeFactory method createPrimitiveArrayLiteral.

@Override
public LLVMExpressionNode createPrimitiveArrayLiteral(Object arrayValues, ArrayType arrayType, GetStackSpaceFactory arrayGetStackSpaceFactory) {
    assert arrayType.getNumberOfElements() == Array.getLength(arrayValues);
    LLVMExpressionNode arrayGetStackSpace = arrayGetStackSpaceFactory.createGetStackSpace(this, arrayType);
    Type elementType = arrayType.getElementType();
    try {
        long elementSize = getByteSize(elementType);
        if (elementSize == 0) {
            throw new TypeOverflowException(elementType + " has size of 0!");
        }
        if (elementType instanceof PrimitiveType) {
            PrimitiveType primitiveType = (PrimitiveType) elementType;
            if (primitiveType.getPrimitiveKind() == PrimitiveKind.I8 && arrayValues instanceof byte[] && elementSize == 1) {
                return LLVMI8ArrayLiteralNodeGen.create((byte[]) arrayValues, arrayGetStackSpace);
            }
        }
    } catch (TypeOverflowException e) {
        return Type.handleOverflowExpression(e);
    }
    throw new AssertionError(elementType);
}
Also used : 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) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 8 with TypeOverflowException

use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(InsertValueInstruction insert) {
    if (!(insert.getAggregate().getType() instanceof StructureType || insert.getAggregate().getType() instanceof ArrayType)) {
        throw new LLVMParserException("\'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.createGetUniqueStackSpace(sourceType, uniquesRegion);
    LLVMExpressionNode result;
    try {
        final long offset = sourceType.getOffsetOf(targetIndex, dataLayout);
        result = nodeFactory.createInsertValue(resultAggregate, sourceAggregate, sourceType.getSize(dataLayout), offset, valueToInsert, valueType);
    } catch (TypeOverflowException e) {
        // FIXME is that the right thing to do?
        result = Type.handleOverflowExpression(e);
    }
    createFrameWrite(result, insert);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 9 with TypeOverflowException

use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method capsuleAddressByValue.

private LLVMExpressionNode capsuleAddressByValue(LLVMExpressionNode child, Type type, AttributesGroup paramAttr) {
    try {
        final Type pointee = ((PointerType) type).getPointeeType();
        final long size = pointee.getSize(dataLayout);
        int alignment = pointee.getAlignment(dataLayout);
        for (Attribute attr : paramAttr.getAttributes()) {
            if (attr instanceof Attribute.KnownIntegerValueAttribute && ((Attribute.KnownIntegerValueAttribute) attr).getAttr() == Attribute.Kind.ALIGN) {
                alignment = ((Attribute.KnownIntegerValueAttribute) attr).getValue();
            }
        }
        return nodeFactory.createVarArgCompoundValue(size, alignment, type, child);
    } catch (TypeOverflowException e) {
        return Type.handleOverflowExpression(e);
    }
}
Also used : 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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) Attribute(com.oracle.truffle.llvm.parser.model.attributes.Attribute) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException)

Example 10 with TypeOverflowException

use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.

the class LLVMForeignCallNode method execute.

@Override
public Object execute(VirtualFrame frame) {
    Object result;
    LLVMThreadingStack threadingStack = LLVMContext.get(this).getThreadingStack();
    LLVMStack stack = getStack.executeWithTarget(threadingStack, Thread.currentThread());
    try {
        result = doCall(frame, stack);
    } catch (ArityException ex) {
        throw silenceException(RuntimeException.class, ex);
    } catch (TypeOverflowException ex) {
        throw silenceException(RuntimeException.class, ex);
    }
    return prepareValueForEscape.executeWithType(result, returnBaseType);
}
Also used : LLVMThreadingStack(com.oracle.truffle.llvm.runtime.memory.LLVMThreadingStack) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) ArityException(com.oracle.truffle.api.interop.ArityException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack)

Aggregations

TypeOverflowException (com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException)10 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)7 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)7 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)7 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)7 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)7 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)7 Type (com.oracle.truffle.llvm.runtime.types.Type)7 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)6 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)5 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)5 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)3 LLVMParserException (com.oracle.truffle.llvm.runtime.except.LLVMParserException)2 ArityException (com.oracle.truffle.api.interop.ArityException)1 AsmFactory (com.oracle.truffle.llvm.asm.amd64.AsmFactory)1 AsmParseException (com.oracle.truffle.llvm.asm.amd64.AsmParseException)1 LLVMParserRuntime (com.oracle.truffle.llvm.parser.LLVMParserRuntime)1 Attribute (com.oracle.truffle.llvm.parser.model.attributes.Attribute)1 GlobalVariable (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable)1