Search in sources :

Example 11 with FunctionType

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

the class Function method createFunctionCall.

private void createFunctionCall(long[] args) {
    int i = 0;
    final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[i++]);
    final long ccinfo = args[i++];
    if (((ccinfo >> CALL_HAS_FMF_SHIFT) & 1) != 0) {
        // fast math flags
        i++;
    }
    FunctionType functionType = null;
    if (((ccinfo >> CALL_HAS_EXPLICITTYPE_SHIFT) & 1) != 0) {
        functionType = (FunctionType) types.get(args[i++]);
    }
    int callee = getIndex(args[i++]);
    Type calleeType;
    if (scope.isValueForwardRef(callee)) {
        calleeType = types.get(args[i++]);
    } else {
        calleeType = scope.getValueType(callee);
    }
    if (functionType == null) {
        if (calleeType instanceof FunctionType) {
            functionType = (FunctionType) calleeType;
        } else {
            functionType = (FunctionType) ((PointerType) calleeType).getPointeeType();
        }
    }
    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(VoidCallInstruction.fromSymbols(scope, callee, arguments, paramAttr));
    } else {
        emit(CallInstruction.fromSymbols(scope, returnType, callee, arguments, paramAttr));
    }
}
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)

Example 12 with FunctionType

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

the class BasicNodeFactory method createInlineAssemblerExpression.

@Override
public LLVMExpressionNode createInlineAssemblerExpression(LLVMParserRuntime runtime, String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type[] argTypes, Type retType, LLVMSourceLocation sourceSection) {
    Type[] retTypes = null;
    int[] retOffsets = null;
    if (retType instanceof StructureType) {
        // multiple out values
        assert args[1] instanceof LLVMAllocaConstInstruction;
        LLVMAllocaConstInstruction alloca = (LLVMAllocaConstInstruction) args[1];
        retTypes = alloca.getTypes();
        retOffsets = alloca.getOffsets();
    }
    Parser asmParser = new Parser(runtime.getLanguage(), sourceSection, asmExpression, asmFlags, argTypes, retType, retTypes, retOffsets);
    LLVMInlineAssemblyRootNode assemblyRoot = asmParser.Parse();
    LLVMFunctionDescriptor asm = LLVMFunctionDescriptor.createDescriptor(runtime.getContext(), runtime.getLibrary(), "<asm>", new FunctionType(MetaType.UNKNOWN, new Type[0], false), -1);
    asm.declareInSulong(Truffle.getRuntime().createCallTarget(assemblyRoot), false);
    LLVMFunctionLiteralNode asmFunction = LLVMFunctionLiteralNodeGen.create(asm);
    return new LLVMCallNode(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, sourceSection);
}
Also used : LLVMInlineAssemblyRootNode(com.oracle.truffle.llvm.nodes.func.LLVMInlineAssemblyRootNode) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) 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) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) 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) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) LLVMCallNode(com.oracle.truffle.llvm.nodes.func.LLVMCallNode) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMFunctionLiteralNode(com.oracle.truffle.llvm.nodes.literals.LLVMFunctionLiteralNode) LLVMAllocaConstInstruction(com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction) Parser(com.oracle.truffle.llvm.asm.amd64.Parser)

Example 13 with FunctionType

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

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 Type[] argTypes = new Type[argumentCount];
    int argIndex = 0;
    // stack pointer
    argNodes[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
    argTypes[argIndex] = new PointerType(null);
    argIndex++;
    if (targetType instanceof StructureType) {
        argTypes[argIndex] = new PointerType(targetType);
        argNodes[argIndex] = nodeFactory.createAlloca(runtime, targetType);
        argIndex++;
    }
    for (int i = 0; argIndex < argumentCount; i++) {
        argNodes[argIndex] = symbols.resolve(call.getArgument(i));
        argTypes[argIndex] = call.getArgument(i).getType();
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        if (isByValue(paramAttr)) {
            argNodes[argIndex] = capsuleAddressByValue(argNodes[argIndex], argTypes[argIndex], paramAttr);
        }
        argIndex++;
    }
    final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
    final SymbolImpl target = call.getCallTarget();
    LLVMExpressionNode result = nodeFactory.createLLVMBuiltin(runtime, target, argNodes, argCount, source);
    if (result == null) {
        if (target instanceof InlineAsmConstant) {
            final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
            result = createInlineAssemblerNode(inlineAsmConstant, argNodes, argTypes, targetType, source);
        } else {
            LLVMExpressionNode function = symbols.resolve(target);
            result = nodeFactory.createFunctionCall(runtime, function, argNodes, new FunctionType(targetType, argTypes, false), source);
        }
    }
    // the SourceSection references the call, not the return value assignment
    createFrameWrite(result, call, null);
}
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) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) 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 14 with FunctionType

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(VoidInvokeInstruction call) {
    final SymbolImpl target = call.getCallTarget();
    // 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++;
    }
    int regularIndex = call.normalSuccessor().getBlockIndex();
    int unwindIndex = call.unwindSuccessor().getBlockIndex();
    List<FrameSlot> normalTo = new ArrayList<>();
    List<FrameSlot> unwindTo = new ArrayList<>();
    List<Type> normalType = new ArrayList<>();
    List<Type> unwindType = new ArrayList<>();
    List<LLVMExpressionNode> normalValue = new ArrayList<>();
    List<LLVMExpressionNode> unwindValue = new ArrayList<>();
    if (blockPhis != null) {
        for (Phi phi : blockPhis) {
            FrameSlot slot = getSlot(phi.getPhiValue().getName());
            LLVMExpressionNode value = symbols.resolve(phi.getValue());
            if (call.normalSuccessor() == phi.getBlock()) {
                normalTo.add(slot);
                normalType.add(phi.getValue().getType());
                normalValue.add(value);
            } else {
                unwindTo.add(slot);
                unwindType.add(phi.getValue().getType());
                unwindValue.add(value);
            }
        }
    }
    LLVMExpressionNode normalPhi = nodeFactory.createPhi(runtime, normalValue.toArray(new LLVMExpressionNode[normalValue.size()]), normalTo.toArray(new FrameSlot[normalTo.size()]), normalType.toArray(Type.EMPTY_ARRAY));
    LLVMExpressionNode unwindPhi = nodeFactory.createPhi(runtime, unwindValue.toArray(new LLVMExpressionNode[unwindValue.size()]), unwindTo.toArray(new FrameSlot[unwindTo.size()]), unwindType.toArray(Type.EMPTY_ARRAY));
    final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
    LLVMExpressionNode function = nodeFactory.createLLVMBuiltin(runtime, target, args, argCount, null);
    if (function == null) {
        function = symbols.resolve(target);
    }
    LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(runtime, null, function, args, new FunctionType(call.getType(), argsType, false), regularIndex, unwindIndex, normalPhi, unwindPhi, source);
    setControlFlowNode(result);
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayList(java.util.ArrayList) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) 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) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Aggregations

FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)14 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)12 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)11 Type (com.oracle.truffle.llvm.runtime.types.Type)11 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)10 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)10 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)9 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)6 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)6 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)6 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)6 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)6 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)4 AttributesCodeEntry (com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry)3 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)3 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)3 ArrayList (java.util.ArrayList)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2