use of com.oracle.truffle.llvm.parser.util.LLVMControlFlowGraph.CFGBlock 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;
}
}
}
Aggregations