if edge_visited.contains(from, to){ continue; } edge_visited.inset(from,to) for inst in to { if(inst.isPhi()){ visit_phi(inst) }else{ visit_inst(inst) } } } }
remove all the inst with Top lattice }
void visit_phi(PhiNode* phi){ auto old = lattice_map.get(phi)
auto (v1, bb1) = phi.incomings().begin() new_cell = Top if edge_visited.contains(bb1, phi->getParent()) { new_cell = lattice_map.get(v1) }
for (v, bb) in phi.incomings().else(){ celli = Top if(edge_visited.contains(bb, phi->getParent()) ){ celli = lattice_map.get(v) new_cell = meet(new_cell, celli) } } }
void visit_inst(inst){ old = lattice_map.get(inst) switch inst.kind(){ case BinOp:{ a = lattice_map.get(inst.getLHS()) b = lattice_map.get(inst.getRHS()) new_cell = eval(a,b, inst) if new_cell != old { lattice_map[inst] = new_cell for u in inst.getUsers(){ instList.push(u) } } break; } case UnaryOp:{ a = lattice_map.get(inst.getOp()) res = evalExpr(a) if( a != old ){ lattice_map[inst] = a for u in inst.getUsers(){ instList.push(u) } } break; } case Branch { auto succ = inst.getSucc() for i in succ{ if edge_visited.contains(inst.getParent(), i){ continue; } edgeList.push(inst.getParent(), i) for phi in i.phis(){ visit_phi(phi) } } } } }