1 package Analysis.Loops;
4 import java.util.HashSet;
5 import java.util.Iterator;
7 public class DeadCode {
10 public void optimize(FlatMethod fm) {
11 UseDef ud=new UseDef(fm);
12 HashSet useful=new HashSet();
17 for(Iterator<FlatNode> it=fm.getNodeSet().iterator();it.hasNext();) {
18 FlatNode fn=it.next();
21 case FKind.FlatFieldNode:
22 case FKind.FlatSetFieldNode:
24 case FKind.FlatCastNode:
25 case FKind.FlatReturnNode:
26 case FKind.FlatCondBranch:
27 case FKind.FlatSetElementNode:
28 case FKind.FlatElementNode:
29 case FKind.FlatFlagActionNode:
30 case FKind.FlatCheckNode:
31 case FKind.FlatBackEdge:
32 case FKind.FlatTagDeclaration:
33 case FKind.FlatMethod:
34 case FKind.FlatAtomicEnterNode:
35 case FKind.FlatAtomicExitNode:
36 case FKind.FlatPrefetchNode:
37 case FKind.FlatSESEEnterNode:
38 case FKind.FlatSESEExitNode:
39 if (!useful.contains(fn)) {
44 case FKind.FlatOpNode:
45 FlatOpNode fon=(FlatOpNode)fn;
46 if (fon.getOp().getOp()==Operation.DIV||
47 fon.getOp().getOp()==Operation.MOD) {
48 if (!useful.contains(fn)) {
55 TempDescriptor[] writes=fn.writesTemps();
56 if (!useful.contains(fn))
57 for(int i=0;i<writes.length;i++) {
58 for(Iterator<FlatNode> uit=ud.useMap(fn,writes[i]).iterator();uit.hasNext();) {
59 FlatNode ufn=uit.next();
60 if (useful.contains(ufn)) {
71 //get rid of useless nodes
72 for(Iterator<FlatNode> it=fm.getNodeSet().iterator();it.hasNext();) {
73 FlatNode fn=it.next();
74 if (!useful.contains(fn)) {
75 //We have a useless node
76 FlatNode fnnext=fn.getNext(0);
77 for(int i=0;i<fn.numPrev();i++) {
78 FlatNode nprev=fn.getPrev(i);
79 for(int j=0;j<nprev.numNext();j++) {
80 if (nprev.getNext(j)==fn) {
81 nprev.setnext(j, fnnext);
82 fnnext.addPrev(nprev);
86 //fix up prev edge of fnnext
87 fnnext.removePrev(fn);