Package org.renjin.compiler.cfg

Examples of org.renjin.compiler.cfg.ControlFlowGraph


public class SsaTransformTest extends CompilerTestCase {

  @Test
  public void cytronSsa() throws IOException {
    IRBody block = parseCytron();
    ControlFlowGraph cfg = new ControlFlowGraph(block);

    Iterable<BasicBlock> assignmentsToK = Iterables.filter(cfg.getBasicBlocks(),
        CfgPredicates.containsAssignmentTo(new EnvironmentVariable("K")));
   
    assertThat(Iterables.size(assignmentsToK), equalTo(3));
   
   
    DominanceTree dtree = new DominanceTree(cfg);
    System.out.println(dtree);
   
    SsaTransformer transformer = new SsaTransformer(cfg, dtree);
    transformer.transform();
   
    // See Figure 6 in
    // http://www.cs.utexas.edu/~pingali/CS380C/2010/papers/ssaCytron.pdf
   
   
    // just before branching in basic block #2,
    // we need phi functions for all 4 variables
   
    BasicBlock bb2 = cfg.getBasicBlocks().get(1);
    assertThat(bb2.getStatements().size(), equalTo(5));
  
    System.out.println(cfg);
  }
View Full Code Here


    IRBody block = buildScope("for(i in 1:10) { n<-x[i]; print(n); }");
   
    System.out.println(block);
   
   
    ControlFlowGraph cfg = new ControlFlowGraph(block);
   
  
    DominanceTree dtree = new DominanceTree(cfg);
   
    System.out.println("CFG:");
    System.out.println(cfg.getGraph());
   
    System.out.println("Dominance Tree:")
    System.out.println(dtree);
   
    SsaTransformer transformer = new SsaTransformer(cfg, dtree);
View Full Code Here

    IRFunctionTable functionTable = new IRFunctionTable();
    IRBody block = new IRBodyBuilder(functionTable).build(ast);

    System.out.println(block);
   
    final ControlFlowGraph cfg = new ControlFlowGraph(block);
  
    System.out.println(cfg);
   
   
    JFrame frame = new JFrame("Simple Graph View");
View Full Code Here

public class ControlFlowGraphTest extends CompilerTestCase {

  @Test
  public void singleBlock() {
    IRBody block = buildScope("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))// 1 + exit + entry = 3
    assertThat(basicBlocks.get(0).getStatements().size(), equalTo(block.getStatements().size()));
  }
View Full Code Here

  public void forLoop() {
    IRBody block = buildScope("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.getGraph());
    System.out.println(cfg);

    List<BasicBlock> basicBlocks = cfg.getBasicBlocks();
    assertThat(basicBlocks.size(), equalTo(7));
  }
View Full Code Here

//         true,    //L5   14: _t2 := NULL
//        
//         true    //L1   15: return _t2
//      }));
//   
    ControlFlowGraph cfg = new ControlFlowGraph(block);
   
    System.out.println(cfg);
   
  }
View Full Code Here

  }
 
  @Test
  public void cytron() throws IOException {
    IRBody block = parseCytron();
    ControlFlowGraph cfg = new ControlFlowGraph(block);
    List<BasicBlock> bb = cfg.getLiveBasicBlocks();
   
    // see Figure 5 in
    // http://www.cs.utexas.edu/~pingali/CS380C/2010/papers/ssaCytron.pdf
   
    assertThat(cfg.getGraph().getSuccessors(bb.get(0)), itemsEqualTo(bb.get(1)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(1)), itemsEqualTo(bb.get(2), bb.get(6)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(2)), itemsEqualTo(bb.get(3), bb.get(4)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(3)), itemsEqualTo(bb.get(5)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(4)), itemsEqualTo(bb.get(5)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(5)), itemsEqualTo(bb.get(7)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(6)), itemsEqualTo(bb.get(7)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(7)), itemsEqualTo(bb.get(8)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(8)), itemsEqualTo(bb.get(9), bb.get(10)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(9)), itemsEqualTo(bb.get(10)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(10)), itemsEqualTo(bb.get(8),bb.get(11)));
    assertThat(cfg.getGraph().getSuccessors(bb.get(11)), itemsEqualTo(bb.get(12),bb.get(1)));
  }
View Full Code Here

  @Test
  public void dataframe() throws IOException {
   IRBody body = buildScope(Resources.toString(
       getClass().getResource("dataframe.test.R"), Charsets.UTF_8));
   ControlFlowGraph cfg = new ControlFlowGraph(body);
  }
View Full Code Here


  @Test
  public void immediateDominators() {
    IRBody block = buildScope("y<-1; if(q) y<-y+1 else y<-4; y");
    ControlFlowGraph cfg = new ControlFlowGraph(block);
   
    System.out.println(cfg);
   
    BasicBlock bb0 = cfg.getBasicBlocks().get(0); // y <- 1; if q goto BB1 else BB2
    BasicBlock bb1 = cfg.getBasicBlocks().get(1); // y <- y + 1
    BasicBlock bb2 = cfg.getBasicBlocks().get(2); // y <- 4
    BasicBlock bb3 = cfg.getBasicBlocks().get(3); // return y;
   
    DominanceTree domTree = new DominanceTree(cfg);
    assertThat(domTree.getImmediateDominator(bb1), equalTo(bb0));
    assertThat(domTree.getImmediateDominator(bb2), equalTo(bb0));
    assertThat(domTree.getImmediateDominator(bb3), equalTo(bb0));
    assertThat(domTree.getImmediateDominator(cfg.getExit()), equalTo(cfg.getEntry()));
  }
View Full Code Here

  }
 
  @Test
  public void dominanceFrontier() throws IOException {
    IRBody block = parseCytron();
    ControlFlowGraph cfg = new ControlFlowGraph(block);
    List<BasicBlock> bb = cfg.getLiveBasicBlocks();
    DominanceTree dtree = new DominanceTree(cfg);

    // See Figure 9 in
    // http://www.cs.utexas.edu/~pingali/CS380C/2010/papers/ssaCytron.pdf
   
    assertThat(dtree.getFrontier(bb.get(1)), itemsEqualTo(bb.get(1), cfg.getExit()));
    assertThat(dtree.getFrontier(bb.get(2)), itemsEqualTo(bb.get(7)));
    assertThat(dtree.getFrontier(bb.get(3)), itemsEqualTo(bb.get(5)));
    assertThat(dtree.getFrontier(bb.get(4)), itemsEqualTo(bb.get(5)));
    assertThat(dtree.getFrontier(bb.get(5)), itemsEqualTo(bb.get(7)));
    assertThat(dtree.getFrontier(bb.get(6)), itemsEqualTo(bb.get(7)));
    assertThat(dtree.getFrontier(bb.get(7)), itemsEqualTo(bb.get(1), cfg.getExit()));
    assertThat(dtree.getFrontier(bb.get(8)), itemsEqualTo(bb.get(1), bb.get(8), cfg.getExit()));
    assertThat(dtree.getFrontier(bb.get(9)), itemsEqualTo(bb.get(10)));
    assertThat(dtree.getFrontier(bb.get(10)), itemsEqualTo(bb.get(1), bb.get(8), cfg.getExit()));
    assertThat(dtree.getFrontier(bb.get(11)), itemsEqualTo(bb.get(1), cfg.getExit()));
  }
View Full Code Here

TOP

Related Classes of org.renjin.compiler.cfg.ControlFlowGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.