Search in sources :

Example 11 with BytecodeOpcodeAddress

use of de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress 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);
}
Also used : ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) Program(de.mirkosertic.bytecoder.ssa.Program) GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) Relooper(de.mirkosertic.bytecoder.relooper.Relooper) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Example 12 with BytecodeOpcodeAddress

use of de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress 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);
}
Also used : ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) Program(de.mirkosertic.bytecoder.ssa.Program) GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Example 13 with BytecodeOpcodeAddress

use of de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress in project Bytecoder by mirkosertic.

the class RelooperTest method testSwitchCase.

@Test
public void testSwitchCase() {
    Program theProgram = new Program();
    ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
    RegionNode theNode1 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
    RegionNode theNode2 = theGraph.createAt(new BytecodeOpcodeAddress(10), RegionNode.BlockType.NORMAL);
    theNode2.getExpressions().add(new ReturnExpression());
    RegionNode theNode3 = theGraph.createAt(new BytecodeOpcodeAddress(20), RegionNode.BlockType.NORMAL);
    theNode3.getExpressions().add(new ReturnExpression());
    RegionNode theNode4 = theGraph.createAt(new BytecodeOpcodeAddress(30), RegionNode.BlockType.NORMAL);
    theNode4.getExpressions().add(new ReturnExpression());
    theNode1.addSuccessor(theNode2);
    theNode1.addSuccessor(theNode3);
    theNode1.addSuccessor(theNode4);
    theGraph.calculateReachabilityAndMarkBackEdges();
    Relooper theRelooper = new Relooper();
    Relooper.Block theBlock = theRelooper.reloop(theGraph);
    theRelooper.debugPrint(System.out, theBlock);
}
Also used : ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) Program(de.mirkosertic.bytecoder.ssa.Program) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Example 14 with BytecodeOpcodeAddress

use of de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress 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);
}
Also used : ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) Program(de.mirkosertic.bytecoder.ssa.Program) GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Example 15 with BytecodeOpcodeAddress

use of de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress in project Bytecoder by mirkosertic.

the class RelooperTest method testNestedIfs.

@Test
public void testNestedIfs() {
    /**
     *        digraph CFG {
     *            N0 [shape=none, margin=0, label=<<table><tr><td> V 0</td><td> V 1</td><td> V 2</td><td> V 3</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td colspan="4"> Node at 0</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td>REFERENCE</td><td>FLOAT</td><td>FLOAT</td><td>FLOAT</td></tr></table>>];
     *            N0 ->    N39;
     *            N0 ->    N8;
     *            N8 [shape=none, margin=0, label=<<table><tr><td> V 0</td><td> V 1</td><td> V 2</td><td> V 3</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td colspan="4"> Node at 8</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td>REFERENCE</td><td>FLOAT</td><td>FLOAT</td><td>FLOAT</td></tr></table>>];
     *            N8 ->    N19;
     *            N8 ->    N39;
     *            N19 [shape=none, margin=0, label=<<table><tr><td> V 0</td><td> V 1</td><td> V 2</td></tr><tr><td>X</td><td>X</td><td>X</td></tr><tr><td colspan="3"> Node at 19</td></tr><tr><td>X</td><td>X</td><td>X</td></tr><tr><td>REFERENCE</td><td>FLOAT</td><td>FLOAT</td></tr></table>>];
     *            N19 ->    N39;
     *            N39 [shape=none, margin=0, label=<<table><tr><td colspan="0"> Node at 39</td></tr></table>>];
     *        }
     */
    Program theProgram = new Program();
    ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
    RegionNode theNode0 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
    RegionNode theNode8 = theGraph.createAt(new BytecodeOpcodeAddress(8), RegionNode.BlockType.NORMAL);
    RegionNode theNode19 = theGraph.createAt(new BytecodeOpcodeAddress(19), RegionNode.BlockType.NORMAL);
    RegionNode theNode39 = theGraph.createAt(new BytecodeOpcodeAddress(39), RegionNode.BlockType.NORMAL);
    theNode0.addSuccessor(theNode8);
    theNode0.addSuccessor(theNode39);
    theNode8.addSuccessor(theNode19);
    theNode8.addSuccessor(theNode39);
    theNode19.addSuccessor(theNode39);
    theGraph.calculateReachabilityAndMarkBackEdges();
    Relooper theRelooper = new Relooper();
    Relooper.Block theBlock = theRelooper.reloop(theGraph);
    theRelooper.debugPrint(System.out, theBlock);
}
Also used : Program(de.mirkosertic.bytecoder.ssa.Program) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Aggregations

BytecodeOpcodeAddress (de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress)15 Test (org.junit.Test)12 RegionNode (de.mirkosertic.bytecoder.ssa.RegionNode)9 ControlFlowGraph (de.mirkosertic.bytecoder.ssa.ControlFlowGraph)8 Program (de.mirkosertic.bytecoder.ssa.Program)8 GotoExpression (de.mirkosertic.bytecoder.ssa.GotoExpression)7 ReturnExpression (de.mirkosertic.bytecoder.ssa.ReturnExpression)6 BytecodeInstructionACONSTNULL (de.mirkosertic.bytecoder.core.BytecodeInstructionACONSTNULL)3 Address (de.mirkosertic.bytecoder.classlib.Address)2 VM (de.mirkosertic.bytecoder.classlib.VM)2 BytecodeArrayTypeRef (de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef)2 BytecodeBasicBlock (de.mirkosertic.bytecoder.core.BytecodeBasicBlock)2 BytecodeBootstrapMethod (de.mirkosertic.bytecoder.core.BytecodeBootstrapMethod)2 BytecodeBootstrapMethodsAttributeInfo (de.mirkosertic.bytecoder.core.BytecodeBootstrapMethodsAttributeInfo)2 BytecodeClassinfoConstant (de.mirkosertic.bytecoder.core.BytecodeClassinfoConstant)2 BytecodeConstant (de.mirkosertic.bytecoder.core.BytecodeConstant)2 BytecodeDoubleConstant (de.mirkosertic.bytecoder.core.BytecodeDoubleConstant)2 BytecodeFloatConstant (de.mirkosertic.bytecoder.core.BytecodeFloatConstant)2 BytecodeInstruction (de.mirkosertic.bytecoder.core.BytecodeInstruction)2 BytecodeInstructionALOAD (de.mirkosertic.bytecoder.core.BytecodeInstructionALOAD)2