Search in sources :

Example 1 with CFGLoop

use of com.oracle.truffle.llvm.parser.util.LLVMControlFlowGraph.CFGLoop in project graal by oracle.

the class LazyToTruffleConverterImpl method resolveLoops.

private void resolveLoops(LLVMBasicBlockNode[] nodes, LLVMControlFlowGraph cfg, int loopSuccessorSlot, int exceptionSlot, LLVMRuntimeDebugInformation info, OptionValues options) {
    // The original array is needed to access the frame nuller information for outgoing control
    // flow egdes
    LLVMBasicBlockNode[] originalBodyNodes = nodes.clone();
    info.setBlocks(originalBodyNodes);
    for (CFGLoop loop : cfg.getCFGLoops()) {
        int headerId = loop.getHeader().id;
        int[] indexMapping = new int[nodes.length];
        Arrays.fill(indexMapping, -1);
        List<LLVMStatementNode> bodyNodes = new ArrayList<>();
        // add header to body nodes
        LLVMBasicBlockNode header = nodes[headerId];
        bodyNodes.add(header);
        indexMapping[headerId] = 0;
        // add body nodes
        int i = 1;
        for (CFGBlock block : loop.getBody()) {
            bodyNodes.add(nodes[block.id]);
            indexMapping[block.id] = i++;
        }
        int[] loopSuccessors = loop.getSuccessorIDs();
        RepeatingNode loopBody = runtime.getNodeFactory().createLoopDispatchNode(exceptionSlot, Collections.unmodifiableList(bodyNodes), originalBodyNodes, headerId, indexMapping, loopSuccessors, loopSuccessorSlot);
        LLVMControlFlowNode loopNode = runtime.getNodeFactory().createLoop(loopBody, loopSuccessors);
        // replace header block with loop node
        nodes[headerId] = LLVMBasicBlockNode.createBasicBlockNode(options, new LLVMStatementNode[0], loopNode, headerId, "loopAt" + headerId);
        nodes[headerId].setNullableFrameSlots(header.nullableBefore, header.nullableAfter);
        // remove inner loops to reduce number of nodes
        for (CFGLoop innerLoop : loop.getInnerLoops()) {
            nodes[innerLoop.getHeader().id] = null;
        }
    }
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) CFGBlock(com.oracle.truffle.llvm.parser.util.LLVMControlFlowGraph.CFGBlock) LLVMStatementNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode) ArrayList(java.util.ArrayList) LLVMBasicBlockNode(com.oracle.truffle.llvm.runtime.nodes.base.LLVMBasicBlockNode) CFGLoop(com.oracle.truffle.llvm.parser.util.LLVMControlFlowGraph.CFGLoop) RepeatingNode(com.oracle.truffle.api.nodes.RepeatingNode)

Aggregations

RepeatingNode (com.oracle.truffle.api.nodes.RepeatingNode)1 CFGBlock (com.oracle.truffle.llvm.parser.util.LLVMControlFlowGraph.CFGBlock)1 CFGLoop (com.oracle.truffle.llvm.parser.util.LLVMControlFlowGraph.CFGLoop)1 LLVMControlFlowNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode)1 LLVMStatementNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode)1 LLVMBasicBlockNode (com.oracle.truffle.llvm.runtime.nodes.base.LLVMBasicBlockNode)1 ArrayList (java.util.ArrayList)1