Search in sources :

Example 1 with SSAValue

use of com.oracle.truffle.llvm.runtime.types.symbols.SSAValue in project graal by oracle.

the class LLVMDebuggerScopeFactory method getIRLevelEntries.

@TruffleBoundary
private static LLVMDebuggerScopeEntries getIRLevelEntries(Frame frame, LLVMContext context, DataLayout dataLayout) {
    FrameDescriptor desc = frame.getFrameDescriptor();
    if (frame == null || desc.getNumberOfSlots() == 0) {
        return LLVMDebuggerScopeEntries.EMPTY_SCOPE;
    }
    final LLVMDebuggerScopeEntries entries = new LLVMDebuggerScopeEntries();
    for (int slot = 0; slot < desc.getNumberOfSlots(); slot++) {
        if (desc.getSlotInfo(slot) instanceof SSAValue) {
            SSAValue stackValue = (SSAValue) desc.getSlotInfo(slot);
            String identifier = stackValue.getName();
            Object slotValue = frame.getValue(slot);
            if (slotValue == null) {
                // slots are null if they are cleared by LLVMFrameNuller
                slotValue = "<unavailable>";
            }
            Object value = CommonNodeFactory.toGenericDebuggerValue(stackValue.getType(), slotValue, dataLayout);
            entries.add(convertIdentifier(identifier, context), value);
        }
    }
    return entries;
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) SSAValue(com.oracle.truffle.llvm.runtime.types.symbols.SSAValue) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with SSAValue

use of com.oracle.truffle.llvm.runtime.types.symbols.SSAValue in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method extractNulledValue.

private LLVMExpressionNode extractNulledValue(SSAValue slot) {
    assert slot != null;
    if (instructionNodes.isEmpty()) {
        return null;
    }
    SSAValue target = instructionTargets.get(instructionTargets.size() - 1);
    if (target == slot) {
        LLVMExpressionNode expression = (LLVMExpressionNode) instructionNodes.get(instructionNodes.size() - 1);
        instructionNodes.remove(instructionNodes.size() - 1);
        instructionTargets.remove(instructionTargets.size() - 1);
        return expression;
    }
    return null;
}
Also used : LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) SSAValue(com.oracle.truffle.llvm.runtime.types.symbols.SSAValue)

Example 3 with SSAValue

use of com.oracle.truffle.llvm.runtime.types.symbols.SSAValue in project graal by oracle.

the class LazyToTruffleConverterImpl method generateCallTarget.

private RootCallTarget generateCallTarget() {
    LLVMContext context = LLVMLanguage.getContext();
    NodeFactory nodeFactory = runtime.getNodeFactory();
    OptionValues options = context.getEnv().getOptions();
    boolean printAST = false;
    if (LLVMContext.printAstEnabled()) {
        String printASTOption = options.get(SulongEngineOption.PRINT_AST_FILTER);
        if (!printASTOption.isEmpty()) {
            String[] regexes = printASTOption.split(",");
            for (String regex : regexes) {
                if (method.getName().matches(regex)) {
                    printAST = true;
                    LLVMContext.printAstLog("========== " + method.getName());
                    break;
                }
            }
        }
    }
    doParse();
    // prepare the phis
    final Map<InstructionBlock, List<Phi>> phis = LLVMPhiManager.getPhis(method);
    LLVMLivenessAnalysisResult liveness = LLVMLivenessAnalysis.computeLiveness(phis, method);
    // setup the frameDescriptor
    FrameDescriptor.Builder builder = FrameDescriptor.newBuilder();
    nodeFactory.addStackSlots(builder);
    UniquesRegion uniquesRegion = new UniquesRegion();
    GetStackSpaceFactory getStackSpaceFactory = GetStackSpaceFactory.createGetUniqueStackSpaceFactory(uniquesRegion);
    LLVMSymbolReadResolver symbols = new LLVMSymbolReadResolver(runtime, builder, getStackSpaceFactory, dataLayout, options.get(SulongEngineOption.LL_DEBUG));
    int exceptionSlot = builder.addSlot(FrameSlotKind.Object, null, null);
    for (FunctionParameter parameter : method.getParameters()) {
        symbols.findOrAddFrameSlot(parameter);
    }
    HashSet<SSAValue> neededForDebug = getDebugValues();
    // create blocks and translate instructions
    boolean initDebugValues = true;
    LLVMRuntimeDebugInformation info = new LLVMRuntimeDebugInformation(method.getBlocks().size());
    LLVMBasicBlockNode[] blockNodes = new LLVMBasicBlockNode[method.getBlocks().size()];
    for (InstructionBlock block : method.getBlocks()) {
        List<Phi> blockPhis = phis.get(block);
        ArrayList<LLVMLivenessAnalysis.NullerInformation> blockNullerInfos = liveness.getNullableWithinBlock()[block.getBlockIndex()];
        LLVMBitcodeInstructionVisitor visitor = new LLVMBitcodeInstructionVisitor(exceptionSlot, uniquesRegion, blockPhis, method.getParameters().size(), symbols, context, blockNullerInfos, neededForDebug, dataLayout, nodeFactory);
        if (initDebugValues) {
            for (SourceVariable variable : method.getSourceFunction().getVariables()) {
                if (variable.hasFragments()) {
                    visitor.initializeAggregateLocalVariable(variable);
                }
            }
            initDebugValues = false;
        }
        for (int i = 0; i < block.getInstructionCount(); i++) {
            visitor.setInstructionIndex(i);
            block.getInstruction(i).accept(visitor);
        }
        LLVMStatementNode[] nodes = visitor.finish();
        info.setBlockDebugInfo(block.getBlockIndex(), visitor.getDebugInfo());
        blockNodes[block.getBlockIndex()] = LLVMBasicBlockNode.createBasicBlockNode(options, nodes, visitor.getControlFlowNode(), block.getBlockIndex(), block.getName());
    }
    for (int j = 0; j < blockNodes.length; j++) {
        int[] nullableBeforeBlock = getNullableFrameSlots(liveness.getFrameSlots(), liveness.getNullableBeforeBlock()[j]);
        int[] nullableAfterBlock = getNullableFrameSlots(liveness.getFrameSlots(), liveness.getNullableAfterBlock()[j]);
        blockNodes[j].setNullableFrameSlots(nullableBeforeBlock, nullableAfterBlock);
    }
    info.setBlocks(blockNodes);
    int loopSuccessorSlot = -1;
    if (options.get(SulongEngineOption.OSR_MODE) == SulongEngineOption.OSRMode.CFG && !options.get(SulongEngineOption.AOTCacheStore)) {
        LLVMControlFlowGraph cfg = new LLVMControlFlowGraph(method.getBlocks().toArray(FunctionDefinition.EMPTY));
        cfg.build();
        if (cfg.isReducible() && cfg.getCFGLoops().size() > 0) {
            loopSuccessorSlot = builder.addSlot(FrameSlotKind.Int, null, null);
            resolveLoops(blockNodes, cfg, loopSuccessorSlot, exceptionSlot, info, options);
        }
    }
    LLVMSourceLocation location = method.getLexicalScope();
    rootFunction.setSourceLocation(LLVMSourceLocation.orDefault(location));
    LLVMStatementNode[] copyArgumentsToFrameArray = copyArgumentsToFrame(symbols).toArray(LLVMStatementNode.NO_STATEMENTS);
    FrameDescriptor frame = builder.build();
    RootNode rootNode = nodeFactory.createFunction(exceptionSlot, blockNodes, uniquesRegion, copyArgumentsToFrameArray, frame, loopSuccessorSlot, info, method.getName(), method.getSourceName(), method.getParameters().size(), source, location, rootFunction);
    method.onAfterParse();
    if (printAST) {
        printCompactTree(rootNode);
        LLVMContext.printAstLog("");
    }
    return rootNode.getCallTarget();
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) OptionValues(org.graalvm.options.OptionValues) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) GetStackSpaceFactory(com.oracle.truffle.llvm.runtime.GetStackSpaceFactory) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) SourceVariable(com.oracle.truffle.llvm.parser.metadata.debuginfo.SourceVariable) LLVMControlFlowGraph(com.oracle.truffle.llvm.parser.util.LLVMControlFlowGraph) LLVMStatementNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode) List(java.util.List) ArrayList(java.util.ArrayList) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock) FunctionParameter(com.oracle.truffle.llvm.parser.model.functions.FunctionParameter) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) LLVMLivenessAnalysisResult(com.oracle.truffle.llvm.parser.LLVMLivenessAnalysis.LLVMLivenessAnalysisResult) LLVMBitcodeInstructionVisitor(com.oracle.truffle.llvm.parser.nodes.LLVMBitcodeInstructionVisitor) SSAValue(com.oracle.truffle.llvm.runtime.types.symbols.SSAValue) UniquesRegion(com.oracle.truffle.llvm.runtime.memory.LLVMStack.UniquesRegion) CommonNodeFactory(com.oracle.truffle.llvm.runtime.CommonNodeFactory) NodeFactory(com.oracle.truffle.llvm.runtime.NodeFactory) LLVMRuntimeDebugInformation(com.oracle.truffle.llvm.parser.nodes.LLVMRuntimeDebugInformation) LLVMBasicBlockNode(com.oracle.truffle.llvm.runtime.nodes.base.LLVMBasicBlockNode)

Example 4 with SSAValue

use of com.oracle.truffle.llvm.runtime.types.symbols.SSAValue in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method finish.

public LLVMStatementNode[] finish() {
    for (int i = 0; i < instructionNodes.size(); i++) {
        LLVMNode node = instructionNodes.get(i);
        SSAValue target = instructionTargets.get(i);
        if (target == null) {
            assert node instanceof LLVMStatementNode;
        } else {
            assert node instanceof LLVMExpressionNode;
            instructionNodes.set(i, CommonNodeFactory.createFrameWrite(target.getType(), (LLVMExpressionNode) node, symbols.findOrAddFrameSlot(target)));
        }
    }
    return instructionNodes.toArray(LLVMStatementNode.NO_STATEMENTS);
}
Also used : LLVMStatementNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) SSAValue(com.oracle.truffle.llvm.runtime.types.symbols.SSAValue) LLVMNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode)

Example 5 with SSAValue

use of com.oracle.truffle.llvm.runtime.types.symbols.SSAValue in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method handleDebugIntrinsic.

private void handleDebugIntrinsic(SymbolImpl value, SourceVariable variable, MDExpression expression, long index, boolean isDeclaration) {
    if (index != 0) {
        // this is unsupported, it doesn't appear in LLVM 3.8+
        return;
    }
    int valueFrameSlot = -1;
    Object valueObject = null;
    if (value instanceof UndefinedConstant) {
        valueObject = symbols.resolve(new NullConstant(MetaType.DEBUG));
    } else if (value instanceof AbstractConstant) {
        valueObject = symbols.resolve(value);
    } else if (value instanceof GlobalValueSymbol) {
        valueObject = symbols.resolve(value);
    } else if (value instanceof SSAValue) {
        valueFrameSlot = symbols.findOrAddFrameSlot((SSAValue) value);
    } else {
        return;
    }
    if (valueObject == null && valueFrameSlot == -1) {
        return;
    }
    int partIndex = -1;
    int[] clearParts = null;
    if (ValueFragment.describesFragment(expression)) {
        ValueFragment fragment = ValueFragment.parse(expression);
        List<ValueFragment> siblings = variable.getFragments();
        List<Integer> clearSiblings = new ArrayList<>(siblings.size());
        partIndex = ValueFragment.getPartIndex(fragment, siblings, clearSiblings);
        if (!clearSiblings.isEmpty()) {
            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 LLVMParserException("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;
        }
    }
    boolean mustDereference = isDeclaration || mustDereferenceValue(expression, variable.getSourceType(), value);
    if (clearParts != null && clearParts.length != 0) {
        debugInfo.add(new ClearLocalVariableParts(instructionNodes.size(), variable.getSymbol(), clearParts));
    }
    if (partIndex < 0 && clearParts == null) {
        debugInfo.add(new SimpleLocalVariable(instructionNodes.size(), mustDereference, valueObject, valueFrameSlot, variable.getSymbol()));
    } else if (partIndex >= 0) {
        debugInfo.add(new SetLocalVariablePart(instructionNodes.size(), mustDereference, valueObject, valueFrameSlot, variable.getSymbol(), partIndex));
    }
}
Also used : UndefinedConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant) ArrayList(java.util.ArrayList) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) SSAValue(com.oracle.truffle.llvm.runtime.types.symbols.SSAValue) SetLocalVariablePart(com.oracle.truffle.llvm.parser.nodes.LLVMRuntimeDebugInformation.SetLocalVariablePart) SimpleLocalVariable(com.oracle.truffle.llvm.parser.nodes.LLVMRuntimeDebugInformation.SimpleLocalVariable) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) AbstractConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.AbstractConstant) ClearLocalVariableParts(com.oracle.truffle.llvm.parser.nodes.LLVMRuntimeDebugInformation.ClearLocalVariableParts) ValueFragment(com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Aggregations

SSAValue (com.oracle.truffle.llvm.runtime.types.symbols.SSAValue)6 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)2 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)2 LLVMStatementNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode)2 ArrayList (java.util.ArrayList)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 LLVMLivenessAnalysisResult (com.oracle.truffle.llvm.parser.LLVMLivenessAnalysis.LLVMLivenessAnalysisResult)1 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)1 SourceVariable (com.oracle.truffle.llvm.parser.metadata.debuginfo.SourceVariable)1 ValueFragment (com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment)1 InstructionBlock (com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)1 FunctionParameter (com.oracle.truffle.llvm.parser.model.functions.FunctionParameter)1 AbstractConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.AbstractConstant)1 NullConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant)1 UndefinedConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant)1 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)1 LLVMBitcodeInstructionVisitor (com.oracle.truffle.llvm.parser.nodes.LLVMBitcodeInstructionVisitor)1 LLVMRuntimeDebugInformation (com.oracle.truffle.llvm.parser.nodes.LLVMRuntimeDebugInformation)1 ClearLocalVariableParts (com.oracle.truffle.llvm.parser.nodes.LLVMRuntimeDebugInformation.ClearLocalVariableParts)1