Search in sources :

Example 6 with RegionNode

use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.

the class JSSSAWriter method print.

private void print(ResolveCallsiteObjectExpression aValue) {
    print("bytecoder.resolveStaticCallSiteObject(");
    print(JSWriterUtils.toClassName(aValue.getOwningClass().getThisInfo()));
    print(",'");
    print(aValue.getCallsiteId());
    println("', function() {");
    Program theProgram = aValue.getProgram();
    RegionNode theBootstrapCode = aValue.getBootstrapMethod();
    JSSSAWriter theNested = withDeeperIndent();
    for (Variable theVariable : theProgram.globalVariables()) {
        theNested.print("var ");
        theNested.print(theVariable.getName());
        theNested.println(" = null;");
    }
    theNested.writeExpressions(theBootstrapCode.getExpressions());
    print("})");
}
Also used : Program(de.mirkosertic.bytecoder.ssa.Program) Variable(de.mirkosertic.bytecoder.ssa.Variable) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode)

Example 7 with RegionNode

use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.

the class OpenCLWriter method print.

private void print(Relooper.MultipleBlock aMultiple) {
    OpenCLWriter theWriter = this;
    if (aMultiple.isLabelRequired()) {
        print("$");
        print(aMultiple.label().name());
        print(" : ");
        theWriter = theWriter.withDeeperIndent();
    }
    println("switch ($__label__) {");
    for (Relooper.Block theHandler : aMultiple.handlers()) {
        for (RegionNode theEntry : theHandler.entries()) {
            theWriter.print("case ");
            theWriter.print(theEntry.getStartAddress().getAddress());
            theWriter.println(" : ");
        }
        OpenCLWriter theHandlerWriter = theWriter.withDeeperIndent();
        theHandlerWriter.print(theHandler);
    }
    println("}");
    if (aMultiple.next() != null) {
        print("$");
        print(aMultiple.label().name());
        println("_next:");
        print(aMultiple.next());
    }
}
Also used : Relooper(de.mirkosertic.bytecoder.relooper.Relooper) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode)

Example 8 with RegionNode

use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.

the class InlineFinalNodesOptimizer method inline.

private void inline(Map<BytecodeOpcodeAddress, RegionNode> aFinalNodes, ExpressionList aList) {
    for (Expression theExpression : aList.toList()) {
        if (theExpression instanceof ExpressionListContainer) {
            ExpressionListContainer theContainer = (ExpressionListContainer) theExpression;
            for (ExpressionList theList : theContainer.getExpressionLists()) {
                inline(aFinalNodes, theList);
            }
        }
        if (theExpression instanceof GotoExpression) {
            GotoExpression theGoto = (GotoExpression) theExpression;
            RegionNode thePotentialFinal = aFinalNodes.get(theGoto.getJumpTarget());
            if (thePotentialFinal != null) {
                aList.replace(theExpression, thePotentialFinal.getExpressions());
            }
        }
    }
}
Also used : GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) Expression(de.mirkosertic.bytecoder.ssa.Expression) GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) ExpressionListContainer(de.mirkosertic.bytecoder.ssa.ExpressionListContainer) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) ExpressionList(de.mirkosertic.bytecoder.ssa.ExpressionList)

Example 9 with RegionNode

use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.

the class InlineGotoOptimizer method performNodeInlining.

private boolean performNodeInlining(ControlFlowGraph aGraph, RegionNode aNode, ExpressionList aList, List<BytecodeOpcodeAddress> aJumpTargets) {
    for (Expression theExpression : aList.toList()) {
        if (theExpression instanceof ExpressionListContainer) {
            ExpressionListContainer theContainer = (ExpressionListContainer) theExpression;
            for (ExpressionList theList : theContainer.getExpressionLists()) {
                if (performNodeInlining(aGraph, aNode, theList, aJumpTargets)) {
                    return true;
                }
            }
        }
        if (theExpression instanceof GotoExpression) {
            GotoExpression theGOTO = (GotoExpression) theExpression;
            RegionNode theTargetNode = aGraph.nodeStartingAt(theGOTO.getJumpTarget());
            if (theTargetNode.isStrictlyDominatedBy(aNode)) {
                BytecodeOpcodeAddress theJumpTarget = theGOTO.getJumpTarget();
                int theCount = 0;
                for (BytecodeOpcodeAddress theEntry : aJumpTargets) {
                    if (theEntry.equals(theJumpTarget)) {
                        theCount++;
                    }
                }
                if (theCount == 1) {
                    // Node can be inlined
                    aGraph.delete(theTargetNode);
                    aList.replace(theGOTO, theTargetNode.getExpressions());
                    aNode.inheritSuccessorsOf(theTargetNode);
                    for (RegionNode theNode : aGraph.getKnownNodes()) {
                        recomputeGotos(theNode.getExpressions(), theTargetNode.getStartAddress(), aNode.getStartAddress());
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) Expression(de.mirkosertic.bytecoder.ssa.Expression) GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) ExpressionListContainer(de.mirkosertic.bytecoder.ssa.ExpressionListContainer) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) ExpressionList(de.mirkosertic.bytecoder.ssa.ExpressionList)

Example 10 with RegionNode

use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.

the class RedundantAssignmentOptimizerTest method testBinaryOptimization.

@Test
public void testBinaryOptimization() {
    Program theProgram = new Program();
    ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
    RegionNode theStart = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
    ExpressionList theExpressions = theStart.getExpressions();
    Variable theVariable1 = new Variable(TypeRef.Native.INT, "var1");
    Variable theVariable2 = new Variable(TypeRef.Native.INT, "var2");
    IntegerValue theInt1 = new IntegerValue(10);
    theVariable1.initializeWith(theInt1);
    theExpressions.add(new VariableAssignmentExpression(theVariable1, theInt1));
    IntegerValue theInt2 = new IntegerValue(20);
    theVariable2.initializeWith(theInt2);
    theExpressions.add(new VariableAssignmentExpression(theVariable2, theInt2));
    Variable theVariable3 = new Variable(TypeRef.Native.INT, "var3");
    BinaryExpression theBinary = new BinaryExpression(TypeRef.Native.INT, theVariable1, BinaryExpression.Operator.ADD, theVariable2);
    theVariable3.initializeWith(theBinary);
    theExpressions.add(new VariableAssignmentExpression(theVariable3, theBinary));
    theExpressions.add(new ReturnValueExpression(theVariable3));
    RedundantAssignmentOptimizer theOptimizer = new RedundantAssignmentOptimizer();
    theOptimizer.optimize(theGraph, null);
    System.out.println(theExpressions);
}
Also used : ReturnValueExpression(de.mirkosertic.bytecoder.ssa.ReturnValueExpression) Program(de.mirkosertic.bytecoder.ssa.Program) Variable(de.mirkosertic.bytecoder.ssa.Variable) BinaryExpression(de.mirkosertic.bytecoder.ssa.BinaryExpression) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) ExpressionList(de.mirkosertic.bytecoder.ssa.ExpressionList) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression) Test(org.junit.Test)

Aggregations

RegionNode (de.mirkosertic.bytecoder.ssa.RegionNode)20 Program (de.mirkosertic.bytecoder.ssa.Program)11 GotoExpression (de.mirkosertic.bytecoder.ssa.GotoExpression)10 BytecodeOpcodeAddress (de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress)9 ControlFlowGraph (de.mirkosertic.bytecoder.ssa.ControlFlowGraph)9 Test (org.junit.Test)9 ReturnExpression (de.mirkosertic.bytecoder.ssa.ReturnExpression)8 Relooper (de.mirkosertic.bytecoder.relooper.Relooper)6 ExpressionList (de.mirkosertic.bytecoder.ssa.ExpressionList)5 Expression (de.mirkosertic.bytecoder.ssa.Expression)4 ExpressionListContainer (de.mirkosertic.bytecoder.ssa.ExpressionListContainer)3 Variable (de.mirkosertic.bytecoder.ssa.Variable)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 BreakExpression (de.mirkosertic.bytecoder.ssa.BreakExpression)2 ContinueExpression (de.mirkosertic.bytecoder.ssa.ContinueExpression)2 IntegerValue (de.mirkosertic.bytecoder.ssa.IntegerValue)2 Export (de.mirkosertic.bytecoder.api.Export)1 ConstantPool (de.mirkosertic.bytecoder.backend.ConstantPool)1