Search in sources :

Example 11 with LLVMSourceLocation

use of com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation in project sulong by graalvm.

the class DebugInfoCache method getSourceSymbol.

LLVMSourceSymbol getSourceSymbol(MDBaseNode mdVariable, boolean isGlobal) {
    if (parsedVariables.containsKey(mdVariable)) {
        return parsedVariables.get(mdVariable);
    }
    LLVMSourceLocation location = scopeBuilder.buildLocation(mdVariable);
    final LLVMSourceType type = typeExtractor.parseType(mdVariable);
    final String varName = MDNameExtractor.getName(mdVariable);
    final LLVMSourceSymbol symbol = new LLVMSourceSymbol(varName, location, type, isGlobal);
    parsedVariables.put(mdVariable, symbol);
    if (location != null) {
        // this is currently the line/column where the symbol was declared, we want the
        // scope
        location = location.getParent();
    }
    if (location != null) {
        location.addSymbol(symbol);
    }
    return symbol;
}
Also used : LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)

Example 12 with LLVMSourceLocation

use of com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation in project sulong by graalvm.

the class DebugInfoFunctionProcessor method initSourceFunction.

private void initSourceFunction(FunctionDefinition function, Source bitcodeSource) {
    final MDBaseNode debugInfo = getDebugInfo(function);
    LLVMSourceLocation scope = null;
    LLVMSourceFunctionType type = null;
    if (debugInfo != null) {
        scope = cache.buildLocation(debugInfo);
        LLVMSourceType actualType = cache.parseType(debugInfo);
        if (actualType instanceof LLVMSourceFunctionType) {
            type = (LLVMSourceFunctionType) actualType;
        }
    }
    if (scope == null) {
        final String sourceText = String.format("%s:%s", bitcodeSource.getName(), function.getName());
        final Source irSource = Source.newBuilder(sourceText).mimeType(DIScopeBuilder.getMimeType(null)).name(sourceText).build();
        final SourceSection simpleSection = irSource.createSection(1);
        scope = LLVMSourceLocation.createBitcodeFunction(function.getName(), simpleSection);
    }
    final SourceFunction sourceFunction = new SourceFunction(scope, type);
    function.setSourceFunction(sourceFunction);
    for (SourceVariable local : sourceFunction.getVariables()) {
        local.processFragments();
    }
}
Also used : MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) SourceSection(com.oracle.truffle.api.source.SourceSection) LLVMSourceFunctionType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceFunctionType) Source(com.oracle.truffle.api.source.Source)

Example 13 with LLVMSourceLocation

use of com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation 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 LLVMSourceLocation

use of com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation 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 15 with LLVMSourceLocation

use of com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation in project sulong by graalvm.

the class LLVMBasicBlockNode method getLastAvailableSourceLocation.

private LLVMSourceLocation getLastAvailableSourceLocation(int i) {
    CompilerAsserts.neverPartOfCompilation();
    for (int j = i; j >= 0; j--) {
        LLVMExpressionNode node = statements[j];
        if (node instanceof InstrumentableNode.WrapperNode) {
            node = (LLVMExpressionNode) ((InstrumentableNode.WrapperNode) node).getDelegateNode();
        }
        LLVMSourceLocation location = node.getSourceLocation();
        if (location != null) {
            return location;
        }
    }
    return null;
}
Also used : LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)

Aggregations

LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)15 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)5 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)5 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)5 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)5 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)5 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)5 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)5 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)5 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)5 Type (com.oracle.truffle.llvm.runtime.types.Type)5 ArrayList (java.util.ArrayList)5 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)3 MDString (com.oracle.truffle.llvm.parser.metadata.MDString)3 List (java.util.List)3 SourceSection (com.oracle.truffle.api.source.SourceSection)2 LLVMFunctionStartNode (com.oracle.truffle.llvm.nodes.func.LLVMFunctionStartNode)2