From 4aa6f489c6dd772dcafefead48884d49d8296720 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 8 Aug 2007 20:49:22 +0000 Subject: [PATCH] Simplify BuildCode more... --- .../Analysis/Locality/LocalityBinding.java | 26 ++++ Robust/src/IR/Flat/BuildCode.java | 126 +++++++++++------- 2 files changed, 105 insertions(+), 47 deletions(-) diff --git a/Robust/src/Analysis/Locality/LocalityBinding.java b/Robust/src/Analysis/Locality/LocalityBinding.java index 890835fd..28795f9c 100644 --- a/Robust/src/Analysis/Locality/LocalityBinding.java +++ b/Robust/src/Analysis/Locality/LocalityBinding.java @@ -15,6 +15,32 @@ public class LocalityBinding { isatomic=atomic; } + private static String globalToString(Integer g) { + if (g==LocalityAnalysis.GLOBAL) + return "G"; + else if (g==LocalityAnalysis.LOCAL) + return "L"; + else if (g==LocalityAnalysis.EITHER) + return "E"; + else if (g==LocalityAnalysis.CONFLICT) + return "C"; + else throw new Error(); + } + + public String getSignature() { + String st="_"; + if (isatomic) { + st+="A"; + } else + st+="N"; + st+=globalToString(isglobalthis); + for(int i=0;i 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,outmethod); + if (!md.getModifiers().isNative()) { + generateFlatMethod(fm, lb, outmethod); + } } - } + + + } else { + 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); + if (!md.getModifiers().isNative()) + generateFlatMethod(fm, null, outmethod); + } + } + } } private void outputStructs(PrintWriter outstructs) { @@ -976,7 +997,7 @@ public class BuildCode { /** Generate code for FlatMethod fm. */ - private void generateFlatMethod(FlatMethod fm, PrintWriter output) { + private void generateFlatMethod(FlatMethod fm, LocalityBinding lb, PrintWriter output) { MethodDescriptor md=fm.getMethod(); TaskDescriptor task=fm.getTask(); @@ -984,11 +1005,10 @@ public class BuildCode { ParamsObject objectparams=(ParamsObject)paramstable.get(md!=null?md:task); - generateHeader(fm, md!=null?md:task,output); + generateHeader(fm, lb, md!=null?md:task,output); TempObject objecttemp=(TempObject) tempstable.get(md!=null?md:task); - /* Print code */ if (GENERATEPRECISEGC) { if (md!=null) output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); @@ -1013,42 +1033,21 @@ public class BuildCode { output.println(" "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";"); } - /* Generate labels first */ - HashSet tovisit=new HashSet(); - HashSet visited=new HashSet(); - int labelindex=0; - Hashtable nodetolabel=new Hashtable(); - tovisit.add(fm.getNext(0)); - FlatNode current_node=null; + /* Assign labels to FlatNode's if necessary.*/ - //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++)); - } - } - } + Hashtable nodetolabel=assignLabels(fm); + + /* Check to see if we need to do a GC if this is a + * multi-threaded program...*/ if (state.THREAD&&GENERATEPRECISEGC) { output.println("checkcollect(&"+localsprefix+");"); } - //Do the actual code generation - tovisit=new HashSet(); - visited=new HashSet(); + /* Do the actual code generation */ + FlatNode current_node=null; + HashSet tovisit=new HashSet(); + HashSet visited=new HashSet(); tovisit.add(fm.getNext(0)); while(current_node!=null||!tovisit.isEmpty()) { if (current_node==null) { @@ -1095,10 +1094,43 @@ public class BuildCode { } else throw new Error(); } - output.println("}\n\n"); } + /** This method assigns labels to flatnodes */ + + private Hashtable assignLabels(FlatMethod fm) { + HashSet tovisit=new HashSet(); + HashSet visited=new HashSet(); + int labelindex=0; + Hashtable nodetolabel=new Hashtable(); + tovisit.add(fm.getNext(0)); + + /*Assign labels first. A node needs a label if the previous + * node has two exits or this node is a join point. */ + + 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++)); + } + } + } + return nodetolabel; + } + + /** Generate text string that corresponds to the Temp td. */ private String generateTemp(FlatMethod fm, TempDescriptor td) { MethodDescriptor md=fm.getMethod(); @@ -1462,7 +1494,7 @@ public class BuildCode { /** This method generates header information for the method or * task referenced by the Descriptor des. */ - private void generateHeader(FlatMethod fm, Descriptor des, PrintWriter output) { + private void generateHeader(FlatMethod fm, LocalityBinding lb, Descriptor des, PrintWriter output) { /* Print header */ ParamsObject objectparams=(ParamsObject)paramstable.get(des); MethodDescriptor md=null; -- 2.34.1