00001 package ca.mcgill.sable.soot.jimple;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 import ca.mcgill.sable.soot.*;
00085 import ca.mcgill.sable.util.*;
00086
00087 class SparseLocalDefsFlowAnalysis extends ForwardFlowAnalysis
00088 {
00089 FlowSet emptySet;
00090 Map localToPreserveSet;
00091 FlowSet workingSet;
00092 LiveLocals liveLocals;
00093
00094 public SparseLocalDefsFlowAnalysis(StmtGraph g, LiveLocals liveLocals)
00095 {
00096 super(g);
00097
00098 this.liveLocals = liveLocals;
00099 if(Main.isProfilingOptimization)
00100 Main.defsSetupTimer.start();
00101
00102 emptySet = new ArraySparseSet();
00103 workingSet = (FlowSet) emptySet.clone();
00104
00105 if(Main.isProfilingOptimization)
00106 Main.defsSetupTimer.end();
00107
00108 if(Main.isProfilingOptimization)
00109 Main.defsAnalysisTimer.start();
00110
00111 doAnalysis();
00112
00113 if(Main.isProfilingOptimization)
00114 Main.defsAnalysisTimer.end();
00115
00116 }
00117 protected void copy(Object source, Object dest)
00118 {
00119 FlowSet sourceSet = (FlowSet) source,
00120 destSet = (FlowSet) dest;
00121
00122 sourceSet.copy(destSet);
00123 }
00124 protected void flowThrough(Object inValue, Stmt stmt, Object outValue)
00125 {
00126 FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue;
00127
00128 if(stmt instanceof DefinitionStmt)
00129 {
00130 DefinitionStmt d = (DefinitionStmt) stmt;
00131
00132 if(!(d.getLeftOp() instanceof Local))
00133 {
00134 in.copy(out);
00135 }
00136 else {
00137
00138 Local local = (Local) d.getLeftOp();
00139
00140
00141 {
00142 workingSet.clear();
00143
00144 Iterator defIt = in.toList().iterator();
00145
00146 while(defIt.hasNext())
00147 {
00148 DefinitionStmt def = (DefinitionStmt) defIt.next();
00149
00150 if(def.getLeftOp() == local)
00151 workingSet.add(def, workingSet);
00152 }
00153
00154 in.difference(workingSet, out);
00155 }
00156
00157
00158
00159 out.add(d, out);
00160 }
00161
00162 }
00163 else
00164 in.copy(out);
00165
00166
00167 {
00168 Iterator useBoxIt = stmt.getUseBoxes().iterator();
00169 List liveLocalsAfter = liveLocals.getLiveLocalsAfter(stmt);
00170
00171 workingSet.clear();
00172
00173 while(useBoxIt.hasNext())
00174 {
00175 ValueBox useBox = (ValueBox) useBoxIt.next();
00176
00177 if(useBox.getValue() instanceof Local)
00178 {
00179 Local l = (Local) useBox.getValue();
00180
00181 if(!liveLocalsAfter.contains(l))
00182 {
00183
00184
00185 Iterator defIt = out.toList().iterator();
00186
00187 while(defIt.hasNext())
00188 {
00189 DefinitionStmt def = (DefinitionStmt) defIt.next();
00190
00191 if(def.getLeftOp() == l)
00192 workingSet.add(def, workingSet);
00193 }
00194 }
00195 }
00196 }
00197
00198 out.difference(workingSet, out);
00199 }
00200
00201 }
00202 protected void merge(Object in1, Object in2, Object out)
00203 {
00204 FlowSet inSet1 = (FlowSet) in1,
00205 inSet2 = (FlowSet) in2;
00206
00207 FlowSet outSet = (FlowSet) out;
00208
00209 inSet1.union(inSet2, outSet);
00210 }
00211 protected Object newInitialFlow()
00212 {
00213 return emptySet.clone();
00214 }
00215 }