Search in sources :

Example 1 with Edge

use of de.mirkosertic.bytecoder.graph.Edge in project Bytecoder by mirkosertic.

the class RedundantAssignmentOptimizer method visit.

@Override
protected void visit(ControlFlowGraph aGraph, ExpressionList aList, Expression aExpression, BytecodeLinkerContext aLinkerContext) {
    // Check if a variable assignment is before the current expression
    Expression theBefore = aList.predecessorOf(aExpression);
    if (theBefore instanceof VariableAssignmentExpression) {
        VariableAssignmentExpression theAssignment = (VariableAssignmentExpression) theBefore;
        Variable theVariable = theAssignment.getVariable();
        Value theValue = theAssignment.getValue();
        // Check if there is only one data flow
        List<Edge> theDataEdges = theVariable.outgoingEdges(DataFlowEdgeType.filter()).collect(Collectors.toList());
        if (theDataEdges.size() == 1) {
            List<Value> theIncomingData = aExpression.incomingDataFlows();
            if (theIncomingData.contains(theVariable)) {
                aExpression.replaceIncomingDataEdge(theVariable, theValue);
                aList.remove(theAssignment);
                aGraph.getProgram().deleteVariable(theVariable);
            }
        }
    }
}
Also used : Variable(de.mirkosertic.bytecoder.ssa.Variable) Expression(de.mirkosertic.bytecoder.ssa.Expression) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression) Value(de.mirkosertic.bytecoder.ssa.Value) Edge(de.mirkosertic.bytecoder.graph.Edge) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression)

Example 2 with Edge

use of de.mirkosertic.bytecoder.graph.Edge in project Bytecoder by mirkosertic.

the class Value method incomingDataFlowEdgesRecursive.

private List<Edge> incomingDataFlowEdgesRecursive(Set<Value> aAlreadyVisited) {
    List<Edge> theResult = new ArrayList<>();
    if (aAlreadyVisited.add(this)) {
        for (Edge theEdge : incomingDataFlowEdges()) {
            theResult.add(theEdge);
            Value theSource = (Value) theEdge.sourceNode();
            theResult.addAll(theSource.incomingDataFlowEdgesRecursive(aAlreadyVisited));
        }
    }
    return theResult;
}
Also used : ArrayList(java.util.ArrayList) Edge(de.mirkosertic.bytecoder.graph.Edge)

Aggregations

Edge (de.mirkosertic.bytecoder.graph.Edge)2 Expression (de.mirkosertic.bytecoder.ssa.Expression)1 Value (de.mirkosertic.bytecoder.ssa.Value)1 Variable (de.mirkosertic.bytecoder.ssa.Variable)1 VariableAssignmentExpression (de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression)1 ArrayList (java.util.ArrayList)1