KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > scalar > SlowAvailableExpressions


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2000 Patrick Lam
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-1999.
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;
28 import soot.*;
29 import soot.toolkits.scalar.*;
30 import soot.toolkits.graph.*;
31 import soot.jimple.*;
32 import java.util.*;
33 import soot.util.*;
34
35 /** Provides an user-interface for the AvailableExpressionsAnalysis class.
36  * Returns, for each statement, the list of expressions available before and after it. */

37 public class SlowAvailableExpressions implements AvailableExpressions
38 {
39     Map unitToPairsAfter;
40     Map unitToPairsBefore;
41
42     Map unitToEquivsAfter;
43     Map unitToEquivsBefore;
44
45     /** Wrapper for SlowAvailableExpressionsAnalysis. */
46     public SlowAvailableExpressions(Body b)
47     {
48         SlowAvailableExpressionsAnalysis analysis =
49             new SlowAvailableExpressionsAnalysis(new ExceptionalUnitGraph(b));
50
51         // Build unitToExprs map
52
{
53             unitToPairsAfter = new HashMap(b.getUnits().size() * 2 + 1, 0.7f);
54             unitToPairsBefore = new HashMap(b.getUnits().size() * 2 + 1, 0.7f);
55             unitToEquivsAfter = new HashMap(b.getUnits().size() * 2 + 1, 0.7f);
56             unitToEquivsBefore = new HashMap(b.getUnits().size() * 2 + 1, 0.7f);
57
58             Iterator unitIt = b.getUnits().iterator();
59
60             while(unitIt.hasNext())
61             {
62                 Unit s = (Unit) unitIt.next();
63  
64                 FlowSet set = (FlowSet) analysis.getFlowBefore(s);
65
66                 List pairsBefore = new ArrayList();
67                 List pairsAfter = new ArrayList();
68
69                 Chain equivsBefore = new HashChain();
70                 Chain equivsAfter = new HashChain();
71
72                 List setAsList = set.toList();
73                 Iterator si = setAsList.iterator();
74                 while (si.hasNext())
75                 {
76                     Value v = (Value)si.next();
77                     Stmt containingStmt = (Stmt)analysis.rhsToContainingStmt.get(v);
78                     UnitValueBoxPair p = new UnitValueBoxPair
79                         (containingStmt, ((AssignStmt)containingStmt).getRightOpBox());
80                     EquivalentValue ev = new EquivalentValue(v);
81                     pairsBefore.add(p);
82                     if (!equivsBefore.contains(ev))
83                         equivsBefore.add(ev);
84                 }
85
86                 unitToPairsBefore.put(s, pairsBefore);
87                 unitToEquivsBefore.put(s, equivsBefore);
88                 
89                 set = (FlowSet) analysis.getFlowAfter(s);
90                 setAsList = set.toList();
91                 si = setAsList.iterator();
92                 while (si.hasNext())
93                 {
94                     Value v = (Value)si.next();
95                     Stmt containingStmt = (Stmt)analysis.rhsToContainingStmt.get(v);
96                     UnitValueBoxPair p = new UnitValueBoxPair
97                         (containingStmt, ((AssignStmt)containingStmt).getRightOpBox());
98                     EquivalentValue ev = new EquivalentValue(v);
99                     pairsAfter.add(p);
100                     if (!equivsAfter.contains(ev))
101                         equivsAfter.add(ev);
102                 }
103
104                 unitToPairsAfter.put(s, pairsAfter);
105                 unitToEquivsAfter.put(s, equivsAfter);
106             }
107         }
108     }
109
110     /** Returns a List containing the UnitValueBox pairs corresponding to expressions available before u. */
111     public List getAvailablePairsBefore(Unit u)
112     {
113         return (List)unitToPairsBefore.get(u);
114     }
115
116     /** Returns a List containing the UnitValueBox pairs corresponding to expressions available after u. */
117     public List getAvailablePairsAfter(Unit u)
118     {
119         return (List)unitToPairsAfter.get(u);
120     }
121
122     /** Returns a Chain containing the EquivalentValue objects corresponding to expressions available before u. */
123     public Chain getAvailableEquivsBefore(Unit u)
124     {
125         return (Chain)unitToEquivsBefore.get(u);
126     }
127
128     /** Returns a Chain containing the EquivalentValue objects corresponding to expressions available after u. */
129     public Chain getAvailableEquivsAfter(Unit u)
130     {
131         return (Chain)unitToEquivsAfter.get(u);
132     }
133 }
134
Popular Tags