KickJava   Java API By Example, From Geeks To Geeks.

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


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 Delayability-analysis on the given graph.
38  * This analysis is the third analysis in the PRE (lazy code motion) and has
39  * little (no?) sense if used alone. Basicly it tries to push the computations
40  * we would insert in the Busy Code Motion as far down as possible, to decrease
41  * life-time ranges (clearly this is not true, if the computation "uses" two
42  * variables and produces only one temporary).
43  */

44 public class DelayabilityAnalysis extends ForwardFlowAnalysis {
45   private EarliestnessComputation earliest;
46   private Map unitToKillValue;
47   private BoundedFlowSet set;
48
49   /**
50    * this constructor should not be used, and will throw a runtime-exception!
51    */

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

68   public DelayabilityAnalysis(DirectedGraph dg, EarliestnessComputation
69       earliest, Map equivRhsMap) {
70     this(dg, earliest, equivRhsMap, new
71       ArrayPackedSet(new CollectionFlowUniverse(equivRhsMap.values())));
72   }
73
74   /**
75    * automaticly performs the Delayability-analysis on the graph
76    * <code>dg</code> and the Earliest-computation <code>earliest</code>.<br>
77    * the <code>equivRhsMap</code> is only here to avoid doing these things
78    * again...<br>
79    * as set-operations are usually more efficient, if the sets come from one
80    * source, sets should be shared around analyses, if the analyses are to be
81    * combined.
82    *
83    * @param dg a ExceptionalUnitGraph
84    * @param earliest the earliest-computation of the <b>same</b> graph.
85    * @param equivRhsMap the rhs of each unit (if assignment-stmt).
86    * @param set the shared set.
87    */

88   public DelayabilityAnalysis(DirectedGraph dg, EarliestnessComputation
89       earliest, Map equivRhsMap, BoundedFlowSet set) {
90     super(dg);
91     UnitGraph g = (UnitGraph)dg;
92     this.set = set;
93     unitToKillValue = equivRhsMap;
94     this.earliest = earliest;
95
96     doAnalysis();
97     { // finally add the genSet to each BeforeFlow
98
Iterator unitIt = g.iterator();
99       while (unitIt.hasNext()) {
100         Unit currentUnit = (Unit)unitIt.next();
101         FlowSet beforeSet = (FlowSet)getFlowBefore(currentUnit);
102         beforeSet.union((FlowSet)earliest.getFlowBefore(currentUnit));
103       }
104     }
105   }
106
107   protected Object JavaDoc newInitialFlow() {
108     return set.topSet();
109   }
110
111   protected Object JavaDoc entryInitialFlow() {
112     return set.emptySet();
113   }
114
115   protected void flowThrough(Object JavaDoc inValue, Object JavaDoc unit, Object JavaDoc outValue) {
116     FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue;
117
118     in.copy(out);
119
120     // Perform generation
121
out.union((FlowSet)earliest.getFlowBefore((Unit)unit));
122
123     { /* Perform kill */
124       Unit u = (Unit)unit;
125       EquivalentValue equiVal = (EquivalentValue)unitToKillValue.get(u);
126       if (equiVal != null)
127         out.remove(equiVal);
128     }
129   }
130
131   protected void merge(Object JavaDoc in1, Object JavaDoc in2, Object JavaDoc out) {
132     FlowSet inSet1 = (FlowSet) in1;
133     FlowSet inSet2 = (FlowSet) in2;
134
135     FlowSet outSet = (FlowSet) out;
136
137     inSet1.intersection(inSet2, outSet);
138   }
139
140   protected void copy(Object JavaDoc source, Object JavaDoc dest) {
141     FlowSet sourceSet = (FlowSet) source;
142     FlowSet destSet = (FlowSet) dest;
143
144     sourceSet.copy(destSet);
145   }
146 }
147
148
Popular Tags