Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

CopiesFlowAnalysis.java

00001 package ca.mcgill.sable.soot.jimple;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Jimple, a 3-address code Java(TM) bytecode representation.        *
00005  * Copyright (C) 1997, 1998 Raja Vallee-Rai (kor@sable.mcgill.ca)    *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project of the Sable Research Group,      *
00009  * School of Computer Science, McGill University, Canada             *
00010  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00011  * modification not identified as such is not covered by the         *
00012  * preceding statement.                                              *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this library; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other Sable Research Group projects, please      *
00033  * visit the web site: http://www.sable.mcgill.ca/                   *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 
00036 /*
00037  Reference Version
00038  -----------------
00039  This is the latest official version on which this file is based.
00040  The reference version is: $SootVersion: 1.beta.4 $
00041 
00042  Change History
00043  --------------
00044  A) Notes:
00045 
00046  Please use the following template.  Most recent changes should
00047  appear at the top of the list.
00048 
00049  - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate]
00050    [description of modification].
00051 
00052  Any Modification flagged with "(*)" was done as a project of the
00053  Sable Research Group, School of Computer Science,
00054  McGill University, Canada (http://www.sable.mcgill.ca/).
00055 
00056  You should add your copyright, using the following template, at
00057  the top of this file, along with other copyrights.
00058 
00059  *                                                                   *
00060  * Modifications by [name] are                                       *
00061  * Copyright (C) [year(s)] [your name (or company)].  All rights     *
00062  * reserved.                                                         *
00063  *                                                                   *
00064 
00065  B) Changes:
00066 
00067  - Modified on March 13, 1999 by Raja Vallee-Rai (rvalleerai@sable.mcgill.ca) (*)
00068    Re-organized the timers.
00069 
00070  - Modified on November 2, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*)
00071    Repackaged all source files and performed extensive modifications.
00072    First initial release of Soot.
00073 
00074  - Modified on 23-Jul-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00075    Renamed the uses of Hashtable to HashMap.
00076 
00077  - Modified on 15-Jun-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00078    First internal release (Version 0.1).
00079 */
00080 
00081 import ca.mcgill.sable.soot.*;
00082 import ca.mcgill.sable.util.*;
00083 
00084 class CopiesFlowAnalysis extends ForwardFlowAnalysis
00085 {
00086     FlowSet emptySet;
00087     Map localToPreserveSet;
00088 
00089     CopiesFlowAnalysis(StmtGraph g)
00090     {
00091         super(g);
00092 
00093         List copiesList;
00094 
00095         // Create list of possible copies
00096         {
00097             copiesList = new ArrayList();
00098 
00099             Iterator stmtIt = g.iterator();
00100 
00101             while(stmtIt.hasNext())
00102             {
00103                 Stmt s = (Stmt) stmtIt.next();
00104 
00105                 if(s instanceof DefinitionStmt)
00106                 {
00107                     DefinitionStmt def = (DefinitionStmt) s;
00108 
00109                     if(def.getLeftOp() instanceof Local &&
00110                         def.getRightOp() instanceof Local)
00111                     {
00112                         copiesList.add(new LocalCopy((Local) def.getLeftOp(),
00113                             (Local) def.getRightOp()));
00114                     }
00115                 }
00116             }
00117 
00118             FlowUniverse copiesUniverse = new FlowUniverse(copiesList.toArray());
00119             
00120             emptySet = new ArrayPackedSet(copiesUniverse);
00121         }
00122 
00123         // Create preserve sets for each local.
00124         {
00125             localToPreserveSet = new HashMap(g.getBody().getLocalCount() * 2 + 1, 0.7f);
00126 
00127             // Initialize each set to empty
00128             {
00129                 Iterator localIt = g.getBody().getLocals().iterator();
00130 
00131                 while(localIt.hasNext())
00132                     localToPreserveSet.put(localIt.next(), emptySet.clone());
00133             }
00134 
00135             // Go through all the copies, add the copy to the killSet of the involved locals
00136             {
00137                 Iterator copyIt = copiesList.iterator();
00138 
00139                 while(copyIt.hasNext())
00140                 {
00141                     LocalCopy copy = (LocalCopy) copyIt.next();
00142 
00143                     FlowSet fset = (FlowSet) localToPreserveSet.get(copy.leftLocal);
00144 
00145                     fset.add(copy, fset);
00146 
00147                     fset = (FlowSet) localToPreserveSet.get(copy.rightLocal);
00148                     fset.add(copy, fset);
00149                 }
00150             }
00151 
00152             // Flip all the kill sets to really become preserve sets
00153             {
00154                 Iterator localIt = g.getBody().getLocals().iterator();
00155 
00156                 while(localIt.hasNext())
00157                 {
00158                     BoundedFlowSet preserveSet = (BoundedFlowSet) localToPreserveSet.get(localIt.next());
00159 
00160                     preserveSet.complement(preserveSet);
00161                 }
00162             }
00163         }
00164 
00165 
00166         doAnalysis();
00167     }
00168     protected void copy(Object source, Object dest)
00169     {
00170         FlowSet sourceSet = (FlowSet) source,
00171             destSet = (FlowSet) dest;
00172             
00173         sourceSet.copy(destSet);
00174     }
00175     protected void flowThrough(Object inValue, Stmt stmt, Object outValue)
00176     {
00177         FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue;
00178 
00179         if(stmt instanceof DefinitionStmt)
00180         {
00181             // Perform Kill
00182             {
00183                 DefinitionStmt def = (DefinitionStmt) stmt;
00184 
00185                 if(def.getLeftOp() instanceof Local)
00186                     in.intersection((FlowSet) localToPreserveSet.get(def.getLeftOp()), out);
00187                 else
00188                     in.copy(out);
00189             }
00190 
00191             // Perform generation
00192             {
00193                 DefinitionStmt def = (DefinitionStmt) stmt;
00194 
00195                 if(def.getLeftOp() instanceof Local && def.getRightOp() instanceof Local)
00196                 {
00197                     out.add(new LocalCopy((Local) def.getLeftOp(), (Local) def.getRightOp()),
00198                         out);
00199 
00200                 }
00201             }
00202         }
00203         else
00204             in.copy(out);
00205     }
00206     protected void merge(Object in1, Object in2, Object out)
00207     {
00208         FlowSet inSet1 = (FlowSet) in1,
00209             inSet2 = (FlowSet) in2;
00210 
00211         FlowSet outSet = (FlowSet) out;
00212 
00213         inSet1.intersection(inSet2, outSet);
00214     }
00215     protected Object newInitialFlow()
00216     {
00217         return emptySet.clone();
00218     }
00219 }

Generated at Thu Feb 7 06:43:08 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001