From 32dda9662b0ad3fbef4a75c8ca10e39396e54d7f Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 25 Sep 2007 00:07:44 +0000 Subject: [PATCH] file where prefetch analysis will reside --- .../Analysis/Prefetch/PrefetchAnalysis.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Robust/src/Analysis/Prefetch/PrefetchAnalysis.java diff --git a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java new file mode 100644 index 00000000..4d9e4fd9 --- /dev/null +++ b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java @@ -0,0 +1,106 @@ +package Analysis.Prefetch; + +import java.util.*; +import Analysis.CallGraph.CallGraph; +import IR.SymbolTable; +import IR.State; +import IR.TypeUtil; +import IR.MethodDescriptor; +import IR.Flat.*; +import IR.ClassDescriptor; + +public class PrefetchAnalysis { + State state; + CallGraph callgraph; + TypeUtil typeutil; + + public PrefetchAnalysis(State state, CallGraph callgraph, TypeUtil typeutil) { + this.typeutil=typeutil; + this.state=state; + this.callgraph=callgraph; + doAnalysis(); + } + + private void doAnalysis() { + Iterator classit=state.getClassSymbolTable().getDescriptorsIterator( +); + while(classit.hasNext()) { + ClassDescriptor cn=(ClassDescriptor)classit.next(); + Iterator methodit=cn.getMethods(); + while(methodit.hasNext()) { + /* Classify parameters */ + MethodDescriptor md=(MethodDescriptor)methodit.next(); + FlatMethod fm=state.getMethodFlat(md); + printMethod(fm); + } + } + } + + private void printMethod(FlatMethod fm) { + System.out.println(fm.getMethod()+" {"); + HashSet tovisit=new HashSet(); + HashSet visited=new HashSet(); + int labelindex=0; + Hashtable nodetolabel=new Hashtable(); + tovisit.add(fm); + FlatNode current_node=null; + //Assign labels 1st + //Node needs a label if it is + while(!tovisit.isEmpty()) { + FlatNode fn=(FlatNode)tovisit.iterator().next(); + tovisit.remove(fn); + visited.add(fn); + + for(int i=0;i0) { + //1) Edge >1 of node + nodetolabel.put(nn,new Integer(labelindex++)); + } + if (!visited.contains(nn)&&!tovisit.contains(nn)) { + tovisit.add(nn); + } else { + //2) Join point + nodetolabel.put(nn,new Integer(labelindex++)); + } + } + } + //Do the actual printing + tovisit=new HashSet(); + visited=new HashSet(); + tovisit.add(fm); + while(current_node!=null||!tovisit.isEmpty()) { + if (current_node==null) { + current_node=(FlatNode)tovisit.iterator().next(); + tovisit.remove(current_node); + } + visited.add(current_node); + if (nodetolabel.containsKey(current_node)) + System.out.println("L"+nodetolabel.get(current_node)+":"); + if (current_node.numNext()==0) { + System.out.println(" "+current_node.toString()); + current_node=null; + } else if(current_node.numNext()==1) { + System.out.println(" "+current_node.toString()); + FlatNode nextnode=current_node.getNext(0); + if (visited.contains(nextnode)) { + System.out.println("goto L"+nodetolabel.get(nextnode)); + current_node=null; + } else + current_node=nextnode; + } else if (current_node.numNext()==2) { + /* Branch */ + System.out.println(" "+((FlatCondBranch)current_node).toString("L"+nodetolabel.get(current_node.getNext(1)))); + if (!visited.contains(current_node.getNext(1))) + tovisit.add(current_node.getNext(1)); + if (visited.contains(current_node.getNext(0))) { + System.out.println("goto L"+nodetolabel.get(current_node.getNext(0))); + current_node=null; + } else + current_node=current_node.getNext(0); + } else throw new Error(); + } + System.out.println("}"); + } + +} -- 2.34.1