--- /dev/null
+package Analysis.MLP;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import IR.Flat.TempDescriptor;
+
+public class AccSet {
+
+ private Hashtable<TempDescriptor, HashSet<AccKey>> readTable;
+ private Hashtable<TempDescriptor, HashSet<AccKey>> writeTable;
+
+ public AccSet() {
+
+ readTable = new Hashtable<TempDescriptor, HashSet<AccKey>>();
+ writeTable = new Hashtable<TempDescriptor, HashSet<AccKey>>();
+
+ }
+
+ public void addReadingVar(TempDescriptor td, AccKey access) {
+ HashSet<AccKey> aSet = readTable.get(td);
+ if (aSet == null) {
+ aSet = new HashSet<AccKey>();
+ }
+
+ aSet.add(access);
+ readTable.put(td, aSet);
+ }
+
+ public void addWritingVar(TempDescriptor td, AccKey access) {
+
+ HashSet<AccKey> aSet = writeTable.get(td);
+ if (aSet == null) {
+ aSet = new HashSet<AccKey>();
+ }
+
+ aSet.add(access);
+ writeTable.put(td, aSet);
+
+ }
+
+ public boolean containsParam(TempDescriptor td) {
+
+ Iterator<TempDescriptor> iter = readTable.keySet().iterator();
+
+ while (iter.hasNext()) {
+
+ TempDescriptor key = iter.next();
+ if (key.equals(td)) {
+ return true;
+ }
+
+ }
+
+ return false;
+
+ }
+
+ public void addParam(TempDescriptor paramTD) {
+
+ if (!readTable.containsKey(paramTD)) {
+ HashSet<AccKey> readSet = new HashSet<AccKey>();
+ readTable.put(paramTD, readSet);
+ }
+
+ if (!writeTable.containsKey(paramTD)) {
+ HashSet<AccKey> writeSet = new HashSet<AccKey>();
+ writeTable.put(paramTD, writeSet);
+ }
+
+ }
+
+ public void addAll(AccSet newAccSet) {
+
+ Hashtable<TempDescriptor, HashSet<AccKey>> newReadTable = newAccSet
+ .getReadTable();
+ Hashtable<TempDescriptor, HashSet<AccKey>> newWriteTable = newAccSet
+ .getWriteTable();
+
+ Iterator<TempDescriptor> iter = newReadTable.keySet().iterator();
+ while (iter.hasNext()) { // for each variables
+ TempDescriptor td = iter.next();
+
+ HashSet<AccKey> currentSet;
+ if (!readTable.containsKey(td)) {
+ currentSet = new HashSet<AccKey>();
+ } else {
+ currentSet = readTable.get(td);
+ }
+
+ HashSet<AccKey> newSet = newReadTable.get(td);
+ currentSet.addAll(newSet);
+ readTable.put(td, currentSet);
+ }
+
+ iter = newWriteTable.keySet().iterator();
+ while (iter.hasNext()) { // for each variables
+ TempDescriptor td = iter.next();
+
+ HashSet<AccKey> currentSet;
+ if (!writeTable.containsKey(td)) {
+ currentSet = new HashSet<AccKey>();
+ } else {
+ currentSet = writeTable.get(td);
+ }
+
+ HashSet<AccKey> newSet = newWriteTable.get(td);
+ currentSet.addAll(newSet);
+ writeTable.put(td, currentSet);
+ }
+
+ }
+
+ public Hashtable<TempDescriptor, HashSet<AccKey>> getReadTable() {
+ return readTable;
+ }
+
+ public Hashtable<TempDescriptor, HashSet<AccKey>> getWriteTable() {
+ return writeTable;
+ }
+
+ public boolean equals(Object o) {
+ if (o == null) {
+ return false;
+ }
+
+ if (!(o instanceof AccSet)) {
+ return false;
+ }
+
+ AccSet in = (AccSet) o;
+
+ if (getReadTable().equals(in.getReadTable())
+ && getWriteTable().equals(in.getWriteTable())) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ public void printSet() {
+
+ String readStr = "";
+ String writeStr = "";
+
+ readStr = "#Reading#\r\n";
+ Iterator<TempDescriptor> iter = getReadTable().keySet().iterator();
+ while (iter.hasNext()) { // for each variables
+
+ TempDescriptor td = iter.next();
+ HashSet<AccKey> aSet = readTable.get(td);
+
+ readStr += td.getSymbol() + ":" + "{";
+
+ Iterator<AccKey> setIter = aSet.iterator();
+ while (setIter.hasNext()) {
+ AccKey element = setIter.next();
+ readStr += " " + element;
+ }
+ readStr += "}\r\n";
+ }
+
+ writeStr = "#Writing#\r\n";
+ iter = getWriteTable().keySet().iterator();
+ while (iter.hasNext()) { // for each variables
+
+ TempDescriptor td = iter.next();
+ HashSet<AccKey> aSet = writeTable.get(td);
+
+ writeStr += td.getSymbol() + ":" + "{";
+
+ Iterator<AccKey> setIter = aSet.iterator();
+ while (setIter.hasNext()) {
+ AccKey element = setIter.next();
+ writeStr += " " + element;
+ }
+ writeStr += "}\r\n";
+ }
+
+ System.out.println(readStr);
+ System.out.println(writeStr);
+
+ }
+
+ public String toString() {
+
+ String str = "\n";
+
+ Iterator<TempDescriptor> iter = getReadTable().keySet().iterator();
+ while (iter.hasNext()) { // for each variables
+
+ TempDescriptor td = iter.next();
+
+ str += "\tParameter " + td.getSymbol() + " reading={";
+
+ HashSet<AccKey> aSet = readTable.get(td);
+ Iterator<AccKey> setIter = aSet.iterator();
+ boolean first = true;
+ while (setIter.hasNext()) {
+ AccKey element = setIter.next();
+ if (first) {
+ str += " " + element;
+ first = false;
+ } else {
+ str += " , " + element;
+ }
+
+ }
+ str += " }\n";
+
+ str += "\tParameter " + td.getSymbol() + " writing={";
+
+ aSet = writeTable.get(td);
+ setIter = aSet.iterator();
+ first = true;
+ while (setIter.hasNext()) {
+ AccKey element = setIter.next();
+ if (first) {
+ str += " " + element;
+ first = false;
+ } else {
+ str += " , " + element;
+ }
+
+ }
+ str += " }\n";
+
+ }
+
+ return str;
+ }
+
+}
private Hashtable< FlatNode, VarSrcTokTable > variableResults;
private Hashtable< FlatNode, Set<TempDescriptor> > notAvailableResults;
private Hashtable< FlatNode, CodePlan > codePlans;
+
+ private Hashtable<FlatNode, AccSet> effectsResults;
private Hashtable< FlatEdge, FlatWriteDynamicVarNode > wdvNodesToSpliceIn;
notAvailableResults = new Hashtable< FlatNode, Set<TempDescriptor> >();
codePlans = new Hashtable< FlatNode, CodePlan >();
wdvNodesToSpliceIn = new Hashtable< FlatEdge, FlatWriteDynamicVarNode >();
+
+ effectsResults = new Hashtable<FlatNode, AccSet>();
FlatMethod fmMain = state.getMethodFlat( typeUtil.getMain() );
// point, in a forward fixed-point pass
notAvailableForward( fm );
}
-
+
+ // new pass for method effects analysis
+ methItr = ownAnalysis.descriptorsToAnalyze.iterator();
+ while (methItr.hasNext()) {
+ Descriptor d = methItr.next();
+ FlatMethod fm = state.getMethodFlat(d);
+ effectsForward(fm);
+ }
// 7th pass
methItr = ownAnalysis.descriptorsToAnalyze.iterator();
}
}
+ private void effectsForward(FlatMethod fm) {
+ Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
+ flatNodesToVisit.add(fm);
+
+ while (!flatNodesToVisit.isEmpty()) {
+ FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
+ flatNodesToVisit.remove(fn);
+
+ AccSet prev = effectsResults.get(fn);
+ AccSet curr = new AccSet();
+
+ // merge phase
+ for (int i = 0; i < fn.numPrev(); i++) {
+ FlatNode nn = fn.getPrev(i);
+ AccSet accSet = effectsResults.get(nn);
+ if (accSet != null) {
+ curr.addAll(accSet);
+ }
+ }
+
+ effects_nodeActions(fn, curr);
+
+ // if a new result, schedule forward nodes for analysis
+ if (!curr.equals(prev)) {
+ effectsResults.put(fn, curr);
+ for (int i = 0; i < fn.numNext(); i++) {
+ FlatNode nn = fn.getNext(i);
+ flatNodesToVisit.add(nn);
+ }
+ }
+ }
+
+ }
+
+
+
+
+ private void effects_nodeActions(FlatNode fn, AccSet curr) {
+
+ OwnershipGraph fnOG = ownAnalysis
+ .getMappingFlatNodeToOwnershipGraph(fn);
+
+ switch (fn.kind()) {
+
+ case FKind.FlatMethod: {
+
+ FlatMethod fm = (FlatMethod) fn;
+ int numParam = fm.numParameters();
+
+ for (int i = 0; i < numParam; i++) {
+ TempDescriptor paramTD = fm.getParameter(i);
+
+ curr.addParam(paramTD);
+ }
+
+ // for debug
+ // OwnershipGraph fnOG =
+ // ownAnalysis.getMappingFlatNodeToOwnershipGraph(fn);
+ // try {
+ // fnOG.writeGraph(fn + "FOOGRAPH", true, true, true, true, false);
+ // } catch (IOException e) {
+ // System.out.println("Error writing debug capture.");
+ // System.exit(0);
+ // }
+
+ }
+ break;
+
+ case FKind.FlatSetFieldNode: {
+
+ FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
+
+ TempDescriptor dstDesc = fsfn.getDst();
+ FieldDescriptor fieldDesc = fsfn.getField();
+ TempDescriptor srcDesc = fsfn.getSrc();
+
+ LabelNode ln = fnOG.td2ln.get(dstDesc);
+ if (ln != null) {
+ Iterator<ReferenceEdge> heapRegionsItr = ln
+ .iteratorToReferencees();
+
+ String tempStr = "";
+ while (heapRegionsItr.hasNext()) {
+ HeapRegionNode hrn2 = heapRegionsItr.next().getDst();
+
+ Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
+ .get(hrn2.getID());
+
+ String param = null;
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+ param = "";
+ while (paramIter.hasNext()) {
+ param += paramIter.next() + " ";
+ }
+ }
+ tempStr += " " + hrn2 + "(" + param + ")";
+ }
+
+ heapRegionsItr = ln.iteratorToReferencees();
+ while (heapRegionsItr.hasNext()) {
+ ReferenceEdge edge = heapRegionsItr.next();
+ HeapRegionNode hrn = edge.getDst();
+
+ if (hrn.isParameter()) {
+ // currently, handle this case. otherwise, ignore it.
+ Iterator<ReferenceEdge> iter = hrn
+ .iteratorToReferencers();
+ while (iter.hasNext()) {
+ ReferenceEdge re = iter.next();
+ if (re.getSrc() instanceof LabelNode) {
+ LabelNode labelNode = (LabelNode) re.getSrc();
+
+ if (curr.containsParam(labelNode
+ .getTempDescriptor())) {
+
+ curr.addWritingVar(labelNode
+ .getTempDescriptor(), new AccKey(
+ fieldDesc.getSymbol(), dstDesc
+ .getType()));
+
+ }
+
+ }
+ }
+
+ // check weather this heap region is parameter
+ // reachable...
+
+ Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
+ .get(hrn.getID());
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+
+ Integer primaryID = fnOG.paramIndex2idPrimary
+ .get(paramID);
+ HeapRegionNode paramHRN = fnOG.id2hrn
+ .get(primaryID);
+
+ HashSet<LabelNode> LNSet = getParameterLabelNodeSet(
+ fnOG, curr, paramHRN);
+
+ Iterator<LabelNode> LNSetIter = LNSet
+ .iterator();
+ while (LNSetIter.hasNext()) {
+ LabelNode labelNode = LNSetIter.next();
+
+ curr.addWritingVar(labelNode
+ .getTempDescriptor(), new AccKey(
+ fieldDesc.getSymbol(), dstDesc
+ .getType()));
+ }
+
+ }
+ }
+
+ }
+
+ }
+ }
+
+ }
+ break;
+
+ case FKind.FlatFieldNode: {
+
+ FlatFieldNode ffn = (FlatFieldNode) fn;
+
+ TempDescriptor srcDesc = ffn.getSrc();
+ FieldDescriptor fieldDesc = ffn.getField();
+
+ LabelNode ln = fnOG.td2ln.get(srcDesc);
+ if (ln != null) {
+
+ Iterator<ReferenceEdge> heapRegionsItr = ln
+ .iteratorToReferencees();
+ String tempStr = "";
+ while (heapRegionsItr.hasNext()) {
+
+ HeapRegionNode hrn = heapRegionsItr.next().getDst();
+
+ Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
+ .get(hrn.getID());
+
+ String param = null;
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+ param = "";
+ while (paramIter.hasNext()) {
+ param += paramIter.next() + " ";
+ }
+ }
+ tempStr += " " + hrn + "(" + param + ")";
+ }
+
+ heapRegionsItr = ln.iteratorToReferencees();
+ while (heapRegionsItr.hasNext()) {
+ ReferenceEdge edge = heapRegionsItr.next();
+ HeapRegionNode hrn = edge.getDst();
+
+ if (hrn.isParameter()) {
+ Iterator<ReferenceEdge> iter = hrn
+ .iteratorToReferencers();
+
+ while (iter.hasNext()) {
+ ReferenceEdge re = iter.next();
+ if (re.getSrc() instanceof LabelNode) {
+
+ LabelNode labelNode = (LabelNode) re.getSrc();
+
+ if (curr.containsParam(labelNode
+ .getTempDescriptor())) {
+ curr.addReadingVar(labelNode
+ .getTempDescriptor(), new AccKey(
+ fieldDesc.getSymbol(), srcDesc
+ .getType()));
+ }
+ }
+ }
+
+ //
+ // check weather this heap region is parameter
+ // reachable...
+ //
+
+ Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
+ .get(hrn.getID());
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+
+ Integer primaryID = fnOG.paramIndex2idPrimary
+ .get(paramID);
+ HeapRegionNode paramHRN = fnOG.id2hrn
+ .get(primaryID);
+
+ HashSet<LabelNode> LNSet = getParameterLabelNodeSet(
+ fnOG, curr, paramHRN);
+
+ Iterator<LabelNode> LNSetIter = LNSet
+ .iterator();
+ while (LNSetIter.hasNext()) {
+ LabelNode labelNode = LNSetIter.next();
+
+ curr.addReadingVar(labelNode
+ .getTempDescriptor(), new AccKey(
+ fieldDesc.getSymbol(), srcDesc
+ .getType()));
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ break;
+
+ }
+
+ }
+
+ // returns the set of parameter label node which are associated with the
+ // specific heap region node.
+ private HashSet<LabelNode> getParameterLabelNodeSet(OwnershipGraph og,
+ AccSet curr, HeapRegionNode hrn) {
+
+ HashSet<LabelNode> set = new HashSet<LabelNode>();
+ Iterator<ReferenceEdge> iter = hrn.iteratorToReferencers();
+ while (iter.hasNext()) {
+ ReferenceEdge re = iter.next();
+ if (re.getSrc() instanceof LabelNode) {
+ LabelNode labelNode = (LabelNode) re.getSrc();
+ if (curr.containsParam(labelNode.getTempDescriptor())) {
+ set.add(labelNode);
+ }
+ }
+ }
+ return set;
+ }
private void notAvailableForward( FlatMethod fm ) {