Search in sources :

Example 1 with TypeOverflowException

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

the class BasicNodeFactory method createInlineAssemblerExpression.

@Override
public LLVMExpressionNode createInlineAssemblerExpression(String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type.TypeArrayBuilder argTypes, Type retType) {
    Type[] retTypes = null;
    long[] retOffsets = null;
    if (retType instanceof StructureType) {
        // multiple out values
        StructureType struct = (StructureType) retType;
        retOffsets = new long[struct.getNumberOfElementsInt()];
        retTypes = new Type[struct.getNumberOfElementsInt()];
        long currentOffset = 0;
        try {
            for (int i = 0; i < struct.getNumberOfElements(); i++) {
                Type elemType = struct.getElementType(i);
                if (!struct.isPacked()) {
                    currentOffset = Type.addUnsignedExact(currentOffset, getBytePadding(currentOffset, elemType));
                }
                retOffsets[i] = currentOffset;
                retTypes[i] = elemType;
                currentOffset = Type.addUnsignedExact(currentOffset, getByteSize(elemType));
            }
            assert currentOffset <= getByteSize(retType) : "currentOffset " + currentOffset + " vs. byteSize " + getByteSize(retType);
        } catch (TypeOverflowException e) {
            return Type.handleOverflowExpression(e);
        }
    }
    LLVMInlineAssemblyRootNode assemblyRoot;
    try {
        assemblyRoot = InlineAssemblyParser.parseInlineAssembly(asmExpression, new AsmFactory(language, argTypes, asmFlags, retType, retTypes, retOffsets, this));
    } catch (AsmParseException e) {
        assemblyRoot = getLazyUnsupportedInlineRootNode(asmExpression, e);
    }
    LLVMIRFunction function = new LLVMIRFunction(assemblyRoot.getCallTarget(), null);
    LLVMFunction functionDetail = LLVMFunction.create("<asm>", function, new FunctionType(MetaType.UNKNOWN, 0, false), IDGenerater.INVALID_ID, LLVMSymbol.INVALID_INDEX, false, assemblyRoot.getName(), false);
    // The function descriptor for the inline assembly does not require a language.
    LLVMFunctionDescriptor asm = new LLVMFunctionDescriptor(functionDetail, new LLVMFunctionCode(functionDetail));
    LLVMManagedPointerLiteralNode asmFunction = LLVMManagedPointerLiteralNodeGen.create(LLVMManagedPointer.create(asm));
    return LLVMCallNode.create(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, false);
}
Also used : LLVMInlineAssemblyRootNode(com.oracle.truffle.llvm.runtime.nodes.func.LLVMInlineAssemblyRootNode) LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMIRFunction(com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LLVMIRFunction) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) AsmFactory(com.oracle.truffle.llvm.asm.amd64.AsmFactory) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) AsmParseException(com.oracle.truffle.llvm.asm.amd64.AsmParseException) LLVMManagedPointerLiteralNode(com.oracle.truffle.llvm.runtime.nodes.literals.LLVMSimpleLiteralNode.LLVMManagedPointerLiteralNode) 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) LLVMFunctionCode(com.oracle.truffle.llvm.runtime.LLVMFunctionCode) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)

Example 2 with TypeOverflowException

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

the class BasicNodeFactory method createArrayLiteral.

@Override
public LLVMExpressionNode createArrayLiteral(LLVMExpressionNode[] arrayValues, ArrayType arrayType, GetStackSpaceFactory arrayGetStackSpaceFactory) {
    assert arrayType.getNumberOfElements() == arrayValues.length;
    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 || elementType instanceof PointerType || elementType instanceof FunctionType || elementType instanceof VariableBitWidthType) {
            return LLVMArrayLiteralNodeGen.create(arrayValues, elementSize, createMemoryStore(null, null, elementType), arrayGetStackSpace);
        } else if (elementType instanceof ArrayType || elementType instanceof StructureType) {
            return LLVMStructArrayLiteralNodeGen.create(arrayValues, createMemMove(), elementSize, arrayGetStackSpace);
        }
    } catch (TypeOverflowException e) {
        return Type.handleOverflowExpression(e);
    }
    throw new AssertionError(elementType);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) 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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Example 3 with TypeOverflowException

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

the class InitializeGlobalNode method createGlobalVariableInitializer.

private static StaticInitsNode createGlobalVariableInitializer(LLVMParserResult parserResult, Object moduleName) {
    LLVMParserRuntime runtime = parserResult.getRuntime();
    GetStackSpaceFactory stackFactory = GetStackSpaceFactory.createAllocaFactory();
    List<GlobalVariable> globals = parserResult.getDefinedGlobals();
    DataLayout dataLayout = parserResult.getDataLayout();
    LLVMStatementNode initNode;
    int totalSize = 0;
    try {
        int[] sizes = new int[globals.size()];
        int nonEmptyGlobals = 0;
        for (int i = 0; i < sizes.length; i++) {
            GlobalVariable global = globals.get(i);
            if (global == null || global.getValue() == null) {
                continue;
            }
            long size = globals.get(i).getType().getPointeeType().getSize(dataLayout);
            if (size > Integer.MAX_VALUE || (totalSize + size) > Integer.MAX_VALUE) {
                throw new TypeOverflowException("globals section > 2GB is not supported");
            }
            if (size == 0) {
                continue;
            }
            sizes[i] = (int) size;
            totalSize += (int) size;
            nonEmptyGlobals++;
        }
        int[] bufferOffsets = new int[nonEmptyGlobals];
        LLVMGlobal[] descriptors = new LLVMGlobal[nonEmptyGlobals];
        Buffer buffer = new Buffer(totalSize, runtime, dataLayout);
        int globalIndex = 0;
        totalSize = 0;
        for (int i = 0; i < sizes.length; i++) {
            if (sizes[i] == 0) {
                continue;
            }
            GlobalVariable global = globals.get(i);
            /*
                 * For fetching the address of the global that we want to initialize, we must use
                 * the file scope because we are initializing the globals of the current file.
                 */
            descriptors[globalIndex] = runtime.getFileScope().getGlobalVariable(global.getName());
            assert descriptors[globalIndex] != null;
            bufferOffsets[globalIndex] = totalSize;
            global.getValue().addToBuffer(buffer, runtime, dataLayout, stackFactory);
            totalSize += sizes[i];
            globalIndex++;
        }
        initNode = buffer.createNode(bufferOffsets, descriptors);
    } catch (TypeOverflowException e) {
        initNode = Type.handleOverflowStatement(e);
    }
    return StaticInitsNodeGen.create(new LLVMStatementNode[] { initNode }, "global variable initializers", moduleName);
}
Also used : DataLayout(com.oracle.truffle.llvm.runtime.datalayout.DataLayout) ByteBuffer(java.nio.ByteBuffer) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) LLVMGlobal(com.oracle.truffle.llvm.runtime.global.LLVMGlobal) LLVMParserRuntime(com.oracle.truffle.llvm.parser.LLVMParserRuntime) GetStackSpaceFactory(com.oracle.truffle.llvm.runtime.GetStackSpaceFactory) GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) LLVMStatementNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode)

Example 4 with TypeOverflowException

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

the class BasicNodeFactory method getLLVMBuiltin.

protected LLVMExpressionNode getLLVMBuiltin(FunctionDeclaration declaration, LLVMExpressionNode[] args, int callerArgumentCount) {
    String intrinsicName = declaration.getName();
    try {
        switch(intrinsicName) {
            case "llvm.memset.p0i8.i32":
            case "llvm.memset.p0i8.i64":
                return createMemsetIntrinsic(args);
            case "llvm.assume":
                return LLVMAssumeNodeGen.create(args[1]);
            // STUB
            case "llvm.clear_cache":
            case "llvm.donothing":
                return LLVMNoOpNodeGen.create();
            case "llvm.prefetch":
                return LLVMPrefetchNodeGen.create(args[1], args[2], args[3], args[4]);
            case "llvm.ctlz.i8":
                return CountLeadingZeroesI8NodeGen.create(args[1], args[2]);
            case "llvm.ctlz.i16":
                return CountLeadingZeroesI16NodeGen.create(args[1], args[2]);
            case "llvm.ctlz.i32":
                return CountLeadingZeroesI32NodeGen.create(args[1], args[2]);
            case "llvm.ctlz.i64":
                return CountLeadingZeroesI64NodeGen.create(args[1], args[2]);
            case "llvm.memcpy.p0i8.p0i8.i64":
            case "llvm.memcpy.p0i8.p0i8.i32":
                return createMemcpyIntrinsic(args);
            case "llvm.ctpop.i32":
                return CountSetBitsI32NodeGen.create(args[1]);
            case "llvm.ctpop.i64":
                return CountSetBitsI64NodeGen.create(args[1]);
            case "llvm.cttz.i8":
                return CountTrailingZeroesI8NodeGen.create(args[1], args[2]);
            case "llvm.cttz.i16":
                return CountTrailingZeroesI16NodeGen.create(args[1], args[2]);
            case "llvm.cttz.i32":
                return CountTrailingZeroesI32NodeGen.create(args[1], args[2]);
            case "llvm.cttz.i64":
                return CountTrailingZeroesI64NodeGen.create(args[1], args[2]);
            case "llvm.trap":
                return LLVMTrapNodeGen.create();
            case "llvm.bswap.i16":
                return LLVMByteSwapI16NodeGen.create(args[1]);
            case "llvm.bswap.i32":
                return LLVMByteSwapI32NodeGen.create(args[1]);
            case "llvm.bswap.i64":
                return LLVMByteSwapI64NodeGen.create(args[1]);
            case "llvm.bswap.v8i16":
                return LLVMByteSwapI16VectorNodeGen.create(8, args[1]);
            case "llvm.bswap.v16i16":
                return LLVMByteSwapI16VectorNodeGen.create(16, args[1]);
            case "llvm.bswap.v4i32":
                return LLVMByteSwapI32VectorNodeGen.create(4, args[1]);
            case "llvm.bswap.v8i32":
                return LLVMByteSwapI32VectorNodeGen.create(8, args[1]);
            case "llvm.bswap.v2i64":
                return LLVMByteSwapI64VectorNodeGen.create(2, args[1]);
            case "llvm.bswap.v4i64":
                return LLVMByteSwapI64VectorNodeGen.create(4, args[1]);
            case "llvm.memmove.p0i8.p0i8.i64":
                return createMemmoveIntrinsic(args);
            case "llvm.pow.f32":
                return LLVMPowNodeGen.create(args[1], args[2]);
            case "llvm.pow.f64":
                return LLVMPowNodeGen.create(args[1], args[2]);
            case "llvm.pow.f80":
                return LLVMPowNodeGen.create(args[1], args[2]);
            case "llvm.powi.f32":
                return LLVMPowNodeGen.create(args[1], args[2]);
            case "llvm.powi.f64":
                return LLVMPowNodeGen.create(args[1], args[2]);
            case "llvm.powi.f80":
                return LLVMPowNodeGen.create(args[1], args[2]);
            case "llvm.round.f32":
            case "llvm.round.f64":
            case "llvm.round.f80":
                return LLVMCMathsIntrinsicsFactory.LLVMRoundNodeGen.create(args[1]);
            case "llvm.abs.i8":
            case "llvm.abs.i16":
            case "llvm.abs.i32":
            case "llvm.abs.i64":
                return LLVMAbsNodeGen.create(args[1]);
            case "llvm.fabs.f32":
            case "llvm.fabs.f64":
            case "llvm.fabs.f80":
                return LLVMFAbsNodeGen.create(args[1]);
            case "llvm.fabs.v2f64":
                return LLVMFAbsVectorNodeGen.create(args[1], 2);
            case "llvm.fshl.i8":
                return LLVMFunnelShiftNodeFactory.Fshl_I8NodeGen.create(args[1], args[2], args[3]);
            case "llvm.fshl.i16":
                return LLVMFunnelShiftNodeFactory.Fshl_I16NodeGen.create(args[1], args[2], args[3]);
            case "llvm.fshl.i32":
                return LLVMFunnelShiftNodeFactory.Fshl_I32NodeGen.create(args[1], args[2], args[3]);
            case "llvm.fshl.i64":
                return LLVMFunnelShiftNodeFactory.Fshl_I64NodeGen.create(args[1], args[2], args[3]);
            case "llvm.fshr.i8":
                return LLVMFunnelShiftNodeFactory.Fshr_I8NodeGen.create(args[1], args[2], args[3]);
            case "llvm.fshr.i16":
                return LLVMFunnelShiftNodeFactory.Fshr_I16NodeGen.create(args[1], args[2], args[3]);
            case "llvm.fshr.i32":
                return LLVMFunnelShiftNodeFactory.Fshr_I32NodeGen.create(args[1], args[2], args[3]);
            case "llvm.fshr.i64":
                return LLVMFunnelShiftNodeFactory.Fshr_I64NodeGen.create(args[1], args[2], args[3]);
            case "llvm.minnum.f32":
            case "llvm.minnum.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMMinnumNodeGen.create(args[1], args[2]);
            case "llvm.maxnum.f32":
            case "llvm.maxnum.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMMaxnumNodeGen.create(args[1], args[2]);
            case "llvm.returnaddress":
                return LLVMReturnAddressNodeGen.create(args[1]);
            case "llvm.lifetime.start.p0i8":
            case "llvm.lifetime.start":
                return LLVMLifetimeStartNodeGen.create(args[1], args[2]);
            case "llvm.lifetime.end.p0i8":
            case "llvm.lifetime.end":
                return LLVMLifetimeEndNodeGen.create(args[1], args[2]);
            case "llvm.invariant.start":
            case "llvm.invariant.start.p0i8":
                return LLVMInvariantStartNodeGen.create(args[1], args[2]);
            case "llvm.invariant.end":
            case "llvm.invariant.end.p0i8":
                return LLVMInvariantEndNodeGen.create(args[1], args[2]);
            case "llvm.stacksave":
                return LLVMStackSaveNodeGen.create();
            case "llvm.stackrestore":
                return LLVMStackRestoreNodeGen.create(args[1]);
            case "llvm.frameaddress":
            case "llvm.frameaddress.p0i8":
                return LLVMFrameAddressNodeGen.create(args[1]);
            case "llvm.va_start":
                return LLVMVAStartNodeGen.create(callerArgumentCount, args[1]);
            case "llvm.va_end":
                return LLVMVAEndNodeGen.create(args[1]);
            case "llvm.va_copy":
                return LLVMVACopyNodeGen.create(args[1], args[2], callerArgumentCount);
            case "llvm.eh.sjlj.longjmp":
            case "llvm.eh.sjlj.setjmp":
                return LLVMUnsupportedInstructionNode.createExpression(UnsupportedReason.SET_JMP_LONG_JMP);
            case "llvm.dbg.declare":
            case "llvm.dbg.addr":
            case "llvm.dbg.value":
                throw new IllegalStateException("Unhandled call to intrinsic function " + declaration.getName());
            case "llvm.dbg.label":
                // the other dbg.* intrinsics.
                return LLVMNoOpNodeGen.create();
            case "llvm.eh.typeid.for":
                return LLVMTypeIdForExceptionNodeGen.create(args[1]);
            case "llvm.expect.i1":
                {
                    boolean expectedValue = LLVMTypesGen.asBoolean(args[2].executeGeneric(null));
                    LLVMExpressionNode actualValueNode = args[1];
                    return LLVMExpectI1NodeGen.create(expectedValue, actualValueNode);
                }
            case "llvm.expect.i32":
                {
                    int expectedValue = LLVMTypesGen.asInteger(args[2].executeGeneric(null));
                    LLVMExpressionNode actualValueNode = args[1];
                    return LLVMExpectI32NodeGen.create(expectedValue, actualValueNode);
                }
            case "llvm.expect.i64":
                {
                    long expectedValue = LLVMTypesGen.asLong(args[2].executeGeneric(null));
                    LLVMExpressionNode actualValueNode = args[1];
                    return LLVMExpectI64NodeGen.create(expectedValue, actualValueNode);
                }
            case "llvm.objectsize.i64.p0i8":
            case "llvm.objectsize.i64":
                return LLVMI64ObjectSizeNodeGen.create(args[1], args[2]);
            case "llvm.copysign.f32":
            case "llvm.copysign.f64":
            case "llvm.copysign.f80":
                return LLVMCMathsIntrinsicsFactory.LLVMCopySignNodeGen.create(args[1], args[2]);
            case "llvm.uadd.sat.i8":
            case "llvm.uadd.sat.i16":
            case "llvm.uadd.sat.i32":
            case "llvm.uadd.sat.i64":
                return LLVMSimpleArithmeticPrimitiveNodeGen.create(LLVMArithmetic.UNSIGNED_ADD_SAT, args[1], args[2]);
            case "llvm.usub.sat.i8":
            case "llvm.usub.sat.i16":
            case "llvm.usub.sat.i32":
            case "llvm.usub.sat.i64":
                return LLVMSimpleArithmeticPrimitiveNodeGen.create(LLVMArithmetic.UNSIGNED_SUB_SAT, args[1], args[2]);
            case "llvm.sadd.sat.i8":
            case "llvm.sadd.sat.i16":
            case "llvm.sadd.sat.i32":
            case "llvm.sadd.sat.i64":
                return LLVMSimpleArithmeticPrimitiveNodeGen.create(LLVMArithmetic.SIGNED_ADD_SAT, args[1], args[2]);
            case "llvm.ssub.sat.i8":
            case "llvm.ssub.sat.i16":
            case "llvm.ssub.sat.i32":
            case "llvm.ssub.sat.i64":
                return LLVMSimpleArithmeticPrimitiveNodeGen.create(LLVMArithmetic.SIGNED_SUB_SAT, args[1], args[2]);
            case "llvm.uadd.with.overflow.i8":
            case "llvm.uadd.with.overflow.i16":
            case "llvm.uadd.with.overflow.i32":
            case "llvm.uadd.with.overflow.i64":
                return LLVMArithmeticWithOverflowNodeGen.create(LLVMArithmetic.UNSIGNED_ADD, getOverflowFieldOffset(declaration), args[2], args[3], args[1]);
            case "llvm.usub.with.overflow.i8":
            case "llvm.usub.with.overflow.i16":
            case "llvm.usub.with.overflow.i32":
            case "llvm.usub.with.overflow.i64":
                return LLVMArithmeticWithOverflowNodeGen.create(LLVMArithmetic.UNSIGNED_SUB, getOverflowFieldOffset(declaration), args[2], args[3], args[1]);
            case "llvm.umul.with.overflow.i8":
            case "llvm.umul.with.overflow.i16":
            case "llvm.umul.with.overflow.i32":
            case "llvm.umul.with.overflow.i64":
                return LLVMArithmeticWithOverflowNodeGen.create(LLVMArithmetic.UNSIGNED_MUL, getOverflowFieldOffset(declaration), args[2], args[3], args[1]);
            case "llvm.sadd.with.overflow.i8":
            case "llvm.sadd.with.overflow.i16":
            case "llvm.sadd.with.overflow.i32":
            case "llvm.sadd.with.overflow.i64":
                return LLVMArithmeticWithOverflowNodeGen.create(LLVMArithmetic.SIGNED_ADD, getOverflowFieldOffset(declaration), args[2], args[3], args[1]);
            case "llvm.ssub.with.overflow.i8":
            case "llvm.ssub.with.overflow.i16":
            case "llvm.ssub.with.overflow.i32":
            case "llvm.ssub.with.overflow.i64":
                return LLVMArithmeticWithOverflowNodeGen.create(LLVMArithmetic.SIGNED_SUB, getOverflowFieldOffset(declaration), args[2], args[3], args[1]);
            case "llvm.smul.with.overflow.i8":
            case "llvm.smul.with.overflow.i16":
            case "llvm.smul.with.overflow.i32":
            case "llvm.smul.with.overflow.i64":
                return LLVMArithmeticWithOverflowNodeGen.create(LLVMArithmetic.SIGNED_MUL, getOverflowFieldOffset(declaration), args[2], args[3], args[1]);
            case "llvm.exp2.f32":
            case "llvm.exp2.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMExp2NodeGen.create(args[1]);
            case "llvm.sqrt.f32":
            case "llvm.sqrt.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMSqrtNodeGen.create(args[1]);
            case "llvm.sqrt.v2f64":
                return LLVMCMathsIntrinsicsFactory.LLVMSqrtVectorNodeGen.create(args[1], 2);
            case "llvm.sin.f32":
            case "llvm.sin.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMSinNodeGen.create(args[1]);
            case "llvm.cos.f32":
            case "llvm.cos.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMCosNodeGen.create(args[1]);
            case "llvm.exp.f32":
            case "llvm.exp.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMExpNodeGen.create(args[1]);
            case "llvm.log.f32":
            case "llvm.log.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMLogNodeGen.create(args[1]);
            case "llvm.log2.f32":
            case "llvm.log2.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMLog2NodeGen.create(args[1]);
            case "llvm.log10.f32":
            case "llvm.log10.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMLog10NodeGen.create(args[1]);
            case "llvm.floor.f32":
            case "llvm.floor.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMFloorNodeGen.create(args[1]);
            case "llvm.ceil.f32":
            case "llvm.ceil.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMCeilNodeGen.create(args[1]);
            case "llvm.rint.f32":
            case "llvm.rint.f64":
                return LLVMCMathsIntrinsicsFactory.LLVMRintNodeGen.create(args[1]);
            case "llvm.x86.sse.cvtss2si":
                return LLVMX86_ConversionFloatToIntNodeGen.create(args[1]);
            case "llvm.x86.sse.cmp.ss":
                return LLVMX86_CmpssNodeGen.create(args[1], args[2], args[3]);
            case "llvm.x86.sse2.cvtsd2si":
                return LLVMX86_ConversionDoubleToIntNodeGen.create(args[1]);
            case "llvm.x86.sse2.sqrt.pd":
                return LLVMX86_VectorSquareRootNodeGen.create(args[1]);
            case "llvm.x86.sse2.max.pd":
                return LLVMX86_VectorMaxNodeGen.create(args[1], args[2]);
            case "llvm.x86.sse2.max.sd":
                return LLVMX86_VectorMaxsdNodeGen.create(args[1], args[2]);
            case "llvm.x86.sse2.min.pd":
                return LLVMX86_VectorMinNodeGen.create(args[1], args[2]);
            case "llvm.x86.sse2.cmp.sd":
                return LLVMX86_VectorCmpNodeGen.create(args[1], args[2], args[3]);
            case "llvm.x86.sse2.packssdw.128":
            case "llvm.x86.sse2.packsswb.128":
                return LLVMX86_VectorPackNodeGen.create(args[1], args[2]);
            case "llvm.x86.sse2.pmovmskb.128":
                return LLVMX86_Pmovmskb128NodeGen.create(args[1]);
            case "llvm.x86.sse2.movmsk.pd":
                return LLVMX86_MovmskpdNodeGen.create(args[1]);
            default:
                break;
        }
    } catch (TypeOverflowException e) {
        return Type.handleOverflowExpression(e);
    }
    LLVMExpressionNode vectorIntrinsic = matchVectorOp(intrinsicName, args);
    if (vectorIntrinsic != null) {
        return vectorIntrinsic;
    }
    // strip the type suffix for intrinsics that are supported for more than one data type. If
    // we do not implement the corresponding data type the node will just report a missing
    // specialization at run-time
    TypeSuffix typeSuffix = getTypeSuffix(intrinsicName);
    if (typeSuffix != null) {
        intrinsicName = intrinsicName.substring(0, intrinsicName.length() - typeSuffix.suffix.length());
    }
    if ("llvm.prefetch".equals(intrinsicName)) {
        return LLVMPrefetchNodeGen.create(args[1], args[2], args[3], args[4]);
    }
    if ("llvm.is.constant".equals(intrinsicName)) {
        return LLVMIsConstantNodeGen.create(args[1]);
    }
    if ("llvm.umax".equals(intrinsicName) && typeSuffix != null && typeSuffix.length != null) {
        try {
            int vectorLength = Integer.parseInt(typeSuffix.length);
            return LLVMUnsignedVectorMinMaxNodeGen.create(args[1], args[2], vectorLength, LLVMUmaxOperator.INSTANCE);
        } catch (NumberFormatException e) {
        // fall through
        }
    }
    if ("llvm.umin".equals(intrinsicName) && typeSuffix != null && typeSuffix.length != null) {
        try {
            int vectorLength = Integer.parseInt(typeSuffix.length);
            return LLVMUnsignedVectorMinMaxNodeGen.create(args[1], args[2], vectorLength, LLVMUminOperator.INSTANCE);
        } catch (NumberFormatException e) {
        // fall through
        }
    }
    return LLVMX86_MissingBuiltin.create(declaration.getName());
}
Also used : LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException)

Example 5 with TypeOverflowException

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

the class BasicNodeFactory method createStructureConstantNode.

@Override
public LLVMExpressionNode createStructureConstantNode(Type structType, GetStackSpaceFactory getStackSpaceFactory, boolean packed, Type[] types, LLVMExpressionNode[] constants) {
    long[] offsets = new long[types.length];
    LLVMStoreNode[] nodes = new LLVMStoreNode[types.length];
    long currentOffset = 0;
    LLVMExpressionNode getStackSpace = getStackSpaceFactory.createGetStackSpace(this, structType);
    try {
        for (int i = 0; i < types.length; i++) {
            Type resolvedType = types[i];
            if (!packed) {
                currentOffset = Type.addUnsignedExact(currentOffset, getBytePadding(currentOffset, resolvedType));
            }
            offsets[i] = currentOffset;
            long byteSize = getByteSize(resolvedType);
            nodes[i] = createMemoryStore(null, null, resolvedType);
            currentOffset = Type.addUnsignedExact(currentOffset, byteSize);
        }
    } catch (TypeOverflowException e) {
        return Type.handleOverflowExpression(e);
    }
    return StructLiteralNodeGen.create(offsets, nodes, constants, getStackSpace);
}
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) LLVMStoreNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStoreNode) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException)

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