Search in sources :

Example 1 with AttributesCodeEntry

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry 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 2 with AttributesCodeEntry

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.

the class Module method createFunction.

private void createFunction(long[] args) {
    final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
    Type type = types.get(args[FUNCTION_TYPE + recordOffset]);
    if (type instanceof PointerType) {
        type = ((PointerType) type).getPointeeType();
    }
    final FunctionType functionType = (FunctionType) type;
    final boolean isPrototype = args[FUNCTION_ISPROTOTYPE + recordOffset] != 0;
    final Linkage linkage = Linkage.decode(args[FUNCTION_LINKAGE + recordOffset]);
    final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[FUNCTION_PARAMATTR + recordOffset]);
    if (isPrototype) {
        final FunctionDeclaration function = new FunctionDeclaration(functionType, linkage, paramAttr);
        module.addFunctionDeclaration(function);
        scope.addSymbol(function, function.getType());
        if (useStrTab()) {
            readNameFromStrTab(args, function);
        }
    } else {
        final FunctionDefinition function = new FunctionDefinition(functionType, linkage, paramAttr);
        module.addFunctionDefinition(function);
        scope.addSymbol(function, function.getType());
        if (useStrTab()) {
            readNameFromStrTab(args, function);
        }
        functionQueue.addLast(function);
    }
}
Also used : FunctionDeclaration(com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) Linkage(com.oracle.truffle.llvm.parser.model.enums.Linkage) 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) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)

Example 3 with AttributesCodeEntry

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.

the class ParameterAttributes method decodeOldCodeEntry.

private void decodeOldCodeEntry(long[] args) {
    final List<AttributesGroup> attrGroup = new ArrayList<>();
    for (int i = 0; i < args.length; i += 2) {
        attrGroup.add(decodeOldGroupCodeEntry(args[i], args[i + 1]));
    }
    parameterCodeEntry.add(new AttributesCodeEntry(attrGroup));
}
Also used : AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) ArrayList(java.util.ArrayList)

Example 4 with AttributesCodeEntry

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry 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 5 with AttributesCodeEntry

use of com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry in project sulong by graalvm.

the class ParameterAttributes method decodeCodeEntry.

private void decodeCodeEntry(long[] args) {
    final List<AttributesGroup> attrGroup = new ArrayList<>();
    for (long groupId : args) {
        for (AttributesGroup attr : attributes) {
            if (attr.getGroupId() == groupId) {
                attrGroup.add(attr);
                break;
            }
        }
    }
    if (attrGroup.size() != args.length) {
        throw new AssertionError("there is a mismatch between defined and found group id's");
    }
    parameterCodeEntry.add(new AttributesCodeEntry(attrGroup));
}
Also used : AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) ArrayList(java.util.ArrayList)

Aggregations

AttributesCodeEntry (com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry)5 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)3 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)3 Type (com.oracle.truffle.llvm.runtime.types.Type)3 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)2 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)2 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)2 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)2 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)2 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)2 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)2 ArrayList (java.util.ArrayList)2 InstructionBlock (com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)1 Linkage (com.oracle.truffle.llvm.parser.model.enums.Linkage)1 FunctionDeclaration (com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration)1 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)1