private void printAllRegions() { for (BasicBlock bb1 : cfg.getBasicBlocks()) { for (BasicBlock bb2 : cfg.getBasicBlocks()) { if (!bb1.equals(bb2) && getDomInfo().dominates(bb1, bb2)) { if (isRegion(bb1, bb2)) { LOGGER.debug("REGION {},{}", bb1, bb2); } } } } }
public void writeInline(EmitContext emitContext, InstructionAdapter mv) { // Last check for assumption violations types.verifyFunctionAssumptions(runtimeState); Label exitLabel = new Label(); for (BasicBlock basicBlock : cfg.getBasicBlocks()) { if (basicBlock != cfg.getEntry() && basicBlock != cfg.getExit()) { for (IRLabel label : basicBlock.getLabels()) { mv.visitLabel(emitContext.getAsmLabel(label)); } for (Statement stmt : basicBlock.getStatements()) { try { if (stmt instanceof ReturnStatement) { // Instead of returning, just push the return value on the stack // and jump to the exit point for the function. stmt.getRHS().load(emitContext, mv); mv.goTo(exitLabel); } else { stmt.emit(emitContext, mv); } } catch (NotCompilableException e) { throw e; } catch (Exception e) { throw new InternalCompilerException("Exception compiling statement " + stmt, e); } } } } mv.mark(exitLabel); }
@Test public void forLoop() { IRBody block = buildBody("y <- 0; for(i in 1:10) y <- y + i; sqrt(y + 3 * x)"); System.out.println(block); ControlFlowGraph cfg = new ControlFlowGraph(block); System.out.println(cfg); List<BasicBlock> basicBlocks = cfg.getBasicBlocks(); assertThat(basicBlocks.size(), equalTo(7)); }
@Test public void singleBlock() { IRBody block = buildBody("y<-x+1;z<-3; 4"); ControlFlowGraph cfg = new ControlFlowGraph(block); System.out.println(cfg); List<BasicBlock> basicBlocks = cfg.getBasicBlocks(); assertThat(basicBlocks.size(), equalTo(3)); // entry + 1 + exit = 3 assertThat(basicBlocks.get(1).getStatements().size(), equalTo(block.getStatements().size())); }