Search in sources :

Example 41 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class LLVMLivenessAnalysis method resolve.

private static int resolve(FrameDescriptor frame, SymbolImpl symbol) {
    if (symbol instanceof ValueSymbol && !(symbol instanceof GlobalValueSymbol || symbol instanceof FunctionDefinition || symbol instanceof FunctionDeclaration)) {
        String name = ((ValueSymbol) symbol).getName();
        assert name != null;
        FrameSlot frameSlot = frame.findFrameSlot(name);
        assert frameSlot != null : "No Frameslot for ValueSymbol: " + symbol;
        return frameSlot.getIndex();
    }
    return -1;
}
Also used : FunctionDeclaration(com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) ValueSymbol(com.oracle.truffle.llvm.parser.model.ValueSymbol) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)

Example 42 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class LLVMRuntimeDebugInformation method createInitializer.

LLVMExpressionNode createInitializer(SourceVariable variable) {
    if (!isEnabled) {
        return null;
    }
    final FrameSlot targetSlot = frame.findOrAddFrameSlot(variable.getSymbol(), MetaType.DEBUG, FrameSlotKind.Object);
    int[] offsets = null;
    int[] lengths = null;
    if (variable.hasFragments()) {
        final List<ValueFragment> fragments = variable.getFragments();
        offsets = new int[fragments.size()];
        lengths = new int[fragments.size()];
        for (int i = 0; i < fragments.size(); i++) {
            final ValueFragment fragment = fragments.get(i);
            offsets[i] = fragment.getOffset();
            lengths[i] = fragment.getLength();
        }
    }
    return factory.createDebugInit(targetSlot, offsets, lengths);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) ValueFragment(com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment)

Example 43 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.

the class LLVMRuntimeDebugInformation method registerStaticDebugSymbols.

void registerStaticDebugSymbols(FunctionDefinition fn) {
    if (!isEnabled) {
        return;
    }
    for (SourceVariable local : fn.getSourceFunction().getVariables()) {
        if (local.isSingleDeclaration()) {
            final DbgDeclareInstruction dbg = local.getSingleDeclaration();
            FrameSlot frameSlot = null;
            if (dbg.getValue() instanceof AllocateInstruction) {
                frameSlot = frame.findFrameSlot(((AllocateInstruction) dbg.getValue()).getName());
            }
            if (frameSlot == null) {
                continue;
            }
            final LLVMSourceSymbol symbol = local.getSymbol();
            final LLVMFrameValueAccess alloc = factory.createDebugFrameValue(frameSlot, true);
            notNullableSlots.add(frameSlot);
            context.getSourceContext().registerFrameValue(symbol, alloc);
            local.addStaticValue();
        } else if (local.isSingleValue()) {
            final DbgValueInstruction dbg = local.getSingleValue();
            final MDExpression expr = dbg.getExpression();
            final SymbolImpl value = dbg.getValue();
            if (expr.getElementCount() != 0) {
                continue;
            }
            final boolean mustDereference = mustDereferenceValue(expr, local.getSourceType(), value);
            staticValueAccessVisitor.registerStaticAccess(local, value, mustDereference);
        }
    }
}
Also used : SourceVariable(com.oracle.truffle.llvm.parser.metadata.debuginfo.SourceVariable) DbgDeclareInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgDeclareInstruction) LLVMFrameValueAccess(com.oracle.truffle.llvm.runtime.debug.scope.LLVMFrameValueAccess) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) AllocateInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.AllocateInstruction) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) DbgValueInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgValueInstruction) MDExpression(com.oracle.truffle.llvm.parser.metadata.MDExpression) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol)

Example 44 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot 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)

Example 45 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot 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

FrameSlot (com.oracle.truffle.api.frame.FrameSlot)47 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)12 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)10 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)7 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Type (com.oracle.truffle.llvm.runtime.types.Type)5 CallTarget (com.oracle.truffle.api.CallTarget)4 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)3 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)3 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 Frame (com.oracle.truffle.api.frame.Frame)2 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2