use of de.mirkosertic.bytecoder.ssa.GotoExpression in project Bytecoder by mirkosertic.
the class InlineGotoOptimizerTest method testSimpleFlowTwoLevels.
@Test
public void testSimpleFlowTwoLevels() {
Program theProgram = new Program();
ControlFlowGraph theGraph = theProgram.getControlFlowGraph();
RegionNode theNode = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
RegionNode theNode1 = theGraph.createAt(new BytecodeOpcodeAddress(20), RegionNode.BlockType.NORMAL);
RegionNode theNode2 = theGraph.createAt(new BytecodeOpcodeAddress(40), RegionNode.BlockType.NORMAL);
theNode.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(20)));
theNode.addSuccessor(theNode1);
theNode1.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(40)));
theNode1.addSuccessor(theNode2);
theNode2.getExpressions().add(new ReturnExpression());
theGraph.calculateReachabilityAndMarkBackEdges();
InlineGotoOptimizer theOptimizer = new InlineGotoOptimizer();
theOptimizer.optimize(theGraph, null);
Assert.assertEquals(1, theGraph.getKnownNodes().size(), 0);
Assert.assertEquals(1, theGraph.getDominatedNodes().size(), 0);
Assert.assertTrue(theGraph.getKnownNodes().contains(theNode));
Assert.assertEquals(1, theNode.getExpressions().size(), 0);
Assert.assertTrue(theNode.getExpressions().toList().get(0) instanceof ReturnExpression);
Assert.assertEquals(0, theNode.getSuccessors().size(), 0);
Relooper theRelooper = new Relooper();
Relooper.Block theRoot = theRelooper.reloop(theGraph);
}
use of de.mirkosertic.bytecoder.ssa.GotoExpression in project Bytecoder by mirkosertic.
the class RelooperTest method testDirectFlow.
@Test
public void testDirectFlow() {
Program theProgram = new Program();
ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
RegionNode theNode1 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
theNode1.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(10)));
RegionNode theNode2 = theGraph.createAt(new BytecodeOpcodeAddress(10), RegionNode.BlockType.NORMAL);
theNode2.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(20)));
RegionNode theNode3 = theGraph.createAt(new BytecodeOpcodeAddress(20), RegionNode.BlockType.NORMAL);
theNode3.getExpressions().add(new ReturnExpression());
theNode1.addSuccessor(theNode2);
theNode2.addSuccessor(theNode3);
theGraph.calculateReachabilityAndMarkBackEdges();
Relooper theRelooper = new Relooper();
Relooper.Block theBlock = theRelooper.reloop(theGraph);
theRelooper.debugPrint(System.out, theBlock);
}
use of de.mirkosertic.bytecoder.ssa.GotoExpression in project Bytecoder by mirkosertic.
the class RelooperTest method testIf.
@Test
public void testIf() {
Program theProgram = new Program();
ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
RegionNode theNode1 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
theNode1.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(10)));
RegionNode theNode2 = theGraph.createAt(new BytecodeOpcodeAddress(10), RegionNode.BlockType.NORMAL);
theNode2.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(20)));
RegionNode theNode3 = theGraph.createAt(new BytecodeOpcodeAddress(20), RegionNode.BlockType.NORMAL);
theNode3.getExpressions().add(new ReturnExpression());
theNode1.addSuccessor(theNode2);
theNode1.addSuccessor(theNode3);
theNode2.addSuccessor(theNode3);
theGraph.calculateReachabilityAndMarkBackEdges();
Relooper theRelooper = new Relooper();
Relooper.Block theBlock = theRelooper.reloop(theGraph);
theRelooper.debugPrint(System.out, theBlock);
}
Aggregations