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);
}
}
}
}
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;
}
Aggregations