*Fixed duplicate edges in TaskGraph
authorsivaji <sivaji>
Tue, 22 May 2007 18:17:19 +0000 (18:17 +0000)
committersivaji <sivaji>
Tue, 22 May 2007 18:17:19 +0000 (18:17 +0000)
*Added 'isSourceNode' boolean var to FlagState to keep track
of whether it's a start/source node.
*Used 'FlagState.isSourceNode' to add Start Node in TaskGraph.

Robust/src/Analysis/TaskStateAnalysis/FlagState.java
Robust/src/Analysis/TaskStateAnalysis/TEdge.java
Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java
Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java
Robust/src/Analysis/TaskStateAnalysis/TaskNode.java

index 682333ff618965cafb2c95d2cd4724f454f66906..b32c02653ed97411baaa10130a7053879bcf70a5 100644 (file)
@@ -21,6 +21,7 @@ public class FlagState extends GraphNode {
     private final HashSet flagstate;
     private final ClassDescriptor cd;
     private final Hashtable<TagDescriptor,Integer> tags;
+    private boolean issourcenode;
 
     /** Class constructor
      *  Creates a new flagstate with all flags set to false.
@@ -31,6 +32,7 @@ public class FlagState extends GraphNode {
        this.cd=cd;
        this.tags=new Hashtable<TagDescriptor,Integer>();
        this.uid=FlagState.nodeid++;
+       this.issourcenode=false;
     }
 
     /** Class constructor
@@ -44,6 +46,7 @@ public class FlagState extends GraphNode {
        this.cd=cd;
        this.tags=tags;
        this.uid=FlagState.nodeid++;
+       this.issourcenode=false;
        
     }
     
@@ -54,6 +57,20 @@ public class FlagState extends GraphNode {
     public boolean get(FlagDescriptor fd) {
        return flagstate.contains(fd);
     }
+    
+    /** Checks if the flagstate is a source node. 
+     *  @return true if the flagstate is a sourcenode(i.e. Is the product of an allocation site).
+     */
+      
+    public boolean isSourceNode(){
+           return issourcenode;
+       }
+       
+       /**  Sets the flagstate as a source node. 
+     */
+       public void setAsSourceNode(){
+               issourcenode=true;
+       }
 
     
     public String toString() {
index 96bdabe60381e128838acb3e7996800a81d308ec..26e6ce478c17f6d67a2e9fbff57755db2b57c8e7 100644 (file)
@@ -9,13 +9,14 @@ import Util.Edge;
 
 public class TEdge extends Edge{
        
+
     
     public TEdge(TaskNode target){
        super(target);
     }
+
        
-          
-        
+                
     public int hashCode(){
        return target.hashCode();
     }
index 0ac4a68af8f1503619d4c2b70c4461978a351d29..7d98537aae5f953137800e4a1acf6e8171d1b508 100644 (file)
@@ -28,6 +28,7 @@ public class TaskAnalysis {
        this.state=state;
        this.typeutil=new TypeUtil(state);
        this.taganalysis=taganalysis;
+       
     }
     
     /** Builds a table of flags for each class in the Bristlecone program.  
@@ -203,6 +204,8 @@ private void analyseTasks(FlagState fs) {
        Set newstates=taganalysis.getFlagStates(td);
        for(Iterator fsit=newstates.iterator();fsit.hasNext();) {
            FlagState fsnew=(FlagState) fsit.next();
+           fsnew.setAsSourceNode();
+           
            if (! ((Hashtable<FlagState,FlagState>)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) {
                ((Hashtable<FlagState,FlagState>)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew);
                toprocess.add(fsnew);
index fbdcfcdd931d69a8510843a7fb0f7042c2282e46..00b31dc07259319366acba057e43b53fa44b8f49 100644 (file)
@@ -19,14 +19,15 @@ public class TaskGraph {
 
        for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext();) {
            ClassDescriptor cd=(ClassDescriptor) classit.next();
-           produceTaskNodes(cd);
+           if (cd.hasFlags())
+               produceTaskNodes(cd);
        }
     }
     
     
     public void createDOTfiles() {
-       for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext();) {
-           ClassDescriptor cd=(ClassDescriptor) classit.next();
+       for(Iterator it_classes=(Iterator)cdtonodes.keys();it_classes.hasNext();) {
+           ClassDescriptor cd=(ClassDescriptor) it_classes.next();
            Set tasknodes=getTaskNodes(cd);
            if (tasknodes!=null) {
                try {
@@ -63,34 +64,45 @@ public class TaskGraph {
        Set fsnodes=taskanalysis.getFlagStates(cd);
        if (fsnodes==null)
            return;
-
+           
        Hashtable<TaskNode,TaskNode> tasknodes=new Hashtable<TaskNode,TaskNode>();
        cdtonodes.put(cd, tasknodes);
 
        for(Iterator it=fsnodes.iterator();it.hasNext();) {
            FlagState fs=(FlagState)it.next();
-           
            Iterator it_inedges=fs.inedges();   
-           TaskNode tn;
-           do {
-               if (!fs.inedges().hasNext()){
-                   tn=new TaskNode("Start Node");
-               } else {
+           TaskNode tn,sn;
+          
+               if (fs.isSourceNode()) {
+                       sn=new TaskNode("Start Node");
+                       if(fs.edges().hasNext()){
+                                addEdges(fs,sn);
+                       }       
+               }
+                                               
+               while(it_inedges.hasNext()){   
+                       
                    FEdge inedge=(FEdge)it_inedges.next();
                    tn=new TaskNode(inedge.getLabel());
-               }
-               if(fs.edges().hasNext()){
-                   tn=(TaskNode)canonicalizeTaskNode(tasknodes, tn);
-                   for (Iterator it_edges=fs.edges();it_edges.hasNext();){
-                       TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel());
-                       target=(TaskNode)canonicalizeTaskNode(tasknodes,target);
-                       TEdge tedge=new TEdge(target);
-                       //                      if (!tn.edges.contains(tedge))
-                           tn.addEdge(new TEdge(target));
-                   }
-               }
-           } while(it_inedges.hasNext());
+                   if(fs.edges().hasNext()){
+                       addEdges(fs,tn);
+                       }
+           }  
        }
     }
     
+    private void addEdges(FlagState fs, TaskNode tn){
+           
+           Hashtable<TaskNode,TaskNode> tasknodes=(Hashtable<TaskNode,TaskNode>)cdtonodes.get(fs.getClassDescriptor());
+           tn=(TaskNode)canonicalizeTaskNode(tasknodes, tn);
+               for (Iterator it_edges=fs.edges();it_edges.hasNext();){
+                       TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel());
+                       target=(TaskNode)canonicalizeTaskNode(tasknodes,target);
+
+                       TEdge newedge=new TEdge(target);
+                       if (! tn.edgeExists(newedge))
+                               tn.addEdge(new TEdge(target));
+           }
+
+       }
 }
index 2d5eec3504ba5cae177dd5afc306c3eafe55170e..e2dbd34e5b2e4eb96c92cd48ef3b5773d21f1742 100644 (file)
@@ -53,6 +53,15 @@ public class TaskNode extends GraphNode {
         }
         return false;
     }
+    
+    public boolean edgeExists(TEdge newedge){
+           if(edges.isEmpty())
+               return false;
+           else
+               return edges.contains(newedge);
+    }
+           
+    
 }