X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FPrefetch%2FPrefetchPair.java;h=fa0ecaab1ec560366c7a341faa5264bcd8a7f997;hb=4cb63e913202459da4fe9d01feb7c02f1b98dd6f;hp=1c23f82fbf26c459eba5f8038f48c9deca7ebf01;hpb=53ca4456abf8f30b1e45ae73379be6d053f2b292;p=IRC.git diff --git a/Robust/src/Analysis/Prefetch/PrefetchPair.java b/Robust/src/Analysis/Prefetch/PrefetchPair.java index 1c23f82f..fa0ecaab 100644 --- a/Robust/src/Analysis/Prefetch/PrefetchPair.java +++ b/Robust/src/Analysis/Prefetch/PrefetchPair.java @@ -4,24 +4,136 @@ import java.util.*; import IR.*; public class PrefetchPair { - TempDescriptor td; - FieldDescriptor fd; - public float num; + public TempDescriptor base; + public ArrayList desc; + + public PrefetchPair(){ + base = new TempDescriptor(""); + desc = new ArrayList(); + } + + public PrefetchPair(TempDescriptor t, Descriptor f) { + base = t; + desc = new ArrayList(); + desc.add(f); + } - public PrefetchPair() { - } + public PrefetchPair(TempDescriptor t, ArrayList descriptor) { + base = t; + desc = new ArrayList(); + desc.addAll(descriptor); + } - public PrefetchPair(TempDescriptor td, float prob) { - this.td = td; - num = prob; + public TempDescriptor getBase() { + return base; + } + + public Descriptor getDescAt(int index) { + return desc.get(index); + } + + public ArrayList getDesc() { + return desc; + } + + public FieldDescriptor getFieldDesc(int index) { + return (FieldDescriptor) desc.get(index); + } + + public IndexDescriptor getIndexDesc(int index) { + return (IndexDescriptor) desc.get(index); + } + + public int hashCode() { + int hashcode = base.toString().hashCode(); + if(desc != null) { + hashcode^=desc.hashCode(); + } + return hashcode; + } + + public String toString() { + String label= getBase().toString(); + if(getDesc() == null) + return label; + ListIterator it=getDesc().listIterator(); + for(;it.hasNext();) { + Object o = it.next(); + if(o instanceof FieldDescriptor) { + FieldDescriptor fd = (FieldDescriptor) o; + label+="."+ fd.toString(); + } else { + IndexDescriptor id = (IndexDescriptor) o; + label+= id.toString(); + } + } + return label; + } + + public boolean equals(Object o) { + if(o instanceof PrefetchPair) { + PrefetchPair pp = (PrefetchPair) o; + return base == pp.base && desc.equals(pp.desc); } + return false; + } + + public Object clone() { + PrefetchPair newpp = new PrefetchPair(); + newpp.base = this.base; + for(int i = 0; i < this.desc.size(); i++) { + Object o = desc.get(i); + if(o instanceof FieldDescriptor) { + newpp.desc.add((FieldDescriptor) o); + } else { + ArrayList td = new ArrayList(); + for(int j = 0; j < ((IndexDescriptor)o).tddesc.size(); j++) { + td.add(((IndexDescriptor)o).getTempDescAt(j)); + } + IndexDescriptor idesc = new IndexDescriptor(); + idesc.tddesc = td; + idesc.offset = ((IndexDescriptor)o).offset; + newpp.desc.add(idesc); + } + } + return newpp; + } - public TempDescriptor getTemp() { - return td; + /** This function returns true if a tempdescriptor object is found in the array of descriptors + * for a given prefetch pair else returns false*/ + public boolean containsTemp(TempDescriptor td) { + ArrayList desc = (ArrayList) getDesc(); + for(ListIterator it = desc.listIterator();it.hasNext();) { + Object o = it.next(); + if(o instanceof IndexDescriptor) { + ArrayList tdarray = (ArrayList)((IndexDescriptor)o).tddesc; + if(tdarray.contains(td)) { + return true; + } + } } + return false; + } - public String toString() { - //if(getTemp()!=null) - return"<"+getTemp()+">"; + /** This function creates a new Arraylist of Descriptors by replacing old tempdescriptors with new + * tempdescriptors when there is a match */ + public PrefetchPair replaceTemp(TempDescriptor td, TempDescriptor[] newtd) { + PrefetchPair npp=(PrefetchPair)clone(); + ArrayList desc = (ArrayList) npp.getDesc(); + for(ListIterator it = desc.listIterator();it.hasNext();) { + Object currdesc = it.next(); + if(currdesc instanceof IndexDescriptor) { + ArrayList tdarray = (ArrayList)((IndexDescriptor)currdesc).tddesc; + if (tdarray.contains(td)) { + int index = tdarray.indexOf(td); + tdarray.set(index, newtd[0]); + for(int i=1;i