[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A couple of changes to Soot



Hi,

I have made some simple changes to Soot and would like to release it into Soot. The changes are to enable SimpleLocalXXX to work on UnitGraphs rather than CompleteUnitGraphs. This stems from the fact that all unit graphs can be used to derive local def/use info that depends on the nature of the Unit graph implementation. Hence, the user can decide which unit graph to use rather than using CompleteUnitGraph always. The proposed change does not break any implementation rather allows for more flexible usage.

I hope it gets committed.

--

Venkatesh Prasad Ranganath,
Dept. Computing and Information Science,
Kansas State University, US.
web: http://www.cis.ksu.edu/~rvprasad
Index: src/soot/toolkits/scalar/SimpleLocalDefs.java
===================================================================
--- src/soot/toolkits/scalar/SimpleLocalDefs.java	(revision 1280)
+++ src/soot/toolkits/scalar/SimpleLocalDefs.java	(working copy)
@@ -18,7 +18,7 @@
  */
 
 /*
- * Modified by the Sable Research Group and others 1997-1999.  
+ * Modified by the Sable Research Group and others 1997-1999.
  * See the 'credits' file distributed with Soot for the complete list of
  * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
  */
@@ -53,20 +53,20 @@
     /**
      *   Computes the analysis given a CompleteUnitGraph computed from a method body.
      *   @param g a graph on which to compute the analysis.
-     *   
+     *
      *   @see CompleteUnitGraph
      */
-    public SimpleLocalDefs(CompleteUnitGraph g)
+    public SimpleLocalDefs(UnitGraph g)
     {
         if(Options.v().time())
             Timers.v().defsTimer.start();
-        
+
         if(Options.v().verbose())
             G.v().out.println("[" + g.getBody().getMethod().getName() +
                                "]     Constructing SimpleLocalDefs...");
-    
+
         LocalDefsFlowAnalysis analysis = new LocalDefsFlowAnalysis(g);
-        
+
         if(Options.v().time())
             Timers.v().defsPostTimer.start();
 
@@ -94,7 +94,7 @@
                                     if(!localUnitPairToDefs.containsKey(pair))
                                         {
                                             IntPair intPair = (IntPair) analysis.localToIntPair.get(l);
-					    
+
                                             ArrayPackedSet value = (ArrayPackedSet) analysis.getFlowBefore(s);
 
                                             List unitLocalDefs = value.toList(intPair.op1, intPair.op2);
@@ -108,7 +108,7 @@
 
         if(Options.v().time())
             Timers.v().defsPostTimer.end();
-                
+
         if(Options.v().time())
             Timers.v().defsTimer.end();
 
@@ -122,12 +122,12 @@
         LocalUnitPair pair = new LocalUnitPair(l, s);
 
         List toReturn = (List) localUnitPairToDefs.get(pair);
-        
+
         if(toReturn == null)
-            throw new RuntimeException("Illegal LocalDefs query; local " + l + " has no definition at " + 
+            throw new RuntimeException("Illegal LocalDefs query; local " + l + " has no definition at " +
                                        s.toString());
-               
-        
+
+
         return toReturn;
     }
 
@@ -277,23 +277,23 @@
                     {
                         Unit s = (Unit) it.next();
 
-                    
+
                         List defBoxes = s.getDefBoxes();
                         if(!defBoxes.isEmpty()) {
-                            if(!(defBoxes.size() ==1)) 
+                            if(!(defBoxes.size() ==1))
                                 throw new RuntimeException("invalid number of def boxes");
-                            
+
                             if(((ValueBox)defBoxes.get(0)).getValue() instanceof Local) {
                                 Local defLocal = (Local) ((ValueBox)defBoxes.get(0)).getValue();
                                 List l = (List) localToDefList.get(defLocal);
-                            
+
                                 if(l == null)
                                     throw new RuntimeException("local " + defLocal + " is used but not declared!");
                                 else
                                     l.add(s);
                             }
                         }
-                    
+
                     }
             }
 
@@ -359,19 +359,19 @@
             for(int i = 0; i < defs.length; i++)
                 {
                     Unit s = (Unit) defs[i];
-                    
+
                     List defBoxes = s.getDefBoxes();
-                    if(!(defBoxes.size() ==1)) 
+                    if(!(defBoxes.size() ==1))
                         throw new RuntimeException("SimpleLocalDefs: invalid number of def boxes");
-                            
+
                     if(((ValueBox)defBoxes.get(0)).getValue() instanceof Local) {
                         Local defLocal = (Local) ((ValueBox)defBoxes.get(0)).getValue();
                         BoundedFlowSet killSet = (BoundedFlowSet) localToKillSet.get(defLocal);
                         killSet.add(s, killSet);
-                        
+
                     }
                 }
-            
+
             // Store complement
             {
                 Iterator localIt = locals.iterator();
@@ -396,11 +396,11 @@
             Timers.v().defsAnalysisTimer.start();
 
         doAnalysis();
-        
+
         if(Options.v().time())
             Timers.v().defsAnalysisTimer.end();
     }
-    
+
     protected Object newInitialFlow()
     {
         return emptySet.clone();
@@ -418,26 +418,26 @@
 
         List defBoxes = unit.getDefBoxes();
         if(!defBoxes.isEmpty()) {
-            if(!(defBoxes.size() ==1)) 
+            if(!(defBoxes.size() ==1))
                 throw new RuntimeException("SimpleLocalDefs: invalid number of def boxes");
-                          
+
             Value value = ((ValueBox)defBoxes.get(0)).getValue();
             if(value  instanceof Local) {
                 Local defLocal = (Local) value;
-            
+
                 // Perform kill on value
                 in.intersection((FlowSet) localToPreserveSet.get(defLocal), out);
 
                 // Perform generation
                 out.add(unit, out);
-            } else { 
+            } else {
                 in.copy(out);
                 return;
             }
 
 
-        
 
+
         }
         else
             in.copy(out);
@@ -447,7 +447,7 @@
     {
         FlowSet sourceSet = (FlowSet) source,
             destSet = (FlowSet) dest;
-        
+
         sourceSet.copy(destSet);
     }
 
@@ -455,9 +455,9 @@
     {
         FlowSet inSet1 = (FlowSet) in1,
             inSet2 = (FlowSet) in2;
-        
+
         FlowSet outSet = (FlowSet) out;
-        
+
         inSet1.union(inSet2, outSet);
     }
 }
Index: src/soot/toolkits/scalar/SimpleLiveLocals.java
===================================================================
--- src/soot/toolkits/scalar/SimpleLiveLocals.java	(revision 1280)
+++ src/soot/toolkits/scalar/SimpleLiveLocals.java	(working copy)
@@ -18,7 +18,7 @@
  */
 
 /*
- * Modified by the Sable Research Group and others 1997-1999.  
+ * Modified by the Sable Research Group and others 1997-1999.
  * See the 'credits' file distributed with Soot for the complete list of
  * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
  */
@@ -51,19 +51,19 @@
     /**
      *   Computes the analysis given a CompleteUnitGraph computed from a method body.
      *   @param g a graph on which to compute the analysis.
-     *   
+     *
      *   @see CompleteUnitGraph
      */
-    public SimpleLiveLocals(CompleteUnitGraph graph)
+    public SimpleLiveLocals(UnitGraph graph)
     {
         if(Options.v().time())
             Timers.v().liveTimer.start();
-        
+
         if(Options.v().verbose())
             G.v().out.println("[" + graph.getBody().getMethod().getName() +
                 "]     Constructing SimpleLiveLocals...");
 
-                        
+
         SimpleLiveLocalsAnalysis analysis = new SimpleLiveLocalsAnalysis(graph);
 
         if(Options.v().time())
@@ -79,18 +79,18 @@
             while(unitIt.hasNext())
             {
                 Unit s = (Unit) unitIt.next();
- 
+
                 FlowSet set = (FlowSet) analysis.getFlowBefore(s);
                 unitToLocalsBefore.put(s, Collections.unmodifiableList(set.toList()));
-                
+
                 set = (FlowSet) analysis.getFlowAfter(s);
                 unitToLocalsAfter.put(s, Collections.unmodifiableList(set.toList()));
-            }            
+            }
         }
-        
+
         if(Options.v().time())
             Timers.v().livePostTimer.end();
-        
+
         if(Options.v().time())
             Timers.v().liveTimer.end();
     }
@@ -99,7 +99,7 @@
     {
         return (List) unitToLocalsAfter.get(s);
     }
-    
+
     public List getLiveLocalsBefore(Unit s)
     {
         return (List) unitToLocalsBefore.get(s);
@@ -125,7 +125,7 @@
             FlowUniverse localUniverse = new CollectionFlowUniverse(locals);
 
             emptySet = new ArrayPackedSet(localUniverse);
-            
+
         }
 
         // Create preserve sets.
@@ -189,7 +189,7 @@
             Timers.v().liveAnalysisTimer.start();
 
         doAnalysis();
-        
+
         if(Options.v().time())
             Timers.v().liveAnalysisTimer.end();
 
@@ -204,7 +204,7 @@
     {
         return emptySet.clone();
     }
-        
+
     protected void flowThrough(Object inValue, Object unit, Object outValue)
     {
         FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue;
@@ -225,12 +225,12 @@
 
         inSet1.union(inSet2, outSet);
     }
-    
+
     protected void copy(Object source, Object dest)
     {
         FlowSet sourceSet = (FlowSet) source,
             destSet = (FlowSet) dest;
-            
+
         sourceSet.copy(destSet);
     }
 }
Index: src/soot/toolkits/scalar/SimpleLocalUses.java
===================================================================
--- src/soot/toolkits/scalar/SimpleLocalUses.java	(revision 1280)
+++ src/soot/toolkits/scalar/SimpleLocalUses.java	(working copy)
@@ -18,7 +18,7 @@
  */
 
 /*
- * Modified by the Sable Research Group and others 1997-1999.  
+ * Modified by the Sable Research Group and others 1997-1999.
  * See the 'credits' file distributed with Soot for the complete list of
  * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
  */
@@ -39,7 +39,7 @@
 
 /**
  *  Analysis that implements the LocalUses interface.
- *  Uses for a Local defined at a given Unit are returned as 
+ *  Uses for a Local defined at a given Unit are returned as
  *  a list of UnitValueBoxPairs each containing a Unit that use the
  *  local and the Local itself wrapped in a ValueBox.
  */
@@ -56,7 +56,7 @@
      * may be cheaper to use the constructor which only requires a
      * Body.
      */
-    public SimpleLocalUses(CompleteUnitGraph graph, LocalDefs localDefs)
+    public SimpleLocalUses(UnitGraph graph, LocalDefs localDefs)
     {
         this(graph.getBody(), localDefs);
     }
@@ -70,18 +70,18 @@
     {
         if(Options.v().time())
            Timers.v().usesTimer.start();
-    
+
         if(Options.v().time())
            Timers.v().usePhase1Timer.start();
-        
+
         if(Options.v().verbose())
             G.v().out.println("[" + body.getMethod().getName() +
                 "]     Constructing SimpleLocalUses...");
-    
+
 	Chain units = body.getUnits();
-	
+
         unitToUses = new HashMap(units.size() * 2 + 1, 0.7f);
-    
+
         // Initialize this map to empty sets
         {
             Iterator it = units.iterator();
@@ -95,10 +95,10 @@
 
         if(Options.v().time())
            Timers.v().usePhase1Timer.end();
-    
+
         if(Options.v().time())
            Timers.v().usePhase2Timer.start();
-    
+
         // Traverse units and associate uses with definitions
         {
             Iterator it = units.iterator();
@@ -134,32 +134,32 @@
 
         if(Options.v().time())
            Timers.v().usePhase2Timer.end();
-    
+
         if(Options.v().time())
            Timers.v().usePhase3Timer.start();
-    
+
         // Store the map as a bunch of unmodifiable lists.
         {
             Iterator it = units.iterator();
-            
+
             while(it.hasNext())
             {
                 Unit s = (Unit) it.next();
 
                 unitToUses.put(s, Collections.unmodifiableList(((List) unitToUses.get(s))));
             }
-            
+
         }
-        
+
         if(Options.v().time())
            Timers.v().usePhase3Timer.end();
-    
+
         if(Options.v().time())
             Timers.v().usesTimer.end();
     }
 
     /**
-     *  Uses for a Local defined at a given Unit are returned as 
+     *  Uses for a Local defined at a given Unit are returned as
      *  a list of UnitValueBoxPairs each containing a Unit that use the
      *  local and the Local itself wrapped in a ValueBox.
      *  @param s a unit that we want to query for the uses of the Local it (may) define.
Index: build.xml
===================================================================
--- build.xml	(revision 1280)
+++ build.xml	(working copy)
@@ -64,6 +64,7 @@
             destdir="doc"
             maxmemory="200m"
             windowtitle="Soot API"
+            private="yes"
         >
             <fileset dir="src" includes="**/*.java"/>
         </javadoc>