Search in sources :

Example 11 with StructureType

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(ExtractValueInstruction extract) {
    if (!(extract.getAggregate().getType() instanceof ArrayType || extract.getAggregate().getType() instanceof StructureType || extract.getAggregate().getType() instanceof PointerType)) {
        throw new IllegalStateException("\'extractvalue\' can only extract elements of arrays and structs!");
    }
    final LLVMExpressionNode baseAddress = symbols.resolve(extract.getAggregate());
    final Type baseType = extract.getAggregate().getType();
    final int targetIndex = extract.getIndex();
    final Type resultType = extract.getType();
    LLVMExpressionNode targetAddress = baseAddress;
    final AggregateType aggregateType = (AggregateType) baseType;
    long offset = runtime.getContext().getIndexOffset(targetIndex, aggregateType);
    final Type targetType = aggregateType.getElementType(targetIndex);
    if (targetType != null && !((targetType instanceof StructureType) && (((StructureType) targetType).isPacked()))) {
        offset += runtime.getContext().getBytePadding(offset, targetType);
    }
    if (offset != 0) {
        final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(runtime, 1, PrimitiveType.I32);
        targetAddress = nodeFactory.createTypedElementPointer(runtime, targetAddress, oneLiteralNode, offset, extract.getType());
    }
    final LLVMExpressionNode result = nodeFactory.createExtractValue(runtime, resultType, targetAddress);
    createFrameWrite(result, extract);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType)

Example 12 with StructureType

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(InsertValueInstruction insert) {
    if (!(insert.getAggregate().getType() instanceof StructureType || insert.getAggregate().getType() instanceof ArrayType)) {
        throw new IllegalStateException("\'insertvalue\' can only insert values into arrays and structs!");
    }
    final AggregateType sourceType = (AggregateType) insert.getAggregate().getType();
    final LLVMExpressionNode sourceAggregate = symbols.resolve(insert.getAggregate());
    final LLVMExpressionNode valueToInsert = symbols.resolve(insert.getValue());
    final Type valueType = insert.getValue().getType();
    final int targetIndex = insert.getIndex();
    final LLVMExpressionNode resultAggregate = nodeFactory.createAlloca(runtime, sourceType);
    final long offset = runtime.getContext().getIndexOffset(targetIndex, sourceType);
    final LLVMExpressionNode result = nodeFactory.createInsertValue(runtime, resultAggregate, sourceAggregate, runtime.getContext().getByteSize(sourceType), offset, valueToInsert, valueType);
    createFrameWrite(result, insert);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType)

Example 13 with StructureType

use of com.oracle.truffle.llvm.runtime.types.StructureType 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 StructureType

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

the class LLVMParserRuntime method createGlobalInitialization.

private LLVMExpressionNode createGlobalInitialization(LLVMSymbolReadResolver symbolResolver, GlobalValueSymbol global) {
    if (global == null || global.getValue() == null) {
        return null;
    }
    LLVMExpressionNode constant = symbolResolver.resolve(global.getValue());
    if (constant != null) {
        final Type type = ((PointerType) global.getType()).getPointeeType();
        final int size = getContext().getByteSize(type);
        final LLVMExpressionNode globalVarAddress = getGlobalVariable(symbolResolver, global);
        if (size != 0) {
            final LLVMExpressionNode store;
            if (type instanceof ArrayType || type instanceof StructureType) {
                store = nodeFactory.createStore(this, globalVarAddress, constant, type, null);
            } else {
                final Type t = global.getValue().getType();
                store = nodeFactory.createStore(this, globalVarAddress, constant, t, null);
            }
            return store;
        }
    }
    return null;
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Type(com.oracle.truffle.llvm.runtime.types.Type) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Example 15 with StructureType

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

the class LazyToTruffleConverterImpl method copyArgumentsToFrame.

private List<LLVMExpressionNode> copyArgumentsToFrame(FrameDescriptor frame) {
    List<FunctionParameter> parameters = method.getParameters();
    List<LLVMExpressionNode> formalParamInits = new ArrayList<>();
    LLVMExpressionNode stackPointerNode = nodeFactory.createFunctionArgNode(0, PrimitiveType.I64);
    formalParamInits.add(nodeFactory.createFrameWrite(runtime, PointerType.VOID, stackPointerNode, frame.findFrameSlot(LLVMStack.FRAME_ID), null));
    int argIndex = 1;
    if (method.getType().getReturnType() instanceof StructureType) {
        argIndex++;
    }
    for (FunctionParameter parameter : parameters) {
        LLVMExpressionNode parameterNode = nodeFactory.createFunctionArgNode(argIndex++, parameter.getType());
        FrameSlot slot = frame.findFrameSlot(parameter.getName());
        if (isStructByValue(parameter)) {
            Type type = ((PointerType) parameter.getType()).getPointeeType();
            formalParamInits.add(nodeFactory.createFrameWrite(runtime, parameter.getType(), nodeFactory.createCopyStructByValue(runtime, type, parameterNode), slot, null));
        } else {
            formalParamInits.add(nodeFactory.createFrameWrite(runtime, parameter.getType(), parameterNode, slot, null));
        }
    }
    return formalParamInits;
}
Also used : LLVMSourceFunctionType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceFunctionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayList(java.util.ArrayList) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionParameter(com.oracle.truffle.llvm.parser.model.functions.FunctionParameter)

Aggregations

StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)15 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)14 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)13 Type (com.oracle.truffle.llvm.runtime.types.Type)12 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)11 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)10 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)10 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)8 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)8 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)8 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)7 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)5 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)5 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)4 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)4 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)4 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)3 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType)3 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)3 ArrayList (java.util.ArrayList)3