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

SimpleLocalDefs.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 // FSet version
00085 
00086 public class SimpleLocalDefs implements LocalDefs
00087 {
00088     Map localStmtPairToDefs;
00089 
00090     /*
00091     public List getDefsOfBefore(Local l, Stmt s)
00092     {
00093         IntPair pair = (IntPair) analysis.localToIntPair.get(l);
00094         FSet value = (FSet) analysis.getValueBeforeStmt(s);
00095 
00096         List localDefs = value.toList(pair.op1, pair.op2);
00097 
00098         return localDefs;
00099     }*/
00100 
00101 /*
00102             Object[] elements = ((FSet) analysis.getValueBeforeStmt(s)).toArray();
00103             List listOfDefs = new LinkedList();
00104 
00105             // Extract those defs which correspond to this local
00106             {
00107                 for(int i = 0; i < elements.length; i++)
00108                 {
00109                     DefinitionStmt d = (DefinitionStmt) elements[i];
00110 
00111                     if(d.getLeftOp() == l)
00112                         listOfDefs.add(d);
00113                 }
00114             }
00115 
00116             // Convert the array so that it's of an appropriate form
00117             {
00118                 Object[] objects = listOfDefs.toArray();
00119                 DefinitionStmt[] defs = new DefinitionStmt[objects.length];
00120 
00121                 for(int i = 0; i < defs.length; i++)
00122                     defs[i] = (DefinitionStmt) objects[i];
00123 
00124                 return defs;
00125             }
00126 
00127         }
00128     }
00129 */
00130 
00131     /*
00132     public DefinitionStmt[] getDefsOfAfter(Local l, Stmt s)
00133     {
00134        Object[] elements = ((FSet) analysis.getValueAfterStmt(s)).toArray();
00135            List listOfDefs = new LinkedList();
00136 
00137         // Extract those defs which correspond to this local
00138          {
00139              for(int i = 0; i < elements.length; i++)
00140             {
00141                    DefinitionStmt d = (DefinitionStmt) elements[i];
00142 
00143                 if(d.getLeftOp() == l)
00144                     listOfDefs.add(d);
00145             }
00146            }
00147 
00148            // Convert the array so that it's of an appropriate form
00149            {
00150                 Object[] objects = listOfDefs.toArray();
00151                 DefinitionStmt[] defs = new DefinitionStmt[objects.length];
00152 
00153                 for(int i = 0; i < defs.length; i++)
00154                     defs[i] = (DefinitionStmt) objects[i];
00155 
00156                 return defs;
00157             }
00158     }
00159 
00160     public DefinitionStmt[] getDefsBefore(Stmt s)
00161     {
00162         Object[] elements = ((FSet) analysis.getValueBeforeStmt(s)).toArray();
00163         DefinitionStmt[] defs = new DefinitionStmt[elements.length];
00164 
00165         for(int i = 0; i < elements.length; i++)
00166             defs[i] = (DefinitionStmt) elements[i];
00167 
00168         return defs;
00169     }
00170 
00171     public DefinitionStmt[] getDefsAfter(Stmt s)
00172     {
00173         Object[] elements = ((FSet) analysis.getValueAfterStmt(s)).toArray();
00174         DefinitionStmt[] defs = new DefinitionStmt[elements.length];
00175 
00176         for(int i = 0; i < elements.length; i++)
00177             defs[i] = (DefinitionStmt) elements[i];
00178 
00179         return defs;
00180     }
00181     */
00182     public SimpleLocalDefs(CompleteStmtGraph g)
00183     {
00184         if(Main.isProfilingOptimization)
00185             Main.defsTimer.start();
00186         
00187         if(Main.isVerbose)
00188             System.out.println("[" + g.getBody().getMethod().getName() +
00189                 "]     Constructing SimpleLocalDefs...");
00190     
00191         LocalDefsFlowAnalysis analysis = new LocalDefsFlowAnalysis(g);
00192         
00193         if(Main.isProfilingOptimization)
00194             Main.defsPostTimer.start();
00195 
00196         // Build localStmtPairToDefs map
00197         {
00198             Iterator stmtIt = g.iterator();
00199 
00200             localStmtPairToDefs = new HashMap(g.size() * 2 + 1, 0.7f);
00201 
00202             while(stmtIt.hasNext())
00203             {
00204                 Stmt s = (Stmt) stmtIt.next();
00205 
00206                 Iterator boxIt = s.getUseBoxes().iterator();
00207 
00208                 while(boxIt.hasNext())
00209                 {
00210                     ValueBox box = (ValueBox) boxIt.next();
00211 
00212                     if(box.getValue() instanceof Local)
00213                     {
00214                         Local l = (Local) box.getValue();
00215                         LocalStmtPair pair = new LocalStmtPair(l, s);
00216 
00217                         if(!localStmtPairToDefs.containsKey(pair))
00218                         {
00219                             IntPair intPair = (IntPair) analysis.localToIntPair.get(l);
00220                             BoundedFlowSet value = (BoundedFlowSet) analysis.getFlowBeforeStmt(s);
00221 
00222                             List localDefs = value.toList(intPair.op1, intPair.op2);
00223 
00224                             localStmtPairToDefs.put(pair, Collections.unmodifiableList(localDefs));
00225                         }
00226                     }
00227                 }
00228             }
00229         }
00230 
00231         if(Main.isProfilingOptimization)
00232             Main.defsPostTimer.end();
00233                 
00234         if(Main.isProfilingOptimization)
00235             Main.defsTimer.end();
00236     }
00237     public List getDefsOfAt(Local l, Stmt s)
00238     {
00239         LocalStmtPair pair = new LocalStmtPair(l, s);
00240 
00241         return (List) localStmtPairToDefs.get(pair);
00242     }
00243 }

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