}
// copy propagation
for (Statement s : new LinkedHashSet<Statement>(graph.getNodes())) {
if (s instanceof VarStm) {
VarStm vs = (VarStm)s;
if (graph.getInEdges(vs).size() == 1) {
Assignment pred = (Assignment)(graph.getInEdges(vs).iterator().next()).getFrom();
if (graph.getOutEdges(pred).size()==1) {
// variable assignment with unique predecessor node that has no other successors - bypass this assignment
pred.setDest(vs.getDest());
for (Edge<Statement,VariableFilter> e : graph.getOutEdges(vs))
graph.addEdge(pred, e.getTo(), e.getData()); // XXX: ok to lose some edge info?
graph.removeNode(vs);
}
} else if (graph.getOutEdges(vs).size() == 1) {
Statement succ = graph.getOutEdges(vs).iterator().next().getTo();
if (graph.getInEdges(succ).size()==1) { // TODO: copy propagation could be improved by not requiring "no other predecessors"
// variable assignment with unique successor node that has no other predecessors - bypass this assignment
final Variable vsrc = vs.getSource();
succ.visitBy(new StatementVisitor() {
public void visitAnalyzeStm(AnalyzeStm s) {
s.setBase(vsrc);
}