Search in sources :

Example 6 with PointerType

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(VoidCallInstruction call) {
    // stackpointer
    final int argumentCount = call.getArgumentCount() + 1;
    final LLVMExpressionNode[] args = new LLVMExpressionNode[argumentCount];
    final Type[] argsType = new Type[argumentCount];
    int argIndex = 0;
    args[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
    argsType[argIndex] = new PointerType(null);
    argIndex++;
    for (int i = 0; i < call.getArgumentCount(); i++) {
        args[argIndex] = symbols.resolve(call.getArgument(i));
        argsType[argIndex] = call.getArgument(i).getType();
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        if (isByValue(paramAttr)) {
            args[argIndex] = capsuleAddressByValue(args[argIndex], argsType[argIndex], paramAttr);
        }
        argIndex++;
    }
    final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
    final SymbolImpl target = call.getCallTarget();
    LLVMExpressionNode node = nodeFactory.createLLVMBuiltin(runtime, target, args, argCount, source);
    if (node == null) {
        if (target instanceof InlineAsmConstant) {
            final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
            node = createInlineAssemblerNode(inlineAsmConstant, args, argsType, call.getType(), source);
        } else {
            final LLVMExpressionNode function = symbols.resolve(target);
            final FunctionType functionType = new FunctionType(call.getType(), argsType, false);
            node = nodeFactory.createFunctionCall(runtime, function, args, functionType, source);
        }
    }
    addInstruction(node);
}
Also used : 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) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) InlineAsmConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.InlineAsmConstant)

Example 7 with PointerType

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

the class Function method createLoad.

private void createLoad(long[] args) {
    int i = 0;
    final int src = getIndex(args[i++]);
    final Type srcType;
    if (scope.isValueForwardRef(src)) {
        srcType = types.get(args[i++]);
    } else {
        srcType = scope.getValueType(src);
    }
    final Type opType;
    if (i + LOAD_ARGS_EXPECTED_AFTER_TYPE == args.length) {
        opType = types.get(args[i++]);
    } else {
        opType = ((PointerType) srcType).getPointeeType();
    }
    final int align = getAlign(args[i++]);
    final boolean isVolatile = args[i] != 0;
    emit(LoadInstruction.fromSymbols(scope.getSymbols(), opType, src, align, isVolatile));
}
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)

Example 8 with PointerType

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

the class Function method createInvoke.

private void createInvoke(long[] args) {
    int i = 0;
    final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[i++]);
    final long ccInfo = args[i++];
    final InstructionBlock normalSuccessor = function.getBlock(args[i++]);
    final InstructionBlock unwindSuccessor = function.getBlock(args[i++]);
    FunctionType functionType = null;
    if (((ccInfo >> INVOKE_HASEXPLICITFUNCTIONTYPE_SHIFT) & 1) != 0) {
        functionType = (FunctionType) types.get(args[i++]);
    }
    final int target = getIndex(args[i++]);
    final Type calleeType;
    if (scope.isValueForwardRef(target)) {
        calleeType = types.get(args[i++]);
    } else {
        calleeType = scope.getValueType(target);
    }
    if (functionType == null) {
        if (calleeType instanceof PointerType) {
            functionType = (FunctionType) ((PointerType) calleeType).getPointeeType();
        } else if (calleeType instanceof FunctionType) {
            functionType = (FunctionType) calleeType;
        } else {
            throw new AssertionError("Cannot find Type of invoked function: " + calleeType.toString());
        }
    }
    int[] arguments = new int[args.length - i];
    int skipped = 0;
    int j = 0;
    while (j < functionType.getArgumentTypes().length && i < args.length) {
        arguments[j++] = getIndex(args[i++]);
    }
    while (i < args.length) {
        int index = getIndex(args[i++]);
        arguments[j++] = index;
        if (scope.isValueForwardRef(index)) {
            i++;
            skipped++;
        }
    }
    if (skipped > 0) {
        arguments = Arrays.copyOf(arguments, arguments.length - skipped);
    }
    final Type returnType = functionType.getReturnType();
    if (returnType == VoidType.INSTANCE) {
        emit(VoidInvokeInstruction.fromSymbols(scope, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
    } else {
        emit(InvokeInstruction.fromSymbols(scope, returnType, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
    }
    isLastBlockTerminated = true;
}
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) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Example 9 with PointerType

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

the class Function method createGetElementPointerOld.

private void createGetElementPointerOld(long[] args, boolean isInbounds) {
    int i = 0;
    int pointer = getIndex(args[i++]);
    Type base;
    if (scope.isValueForwardRef(pointer)) {
        base = types.get(args[i++]);
    } else {
        base = scope.getValueType(pointer);
    }
    List<Integer> indices = getIndices(args, i);
    Type type = new PointerType(getElementPointerType(base, indices));
    emit(GetElementPointerInstruction.fromSymbols(scope.getSymbols(), type, pointer, indices, isInbounds));
}
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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Example 10 with PointerType

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

the class Function method createAlloca.

private void createAlloca(long[] args) {
    int i = 0;
    final long typeRecord = args[i++];
    // type of count
    i++;
    final int count = getIndexAbsolute(args[i++]);
    final long alignRecord = args[i];
    final int align = getAlign(alignRecord & ~ALLOCA_FLAGSMASK);
    Type type = types.get(typeRecord);
    if ((alignRecord & ALLOCA_EXPLICITTYPEMASK) != 0L) {
        type = new PointerType(type);
    } else if (!(type instanceof PointerType)) {
        throw new AssertionError("Alloca must have PointerType!");
    }
    emit(AllocateInstruction.fromSymbols(scope.getSymbols(), type, count, align));
}
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) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Aggregations

PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)37 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)31 Type (com.oracle.truffle.llvm.runtime.types.Type)29 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)27 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)24 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)20 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)18 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)18 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)18 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)14 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)9 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)9 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)9 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)6 ArrayList (java.util.ArrayList)5 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)4 PrimitiveKind (com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)4 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)4 AttributesCodeEntry (com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry)3