Search in sources :

Example 31 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(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 32 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(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)

Example 33 with PointerType

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

the class LLVMParserRuntime method getGlobalVariable.

private LLVMExpressionNode getGlobalVariable(LLVMSymbolReadResolver symbolResolver, GlobalValueSymbol global) {
    LLVMSourceSymbol sourceSymbol = null;
    SymbolImpl g = global;
    while (g instanceof GlobalAlias) {
        if (sourceSymbol == null) {
            sourceSymbol = ((GlobalAlias) g).getSourceSymbol();
        }
        g = aliases.get(g);
    }
    if (sourceSymbol == null && g instanceof GlobalValueSymbol) {
        sourceSymbol = ((GlobalValueSymbol) g).getSourceSymbol();
    }
    if (g instanceof GlobalValueSymbol) {
        final GlobalValueSymbol variable = (GlobalValueSymbol) g;
        final LLVMSourceSymbol finalSourceSymbol = sourceSymbol;
        Object globalVariableDescriptor = scope.lookupOrCreateGlobal(variable.getName(), !Linkage.isFileLocal(variable.getLinkage()), () -> {
            final Object globalValue;
            if (global instanceof GlobalVariable) {
                globalValue = nodeFactory.allocateGlobalVariable(this, (GlobalVariable) global, finalSourceSymbol);
            } else if (global instanceof GlobalConstant) {
                globalValue = nodeFactory.allocateGlobalConstant(this, (GlobalConstant) global, finalSourceSymbol);
            } else {
                throw new AssertionError("Cannot allocate global: " + global);
            }
            return globalValue;
        });
        return nodeFactory.createLiteral(this, globalVariableDescriptor, new PointerType(variable.getType()));
    } else {
        return symbolResolver.resolve(g);
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) GlobalConstant(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)

Example 34 with PointerType

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

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

the class LLVMRuntimeDebugInformation method handleDebugIntrinsic.

LLVMExpressionNode handleDebugIntrinsic(SymbolImpl value, SourceVariable variable, MDExpression expression, long index, boolean isDeclaration) {
    if (!isEnabled || variable.hasStaticAllocation()) {
        return null;
    }
    LLVMExpressionNode valueRead = null;
    if (isDeclaration) {
        if (value instanceof UndefinedConstant) {
            if (variable.hasValue()) {
                // know this from the presence of the value
                return null;
            }
            valueRead = symbols.resolve(new NullConstant(MetaType.DEBUG));
        } else if (value instanceof NullConstant) {
            valueRead = symbols.resolve(new NullConstant(MetaType.DEBUG));
        } else if (value instanceof GlobalValueSymbol || value.getType() instanceof PointerType) {
            valueRead = symbols.resolve(value);
        }
    } else {
        valueRead = symbols.resolve(value);
        if (index != 0) {
            // this is unsupported, it doesn't appear in LLVM 3.8+
            return null;
        }
    }
    if (valueRead == null) {
        return null;
    }
    int partIndex = -1;
    int[] clearParts = null;
    if (ValueFragment.describesFragment(expression)) {
        final ValueFragment fragment = ValueFragment.parse(expression);
        final List<ValueFragment> siblings = variable.getFragments();
        final List<Integer> clearSiblings = new ArrayList<>(siblings.size());
        partIndex = ValueFragment.getPartIndex(fragment, siblings, clearSiblings);
        if (clearSiblings.isEmpty()) {
            // this will be the case most of the time
            clearParts = CLEAR_NONE;
        } else {
            clearParts = clearSiblings.stream().mapToInt(Integer::intValue).toArray();
        }
    }
    if (partIndex < 0 && variable.hasFragments()) {
        partIndex = variable.getFragmentIndex(0, (int) variable.getSymbol().getType().getSize());
        if (partIndex < 0) {
            throw new IllegalStateException("Cannot find index of value fragment!");
        }
        clearParts = new int[variable.getFragments().size() - 1];
        for (int i = 0; i < partIndex; i++) {
            clearParts[i] = i;
        }
        for (int i = partIndex; i < clearParts.length; i++) {
            clearParts[i] = i + 1;
        }
    }
    final boolean mustDereference = isDeclaration || mustDereferenceValue(expression, variable.getSourceType(), value);
    final FrameSlot targetSlot = frame.findOrAddFrameSlot(variable.getSymbol(), MetaType.DEBUG, FrameSlotKind.Object);
    final LLVMExpressionNode containerRead = factory.createFrameRead(runtime, MetaType.DEBUG, targetSlot);
    return factory.createDebugWrite(mustDereference, valueRead, targetSlot, containerRead, partIndex, clearParts);
}
Also used : UndefinedConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) ArrayList(java.util.ArrayList) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ValueFragment(com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment)

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