doInsPrefetchAnalysis(fm);
if(newprefetchset.size() > 0) {
addFlatPrefetchNode(newprefetchset);
- printMethod(fm);
}
}
}
}
break;
case FKind.FlatOpNode:
- processFlatOpNode(curr, child_prefetch_set_copy,parentpmap);
+ processFlatOpNode(curr, child_prefetch_set_copy, parentpmap);
break;
case FKind.FlatLiteralNode:
processFlatLiteralNode(curr, child_prefetch_set_copy, parentpmap);
processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
break;
case FKind.FlatCastNode:
- processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
+ processFlatCastNode(curr, child_prefetch_set_copy, parentpmap);
break;
case FKind.FlatFlagActionNode:
processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
break;
case FKind.FlatTagDeclaration:
- processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
+ processFlatTagDeclaration(curr, child_prefetch_set_copy, parentpmap);
break;
default:
System.out.println("NO SUCH FLATNODE");
}
}
+ /** This functions processes for FlatCastNode
+ * for e.g x = (cast type) y followed by childnode with prefetch set x.f
+ * then drop the prefetches beyond this FlatCastNode */
+ private void processFlatCastNode(FlatNode curr, Hashtable<PrefetchPair, Float>child_prefetch_set_copy,
+ Hashtable<FlatNode, PairMap> parentpmap) {
+ boolean pSetHasChanged = false;
+ Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ FlatCastNode currfcn = (FlatCastNode) curr;
+ Float newprob = new Float((float)0.0);
+ PairMap pm = new PairMap();
+ PrefetchPair childpp = null;
+ Enumeration ecld = null;
+
+ ecld = child_prefetch_set_copy.keys();
+ while (ecld.hasMoreElements()) {
+ childpp = (PrefetchPair) ecld.nextElement();
+ if(childpp.base == currfcn.getDst()){
+ child_prefetch_set_copy.remove(childpp);
+ } else {
+ tocompare.put(childpp, child_prefetch_set_copy.get(childpp));
+ pm.addPair(childpp, childpp);
+ child_prefetch_set_copy.remove(childpp);
+ }
+ }
+
+ /* Create prefetch mappings for child nodes */
+ if(!pm.isEmpty()) {
+ parentpmap.put(curr, pm);
+ }
+ pmap_hash.put(curr.getNext(0), parentpmap);
+
+ /* Compare with the old prefetch set */
+ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare);
+
+ /* Enqueue parent nodes */
+ if(pSetHasChanged) {
+ for(int i=0; i<curr.numPrev(); i++) {
+ tovisit.add(curr.getPrev(i));
+ }
+ /* Overwrite the new prefetch set to the global hash table */
+ prefetch_hash.put(curr,tocompare);
+ }
+ }
+
+ /** This functions processes for FlatTagDeclaration
+ * for e.g x = (cast type) y followed by childnode with prefetch set x.f
+ * then drop the prefetches beyond this FlatTagDeclaration */
+ private void processFlatTagDeclaration(FlatNode curr, Hashtable<PrefetchPair, Float>child_prefetch_set_copy,
+ Hashtable<FlatNode, PairMap> parentpmap) {
+ boolean pSetHasChanged = false;
+ Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ FlatTagDeclaration currftd = (FlatTagDeclaration) curr;
+ Float newprob = new Float((float)0.0);
+ PairMap pm = new PairMap();
+ PrefetchPair childpp = null;
+ Enumeration ecld = null;
+
+ ecld = child_prefetch_set_copy.keys();
+ while (ecld.hasMoreElements()) {
+ childpp = (PrefetchPair) ecld.nextElement();
+ if(childpp.base == currftd.getDst()){
+ child_prefetch_set_copy.remove(childpp);
+ } else {
+ tocompare.put(childpp, child_prefetch_set_copy.get(childpp));
+ pm.addPair(childpp, childpp);
+ child_prefetch_set_copy.remove(childpp);
+ }
+ }
+
+ /* Create prefetch mappings for child nodes */
+ if(!pm.isEmpty()) {
+ parentpmap.put(curr, pm);
+ }
+ pmap_hash.put(curr.getNext(0), parentpmap);
+
+ /* Compare with the old prefetch set */
+ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare);
+
+ /* Enqueue parent nodes */
+ if(pSetHasChanged) {
+ for(int i=0; i<curr.numPrev(); i++) {
+ tovisit.add(curr.getPrev(i));
+ }
+ /* Overwrite the new prefetch set to the global hash table */
+ prefetch_hash.put(curr,tocompare);
+ }
+ }
+
/** This function prints the Prefetch pairs of a given flatnode */
private void printPrefetchPairs(FlatNode fn) {
if(prefetch_hash.containsKey(fn)) {
FlatNode parentnode = (FlatNode) e.nextElement();
PairMap pm = (PairMap) ppairmaphash.get(parentnode);
if(pset1_hash.containsKey(parentnode)) {
- Set pset = pset1_hash.get(parentnode);
+ HashSet pset = pset1_hash.get(parentnode);
if(!pset.isEmpty()) {
if(ppairIsPresent = (pset.contains((PrefetchPair) pm.getPair(pp)))) {
mapIsPresent = ppairIsPresent && mapIsPresent;
}
}
pset1_hash.put(fn, pset1);
- }
- /* To insert prefetch apply rule */
- HashSet s = null;
- if(!newpset.isEmpty() && !pset2.isEmpty()) {
- for(Iterator it = newpset.iterator(); it.hasNext();) {
- PrefetchPair pp = (PrefetchPair) it.next();
- if(!pset2.contains(pp)) {
- s.add(pp);
+ /* To insert prefetch apply rule */
+ HashSet<PrefetchPair> s = new HashSet<PrefetchPair>();
+ //if(!newpset.isEmpty() && !pset2.isEmpty()) {
+ if(!newpset.isEmpty()) {
+ if(!pset2.isEmpty()) {
+ for(Iterator it = newpset.iterator(); it.hasNext();) {
+ PrefetchPair pp = (PrefetchPair) it.next();
+ if(!pset2.contains(pp)) {
+ s.add(pp);
+ }
+ }
+ } else {
+ for(Iterator it = newpset.iterator(); it.hasNext();) {
+ PrefetchPair pp = (PrefetchPair) it.next();
+ s.add(pp);
+ }
}
}
- }
- if(s != null) {
- newprefetchset.put(fn, s);
+ if(s.size() > 0) {
+ newprefetchset.put(fn, s);
+ }
}
}
for(i = 0; i< newprefetchset.get(fn).size(); i++) {
fpn.insAllpp((HashSet)newprefetchset.get(fn));
}
+ //System.out.println("The HashSet of prefetch pairs are "+ fpn.getPrefetchPairs());
if(fn.kind() == FKind.FlatMethod) {
FlatNode nn = fn.getNext(0);
fn.setNext(0, fpn);
fpn.addNext(nn);
-
} else {
while(fn.numPrev() > 0) {
FlatNode nn = fn.getPrev(0);
import Analysis.TaskStateAnalysis.TaskIndex;
import Analysis.Locality.LocalityAnalysis;
import Analysis.Locality.LocalityBinding;
+import Analysis.Prefetch.*;
public class BuildCode {
State state;
/* Generate code for methods */
if (state.DSM) {
for(Iterator<LocalityBinding> lbit=locality.getLocalityBindings().iterator();lbit.hasNext();) {
- LocalityBinding lb=lbit.next();
- MethodDescriptor md=lb.getMethod();
- FlatMethod fm=state.getMethodFlat(md);
- if (!md.getModifiers().isNative()) {
- generateFlatMethod(fm, lb, outmethod);
- }
+ LocalityBinding lb=lbit.next();
+ MethodDescriptor md=lb.getMethod();
+ FlatMethod fm=state.getMethodFlat(md);
+ if (!md.getModifiers().isNative()) {
+ generateFlatMethod(fm, lb, outmethod);
+ }
}
} else {
Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
case FKind.FlatFlagActionNode:
generateFlatFlagActionNode(fm, lb, (FlatFlagActionNode) fn, output);
return;
+ case FKind.FlatPrefetchNode:
+ generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output);
+ return;
}
throw new Error();
-
}
-
+
+ public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) {
+ System.out.println("Inside generateFlatPrefetchNode()");
+ if (state.PREFETCH) {
+ System.out.println("The Prefetch pairs to be fetched are "+ fpn.hspp);
+ Iterator it = fpn.hspp.iterator();
+ for(;it.hasNext();) {
+ PrefetchPair pp = (PrefetchPair) it.next();
+ //TODO handle arrays in prefetch tuples, currently only handle fields
+ Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base);
+ System.out.println("DEBUG-> generateFlatPrefetchNode()" + statusbase);
+ if(statusbase == LocalityAnalysis.GLOBAL) {
+ // Generate oid for base
+ } else {
+ for(int i = 0; i<pp.desc.size(); i++) {
+ Object o = pp.desc.get(i);
+ if(!(o instanceof IndexDescriptor)) {
+ FieldDescriptor fd = (FieldDescriptor) o;
+ Integer statusfd = locality.getNodePreTempInfo(lb,fpn).get(fd);
+ System.out.println("DEBUG-> generateFlatPrefetchNode() fd" + statusfd);
+ //find out the locality of the fieldDescriptor
+ if(statusfd == LocalityAnalysis.GLOBAL) {
+ //generate oid for it
+ }
+ }
+ }
+ }
+ }
+ //Each temp descriptor can be an oid
+ //Find locality of each prefetch tuple in the FLatPrefetchNode
+ //Separate them as Local or Global
+ //generate oids and offset value for prefetch tuple
+ }
+ }
+
public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) {
if (lb!=fgcn.getLocality())
return;
output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
}
+
private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) {
if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray())
throw new Error("Can't set array length");