KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > scalar > pre > NotIsolatedAnalysis


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2002 Florian Loitsch
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-2002.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 package soot.jimple.toolkits.scalar.pre;
28 import soot.*;
29 import soot.toolkits.scalar.*;
30 import soot.toolkits.graph.*;
31 import soot.jimple.toolkits.scalar.*;
32 import soot.jimple.*;
33 import java.util.*;
34 import soot.util.*;
35
36 /**
37  * Performs a Not-Isolated-analysis on the given graph, which is basicly the
38  * same as an Isolated-analysis (we just return the complement, as it's easier
39  * to calculate it).
40  * A computation is isolated, if it can only be used at the current
41  * computation-point. In other words: if the result of the computation will not
42  * be used later on the computation is isolated.<br>
43  * The Latest-analysis helps us in finding isolated computations, as they
44  * show us points, where a precedent computation can't be used anymore.
45  * In completely other words: we search the interval "latest"-"computation". a
46  * computation in this interval would not be isolated.
47  */

48 public class NotIsolatedAnalysis extends BackwardFlowAnalysis {
49   private LatestComputation unitToLatest;
50   private Map unitToGen;
51   private FlowSet set;
52
53   /**
54    * this constructor should not be used, and will throw a runtime-exception!
55    */

56   public NotIsolatedAnalysis(DirectedGraph dg) {
57     /* we have to add super(dg). otherwise Javac complains. */
58     super(dg);
59     throw new RuntimeException JavaDoc("Don't use this Constructor!");
60   }
61
62   /**
63    * automaticly performs the Isolation-analysis on the graph
64    * <code>dg</code> using the Latest-computation <code>latest</code>.<br>
65    * the <code>equivRhsMap</code> is only here to avoid doing these things
66    * again...
67    *
68    * @param dg a ExceptionalUnitGraph
69    * @param latest the latest-computation of the same graph.
70    * @param equivRhsMap the rhs of each unit (if assignment-stmt).
71    */

72   public NotIsolatedAnalysis(DirectedGraph dg, LatestComputation latest,
73       Map equivRhsMap) {
74     this(dg, latest, equivRhsMap, new
75       ArrayPackedSet(new CollectionFlowUniverse(equivRhsMap.values())));
76   }
77
78   /**
79    * automaticly performs the Isolation-analysis on the graph
80    * <code>dg</code> using the Latest-computation <code>latest</code>.<br>
81    * the <code>equivRhsMap</code> is only here to avoid doing these things
82    * again...<br>
83    * the shared set allows more efficient set-operations, when this analysis is
84    * joined with other analyses/computations.
85    *
86    * @param dg a ExceptionalUnitGraph
87    * @param latest the latest-computation of the same graph.
88    * @param equivRhsMap the rhs of each unit (if assignment-stmt).
89    * @param set the shared set.
90    */

91   public NotIsolatedAnalysis(DirectedGraph dg, LatestComputation latest,
92       Map equivRhsMap, BoundedFlowSet set) {
93     super(dg);
94     UnitGraph g = (UnitGraph)dg;
95     this.set = set;
96     unitToGen = equivRhsMap;
97     unitToLatest = latest;
98     doAnalysis();
99   }
100
101   protected Object JavaDoc newInitialFlow() {
102     return set.emptySet();
103   }
104
105   protected Object JavaDoc entryInitialFlow() {
106     return newInitialFlow();
107   }
108
109   protected void flowThrough(Object JavaDoc inValue, Object JavaDoc unit, Object JavaDoc outValue) {
110
111     FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue;
112
113     in.copy(out);
114
115     // Perform generation
116
EquivalentValue rhs = (EquivalentValue)unitToGen.get(unit);
117     if (rhs != null)
118       out.add(rhs);
119
120     // perform kill
121
FlowSet latest = (FlowSet)unitToLatest.getFlowBefore(unit);
122     out.difference(latest);
123   }
124
125   protected void merge(Object JavaDoc in1, Object JavaDoc in2, Object JavaDoc out) {
126     FlowSet inSet1 = (FlowSet) in1;
127     FlowSet inSet2 = (FlowSet) in2;
128
129     FlowSet outSet = (FlowSet) out;
130
131     inSet1.union(inSet2, outSet);
132   }
133
134   protected void copy(Object JavaDoc source, Object JavaDoc dest) {
135     FlowSet sourceSet = (FlowSet) source;
136     FlowSet destSet = (FlowSet) dest;
137
138     sourceSet.copy(destSet);
139   }
140 }
141
Popular Tags