switch to spaces only..
[IRC.git] / Robust / src / Analysis / Loops / DeadCode.java
index 4df9eb4841f54fc3febfe0b52b1706ea71719771..c3ba42a01b541c733f946c46e242548e8ac02734 100644 (file)
@@ -13,82 +13,93 @@ public class DeadCode {
     boolean changed=true;
     while(changed) {
       changed=false;
-      nextfn:
-      for(Iterator<FlatNode> it=fm.getNodeSet().iterator();it.hasNext();) {
-       FlatNode fn=it.next();
-       switch(fn.kind()) {
-       case FKind.FlatCall:
-       case FKind.FlatFieldNode:
-       case FKind.FlatSetFieldNode:
-       case FKind.FlatNew:
-       case FKind.FlatCastNode:
-       case FKind.FlatReturnNode:
-       case FKind.FlatCondBranch:
-       case FKind.FlatSetElementNode:
-       case FKind.FlatElementNode:
-       case FKind.FlatFlagActionNode:
-       case FKind.FlatCheckNode:
-       case FKind.FlatBackEdge:
-       case FKind.FlatExit:
-       case FKind.FlatTagDeclaration:
-       case FKind.FlatMethod:
-       case FKind.FlatAtomicEnterNode:
-       case FKind.FlatAtomicExitNode:
-       case FKind.FlatPrefetchNode:
-       case FKind.FlatSESEEnterNode:
-       case FKind.FlatSESEExitNode:
-         if (!useful.contains(fn)) {
-           useful.add(fn);
-           changed=true;
-         }       
-         break;
-       case FKind.FlatOpNode:
-         FlatOpNode fon=(FlatOpNode)fn;
-         if (fon.getOp().getOp()==Operation.DIV||
-             fon.getOp().getOp()==Operation.MOD) {
-           if (!useful.contains(fn)) {
-             useful.add(fn);
-             changed=true;
-           }
-           break;
-         }
-       default:
-         TempDescriptor[] writes=fn.writesTemps();
-         if (!useful.contains(fn))
-           for(int i=0;i<writes.length;i++) {
-             for(Iterator<FlatNode> uit=ud.useMap(fn,writes[i]).iterator();uit.hasNext();) {
-               FlatNode ufn=uit.next();
-               if (useful.contains(ufn)) {
-                 //we are useful
-                 useful.add(fn);
-                 changed=true;
-                 continue nextfn;
-               }
-             }
-           }
-       }
+nextfn:
+      for(Iterator<FlatNode> it=fm.getNodeSet().iterator(); it.hasNext(); ) {
+        FlatNode fn=it.next();
+        switch(fn.kind()) {
+        case FKind.FlatCall:
+        case FKind.FlatFieldNode:
+        case FKind.FlatSetFieldNode:
+        case FKind.FlatNew:
+        case FKind.FlatCastNode:
+        case FKind.FlatReturnNode:
+        case FKind.FlatCondBranch:
+        case FKind.FlatSetElementNode:
+        case FKind.FlatElementNode:
+        case FKind.FlatFlagActionNode:
+        case FKind.FlatCheckNode:
+        case FKind.FlatBackEdge:
+        case FKind.FlatExit:
+        case FKind.FlatTagDeclaration:
+        case FKind.FlatMethod:
+        case FKind.FlatAtomicEnterNode:
+        case FKind.FlatAtomicExitNode:
+        case FKind.FlatPrefetchNode:
+        case FKind.FlatSESEEnterNode:
+        case FKind.FlatSESEExitNode:
+        case FKind.FlatGenReachNode:
+          if (!useful.contains(fn)) {
+            useful.add(fn);
+            changed=true;
+          }
+          break;
+
+        case FKind.FlatOpNode:
+          FlatOpNode fon=(FlatOpNode)fn;
+          if (fon.getOp().getOp()==Operation.DIV||
+              fon.getOp().getOp()==Operation.MOD) {
+            if (!useful.contains(fn)) {
+              useful.add(fn);
+              changed=true;
+            }
+            break;
+          }
+
+        default:
+          TempDescriptor[] writes=fn.writesTemps();
+          if (!useful.contains(fn))
+            for(int i=0; i<writes.length; i++) {
+              for(Iterator<FlatNode> uit=ud.useMap(fn,writes[i]).iterator(); uit.hasNext(); ) {
+                FlatNode ufn=uit.next();
+                if (useful.contains(ufn)) {
+                  //we are useful
+                  useful.add(fn);
+                  changed=true;
+                  continue nextfn;
+                }
+              }
+            }
+        }
       }
     }
     //get rid of useless nodes
-    for(Iterator<FlatNode> it=fm.getNodeSet().iterator();it.hasNext();) {
+    for(Iterator<FlatNode> it=fm.getNodeSet().iterator(); it.hasNext(); ) {
       FlatNode fn=it.next();
-      if (!useful.contains(fn)) {
-       //We have a useless node
-       FlatNode fnnext=fn.getNext(0);
+      if (!useful.contains(fn)||isuseless(fn)) {
+        //We have a useless node
+        FlatNode fnnext=fn.getNext(0);
+        for(int i=0; i<fn.numPrev(); i++) {
+          FlatNode nprev=fn.getPrev(i);
 
-       for(int i=0;i<fn.numPrev();i++) {
-         FlatNode nprev=fn.getPrev(i);
-             
-         for(int j=0;j<nprev.numNext();j++) {
-           if (nprev.getNext(j)==fn) {
-             nprev.setnext(j, fnnext);
-             fnnext.addPrev(nprev);
-           }
-         }
-       }
-       //fix up prev edge of fnnext
-       fnnext.removePrev(fn);
+          for(int j=0; j<nprev.numNext(); j++) {
+            if (nprev.getNext(j)==fn) {
+              nprev.setnext(j, fnnext);
+              fnnext.addPrev(nprev);
+            }
+          }
+        }
+        //fix up prev edge of fnnext
+        fnnext.removePrev(fn);
       }
     }
   }
+  public boolean isuseless(FlatNode fn) {
+    if (fn.kind()==FKind.FlatOpNode) {
+      FlatOpNode fon=(FlatOpNode)fn;
+      if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getLeft()==fon.getDest())
+        return true;
+    }
+    return false;
+  }
+
 }
\ No newline at end of file