00001 package edu.ksu.cis.bandera.prog;
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 import ca.mcgill.sable.util.*;
00036 import ca.mcgill.sable.soot.*;
00037 import ca.mcgill.sable.soot.jimple.*;
00038
00039 import edu.ksu.cis.bandera.prog.Index;
00040 import edu.ksu.cis.bandera.util.GenericSet;
00041
00042 public class DomAnalysis extends AbstractDom
00043 {
00044 private Map stmtToDoms;
00045 private Map stmtToImmediateDom;
00046
00047 public DomAnalysis(StmtList statementsList, StmtGraph sg)
00048 {
00049 super(statementsList, sg);
00050 stmtToDoms = new HashMap(stmtList.size() *2 +1, 0.7f);
00051
00052 dominatorsMap();
00053 stmtToImmediateDom = computeImmedDom(stmtToDoms);
00054 }
00055 private void dominatorsMap()
00056 {
00057 GenericSet dominators;
00058 GenericSet tempDoms;
00059 Stmt keyStmt;
00060 Index stmtIndex;
00061 LinkedList workList = new LinkedList();
00062 GenericSet visitedNode = new GenericSet();
00063
00064 GenericSet startNodes = getStartNodes();
00065
00066
00067 for (int i = 0; i< startNodes.size(); i++)
00068 {
00069 stmtIndex = (Index) startNodes.setRef(i);
00070 workList.addFirst(stmtIndex);
00071
00072 keyStmt = (Stmt) stmtList.get(stmtIndex.index());
00073 dominators = new GenericSet(stmtIndex);
00074 stmtToDoms.put(keyStmt, dominators);
00075 }
00076
00077
00078
00079
00080 dominators = indexSetWithoutExceptionHandling();
00081
00082 while (workList.size() != 0)
00083 {
00084 Index nodeIndex = (Index) workList.removeFirst();
00085 visitedNode.addElemToSet(nodeIndex);
00086 Stmt nodeStmt = (Stmt) stmtList.get(nodeIndex.index());
00087
00088 if (! startNodes.contains(nodeIndex))
00089 stmtToDoms.put(nodeStmt, dominators);
00090
00091 List nodeStmtSuccs = stmtGraph.getSuccsOf(nodeStmt);
00092 List newSuccs = removeExceptionCaught(nodeStmtSuccs);
00093 Iterator succIt = newSuccs.iterator();
00094 while (succIt.hasNext())
00095 {
00096 Stmt succStmt = (Stmt) succIt.next();
00097 Index succIndex = new Index(stmtList.indexOf(succStmt));
00098 if (workList.contains(succIndex) ||
00099 visitedNode.contains(succIndex))
00100 {
00101 }
00102 else workList.addLast(succIndex);
00103 }
00104 }
00105
00106
00107
00108 boolean change = true;
00109
00110 while (change)
00111 {
00112 change = false;
00113 workList = new LinkedList();
00114 visitedNode = new GenericSet();
00115
00116 for (int i = 0; i< startNodes.size(); i++)
00117 {
00118 stmtIndex = (Index) startNodes.setRef(i);
00119 workList.addFirst(stmtIndex);
00120 }
00121
00122 while (workList.size() != 0)
00123 {
00124 stmtIndex = (Index) workList.removeFirst();
00125 visitedNode.addElemToSet(stmtIndex);
00126
00127 keyStmt = (Stmt) stmtList.get(stmtIndex.index());
00128 dominators = (GenericSet) stmtToDoms.get(keyStmt);
00129 tempDoms = new GenericSet();
00130 tempDoms = tempDoms.union(dominators);
00131
00132 List preds = stmtGraph.getPredsOf(keyStmt);
00133
00134 for (int i = 0; i < preds.size(); i++)
00135 {
00136 Stmt predStmt = (Stmt) preds.get(i);
00137 GenericSet predDom = (GenericSet) stmtToDoms.get(predStmt);
00138
00139 if (predDom != null)
00140 tempDoms = tempDoms.intersect(predDom);
00141 }
00142
00143 tempDoms.addElemToSet(stmtIndex);
00144
00145 if (! tempDoms.equals(dominators))
00146 {
00147 change = true;
00148 stmtToDoms.remove(keyStmt);
00149 stmtToDoms.put(keyStmt, tempDoms);
00150 }
00151
00152
00153 List keyStmtSuccs = stmtGraph.getSuccsOf(keyStmt);
00154 List newSuccs = removeExceptionCaught(keyStmtSuccs);
00155 Iterator succIt = newSuccs.iterator();
00156 while (succIt.hasNext())
00157 {
00158 Stmt succStmt = (Stmt) succIt.next();
00159 Index succIndex = new Index(stmtList.indexOf(succStmt));
00160 if (workList.contains(succIndex) ||
00161 visitedNode.contains(succIndex))
00162 {
00163 }
00164 else workList.addLast(succIndex);
00165 }
00166 }
00167 }
00168 }
00169 public GenericSet domsOf(Stmt stmt)
00170 {
00171 return (GenericSet) stmtToDoms.get(stmt);
00172 }
00173 public Index immediateDomOf(Stmt s)
00174 {
00175 return (Index) stmtToImmediateDom.get(s);
00176 }
00177 public Map stmtToDominatorsMap()
00178 {
00179 return stmtToDoms;
00180 }
00181 public Map stmtToImmediateDom()
00182 {
00183 return stmtToImmediateDom;
00184 }
00185 }