Search in sources :

Example 21 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class ParserDriver method verifyBitcodeSource.

private void verifyBitcodeSource(Source source, DataLayout targetDataLayout, TargetTriple targetTriple) {
    if (targetDataLayout.getByteOrder() != ByteOrder.LITTLE_ENDIAN) {
        throw new LLVMParserException("Byte order " + targetDataLayout.getByteOrder() + " of file " + source.getPath() + " is not supported");
    }
    boolean verifyBitcode = context.getEnv().getOptions().get(SulongEngineOption.VERIFY_BITCODE);
    TargetTriple defaultTargetTriple = language.getDefaultTargetTriple();
    if (defaultTargetTriple == null && !context.isInternalLibraryPath(Paths.get(source.getPath()))) {
        // some internal libraries (libsulong++) might be loaded before libsulong
        throw new IllegalStateException("No default target triple.");
    }
    if (defaultTargetTriple != null && targetTriple != null && !defaultTargetTriple.matches(targetTriple)) {
        TruffleLogger logger = TruffleLogger.getLogger(LLVMLanguage.ID, "BitcodeVerifier");
        String exceptionMessage = "Mismatching target triple (expected " + defaultTargetTriple + ", got " + targetTriple + ')';
        logger.severe(exceptionMessage);
        logger.severe("Source " + source.getPath());
        logger.severe("See https://www.graalvm.org/reference-manual/llvm/Compiling/ for more details");
        logger.severe("To silence this message, set --log." + logger.getName() + ".level=OFF");
        if (verifyBitcode) {
            logger.severe("To make this error non-fatal, set --" + SulongEngineOption.VERIFY_BITCODE_NAME + "=false");
            throw new LLVMParserException(exceptionMessage);
        }
    }
}
Also used : TruffleLogger(com.oracle.truffle.api.TruffleLogger) TargetTriple(com.oracle.truffle.llvm.runtime.target.TargetTriple) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 22 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(CallInstruction call) {
    final Type targetType = call.getType();
    int argumentCount = getArgumentCount(call.getArgumentCount(), targetType);
    final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[argumentCount];
    final TypeArrayBuilder argTypes = new TypeArrayBuilder(argumentCount);
    int argIndex = 0;
    // stack pointer
    argNodes[argIndex] = nodeFactory.createGetStackFromFrame();
    argTypes.set(argIndex, new PointerType(null));
    argIndex++;
    if (targetType instanceof StructureType) {
        argTypes.set(argIndex, new PointerType(targetType));
        argNodes[argIndex] = nodeFactory.createGetUniqueStackSpace(targetType, uniquesRegion);
        argIndex++;
    }
    // realArgumentCount = argumentCount - varArgCount
    int realArgumentCount = call.getCallTarget().getType() instanceof FunctionType ? ((FunctionType) call.getCallTarget().getType()).getNumberOfArguments() : argumentCount;
    final SymbolImpl target = call.getCallTarget();
    for (int i = call.getArgumentCount() - 1; i >= 0; i--) {
        argNodes[argIndex + i] = resolveOptimized(call.getArgument(i), i, target, call.getArguments());
        argTypes.set(argIndex + i, call.getArgument(i).getType());
        boolean isVarArg = i >= realArgumentCount;
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        if (isByValue(paramAttr)) {
            argNodes[argIndex + i] = capsuleAddressByValue(argNodes[argIndex + i], argTypes.get(argIndex + i), paramAttr);
        } else if (isVarArg && isArrayByValue(argTypes.get(argIndex + i), argNodes[argIndex + i])) {
            argNodes[argIndex + i] = capsuleArrayByValue(argNodes[argIndex + i], argTypes.get(argIndex + i));
        }
    }
    LLVMExpressionNode result = nodeFactory.createLLVMBuiltin(target, argNodes, argTypes, argCount);
    if (call.getOperandBundle() != null && !(result instanceof LLVMAssume)) {
        throw new LLVMParserException("Unsupported operand bundle on call of " + target.toString());
    }
    SourceInstrumentationStrategy intent = SourceInstrumentationStrategy.ONLY_FIRST_STATEMENT_ON_LOCATION;
    if (result == null) {
        if (target instanceof InlineAsmConstant) {
            final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
            result = createInlineAssemblerNode(inlineAsmConstant, argNodes, argTypes, targetType);
        } else {
            LLVMExpressionNode function = symbols.resolve(target);
            result = CommonNodeFactory.createFunctionCall(function, argNodes, new FunctionType(targetType, argTypes, false));
            // the callNode needs to be instrumentable so that the debugger can see the CallTag.
            // If it did not provide a source location, the debugger may not be able to show the
            // node on the call stack or offer stepping into the call.
            intent = SourceInstrumentationStrategy.FORCED;
        }
    }
    // the SourceSection references the call, not the return value assignment
    createFrameWrite(result, call, intent);
}
Also used : FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) 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) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) TypeArrayBuilder(com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMAssume(com.oracle.truffle.llvm.runtime.nodes.intrinsics.llvm.LLVMAssume) InlineAsmConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.InlineAsmConstant) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 23 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException 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 24 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class BasicNodeFactory method getCompareOp.

private static CompareOperator getCompareOp(LLVMExpressionNode expr) {
    LLVMMetaLiteralNode meta = (LLVMMetaLiteralNode) expr;
    String op = (String) meta.getMetadata();
    switch(op) {
        case "oeq":
            return CompareOperator.FP_ORDERED_EQUAL;
        case "ogt":
            return CompareOperator.FP_ORDERED_GREATER_THAN;
        case "oge":
            return CompareOperator.FP_ORDERED_GREATER_OR_EQUAL;
        case "olt":
            return CompareOperator.FP_ORDERED_LESS_THAN;
        case "ole":
            return CompareOperator.FP_ORDERED_LESS_OR_EQUAL;
        case "one":
            return CompareOperator.FP_ORDERED_NOT_EQUAL;
        case "ord":
            return CompareOperator.FP_ORDERED;
        case "ueq":
            return CompareOperator.FP_UNORDERED_EQUAL;
        case "ugt":
            return CompareOperator.FP_UNORDERED_GREATER_THAN;
        case "uge":
            return CompareOperator.FP_UNORDERED_GREATER_OR_EQUAL;
        case "ult":
            return CompareOperator.FP_UNORDERED_LESS_THAN;
        case "ule":
            return CompareOperator.FP_UNORDERED_LESS_OR_EQUAL;
        case "une":
            return CompareOperator.FP_UNORDERED_NOT_EQUAL;
        case "uno":
            return CompareOperator.FP_UNORDERED;
        default:
            throw new LLVMParserException("unsupported fp compare op: " + op);
    }
}
Also used : LLVMMetaLiteralNode(com.oracle.truffle.llvm.runtime.nodes.literals.LLVMMetaLiteralNode) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 25 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class ParameterAttributes method decodeGroupCodeEntry.

private void decodeGroupCodeEntry(RecordBuffer buffer) {
    final long groupId = buffer.read();
    final long paramIdx = buffer.read();
    AttributesGroup group = new AttributesGroup(groupId, paramIdx);
    attributes.add(group);
    while (buffer.remaining() > 0) {
        int type = buffer.readInt();
        switch(type) {
            case WELL_KNOWN_ATTRIBUTE_KIND:
                {
                    Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
                    group.addAttribute(new Attribute.KnownAttribute(attr));
                    break;
                }
            case WELL_KNOWN_INTEGER_ATTRIBUTE_KIND:
                {
                    Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
                    group.addAttribute(new Attribute.KnownIntegerValueAttribute(attr, buffer.read()));
                    break;
                }
            case STRING_ATTRIBUTE_KIND:
                {
                    String strAttr = readString(buffer);
                    group.addAttribute(new Attribute.StringAttribute(strAttr));
                    break;
                }
            case STRING_VALUE_ATTRIBUTE_KIND:
                {
                    String strAttr = readString(buffer);
                    String strVal = readString(buffer);
                    group.addAttribute(new Attribute.StringValueAttribute(strAttr, strVal));
                    break;
                }
            case BYVAL_ATTRIBUTE_KIND:
                {
                    Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
                    if (attr == Attribute.Kind.BYVAL) {
                        group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.BYVAL));
                    }
                    break;
                }
            case TYPED_BYVAL_ATTRIBUTE_KIND:
                {
                    Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
                    if (attr == Attribute.Kind.BYVAL) {
                        final Type valueType = types.get(buffer.read());
                        group.addAttribute(new Attribute.KnownTypedAttribute(Attribute.Kind.BYVAL, valueType));
                    } else if (attr == Attribute.Kind.SRET) {
                        final Type retType = types.get(buffer.read());
                        group.addAttribute(new Attribute.KnownTypedAttribute(Attribute.Kind.SRET, retType));
                    }
                    break;
                }
            default:
                throw new LLVMParserException("Unexpected code of attribute group: " + type);
        }
    }
}
Also used : Attribute(com.oracle.truffle.llvm.parser.model.attributes.Attribute) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Aggregations

LLVMParserException (com.oracle.truffle.llvm.runtime.except.LLVMParserException)32 Type (com.oracle.truffle.llvm.runtime.types.Type)12 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)11 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)10 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)10 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)9 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)9 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)6 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)6 ArrayList (java.util.ArrayList)6 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)5 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)5 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)4 TypeArrayBuilder (com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder)3 Matcher (java.util.regex.Matcher)3 CallTarget (com.oracle.truffle.api.CallTarget)2 TruffleFile (com.oracle.truffle.api.TruffleFile)2