Lots of changes that aren't working yet, so new methods are commented and existing...
authorjjenista <jjenista>
Thu, 14 May 2009 21:37:42 +0000 (21:37 +0000)
committerjjenista <jjenista>
Thu, 14 May 2009 21:37:42 +0000 (21:37 +0000)
Robust/src/Analysis/MLP/MLPAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/FlatSESEEnterNode.java
Robust/src/Main/Main.java
Robust/src/Tests/mlp/tinyTest/makefile
Robust/src/Tests/mlp/tinyTest/test.java

index 9a4dbff149b693fc4944cf58b43aa5bbda528b4a..57bfbb65c2aa17d2ed530f31761e05d36658d30c 100644 (file)
@@ -21,6 +21,8 @@ public class MLPAnalysis {
   private FlatSESEEnterNode rootSESE;
   private FlatSESEExitNode  rootExit;
 
+  private Set<FlatSESEEnterNode> allSESEs;
+
   private Hashtable< FlatNode, Stack<FlatSESEEnterNode> > seseStacks;
   private Hashtable< FlatNode, Set<TempDescriptor>      > livenessRootView;
   private Hashtable< FlatNode, Set<TempDescriptor>      > livenessVirtualReads;
@@ -29,6 +31,18 @@ public class MLPAnalysis {
   private Hashtable< FlatNode, CodePlan                 > codePlans;
 
 
+  // use these methods in BuildCode to have access to analysis results
+  public Set<FlatSESEEnterNode> getAllSESEs() {
+    return allSESEs;
+  }
+
+  public CodePlan getCodePlan( FlatNode fn ) {
+    CodePlan cp = codePlans.get( fn );
+    assert cp != null;
+    return cp;
+  }
+
+
   public MLPAnalysis( State             state,
                      TypeUtil          tu,
                      CallGraph         callGraph,
@@ -43,6 +57,8 @@ public class MLPAnalysis {
     this.ownAnalysis = ownAnalysis;
 
     // initialize analysis data structures
+    allSESEs = new HashSet<FlatSESEEnterNode>();
+
     seseStacks           = new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
     livenessVirtualReads = new Hashtable< FlatNode, Set<TempDescriptor>      >();
     variableResults      = new Hashtable< FlatNode, VarSrcTokTable           >();
@@ -50,7 +66,6 @@ public class MLPAnalysis {
     codePlans            = new Hashtable< FlatNode, CodePlan                 >();
 
 
-
     // build an implicit root SESE to wrap contents of main method
     rootTree = new SESENode( "root" );
     rootSESE = new FlatSESEEnterNode( rootTree );
@@ -151,7 +166,7 @@ public class MLPAnalysis {
       flatNodesToVisit.remove( fn );
       visited.add( fn );      
 
-      buildForest_nodeActions( fn, seseStack );
+      buildForest_nodeActions( fn, seseStack, fm );
 
       for( int i = 0; i < fn.numNext(); i++ ) {
        FlatNode nn = fn.getNext( i );
@@ -171,11 +186,16 @@ public class MLPAnalysis {
   }
 
   private void buildForest_nodeActions( FlatNode fn,                                                      
-                                       Stack<FlatSESEEnterNode> seseStack ) {
+                                       Stack<FlatSESEEnterNode> seseStack,
+                                       FlatMethod fm ) {
     switch( fn.kind() ) {
 
     case FKind.FlatSESEEnterNode: {
-      FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;      
+      FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
+
+      allSESEs.add( fsen );
+      fsen.setEnclosingFlatMeth( fm );
+
       assert !seseStack.empty();
       seseStack.peek().addChild( fsen );
       fsen.setParent( seseStack.peek() );
index 7d6f8b85410a2bd649461730049e3a3cd572c27b..0d1cbb67c3bf73e42dca57bedb68316ff9feb13d 100644 (file)
@@ -22,6 +22,7 @@ import Analysis.CallGraph.CallGraph;
 import Analysis.Prefetch.*;
 import Analysis.Loops.WriteBarrier;
 import Analysis.Locality.TypeAnalysis;
+import Analysis.MLP.MLPAnalysis;
 
 public class BuildCode {
   State state;
@@ -52,23 +53,28 @@ public class BuildCode {
   Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>> backuptable;
   SafetyAnalysis sa;
   PrefetchAnalysis pa;
-  HashSet<FlatSESEEnterNode> setSESEtoGen;
+  MLPAnalysis mlpa;
   boolean nonSESEpass=true;
   WriteBarrier wb;
   DiscoverConflicts dc;
   CallGraph callgraph;
 
   public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
-    this(st, temptovar, typeutil, null, sa, pa);
+    this(st, temptovar, typeutil, null, sa, pa, null);
   }
 
-  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa) {
-    this(st, temptovar, typeutil, locality, null, pa);
+  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa) {
+    this(st, temptovar, typeutil, null, sa, pa, mlpa);
   }
 
-  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa) {
+  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa, MLPAnalysis mlpa) {
+    this(st, temptovar, typeutil, locality, null, pa, mlpa);
+  }
+
+  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa) {
     this.sa=sa;
     this.pa=pa;
+    this.mlpa=mlpa;
     state=st;
     callgraph=new CallGraph(state);
     if (state.SINGLETM)
@@ -91,8 +97,6 @@ public class BuildCode {
       this.dc=new DiscoverConflicts(locality, st, typeanalysis);
       dc.doAnalysis();
     }
-
-    setSESEtoGen = new HashSet<FlatSESEEnterNode>();
   }
 
   /** The buildCode method outputs C code for all the methods.  The Flat
@@ -184,15 +188,13 @@ public class BuildCode {
     /* Build the actual methods */
     outputMethods(outmethod);
 
+    // Output function prototypes and structures for SESE's and code
     if( state.MLP ) {
       nonSESEpass = false;
-      while( !setSESEtoGen.isEmpty() ) {
-       FlatSESEEnterNode fsen = setSESEtoGen.iterator().next();
-       setSESEtoGen.remove(fsen);
-       generateMethodSESE(fsen, fsen.getEnclosingFlatMeth(), null, outmethod);
+      for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
+       FlatSESEEnterNode fsen = seseit.next();
+       generateMethodSESE(fsen, null, outstructs, outmethodheader, outmethod);
       }
-    } else {
-      assert setSESEtoGen.isEmpty();
     }
 
     if (state.TASK) {
@@ -1489,35 +1491,156 @@ public class BuildCode {
     output.println("}\n\n");
   }
 
+  /***** Generate code for FlatMethod fm. *****/
+
+  private void generateFlatMethodSESE(FlatMethod fm, 
+                                      ClassDescriptor cn, 
+                                      FlatSESEEnterNode seseEnter, 
+                                      FlatSESEExitNode  seseExit, 
+                                      PrintWriter output
+                                      ) {
+    /*
+    MethodDescriptor md=fm.getMethod();
+    ParamsObject objectparams=(ParamsObject)paramstable.get(md);
+    //generateHeader(fm, lb, md);
+    TempObject objecttemp=(TempObject) tempstable.get(md);
+    */
+
+    /*
+    if (GENERATEPRECISEGC) {
+      output.print("   struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
+      output.print(objecttemp.numPointers()+",");
+      output.print(paramsprefix);
+      for(int j=0; j<objecttemp.numPointers(); j++)
+       output.print(", NULL");
+      output.println("};");
+    }
+    */
+
+    /*
+    for(int i=0; i<objecttemp.numPrimitives(); i++) {
+      TempDescriptor td=objecttemp.getPrimitive(i);
+      TypeDescriptor type=td.getType();
+      if (type.isNull())
+       output.println("   void * "+td.getSafeSymbol()+";");
+      else if (type.isClass()||type.isArray())
+       output.println("   struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";");
+      else
+       output.println("   "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
+    }
+    */
+
+    /* Check to see if we need to do a GC if this is a
+     * multi-threaded program...*/
+
+    /*
+    if (GENERATEPRECISEGC) {
+      //Don't bother if we aren't in recursive methods...The loops case will catch it
+      if (callgraph.getAllMethods(md).contains(md)) {
+        output.println("if (needtocollect) checkcollect(&"+localsprefix+");");
+      }
+    }
+    */
+
+    //generateCode(seseEnter, getNext(0), fm, null, seseExit, output);
+
+    //output.println("}\n\n");
+  }
 
   protected void generateMethodSESE(FlatSESEEnterNode fsen,
-                                    FlatMethod fm,
                                     LocalityBinding lb,
-                                    PrintWriter output) {
-
-    //output.println( "void _SESE"+fsen.getPrettyIdentifier()+
-    //" {\n" );
-    //generateCode( fsen.getNext(0), fm, lb, fsen.getFlatExit(), output );
-    //output.println( "}\n\n" );
+                                    PrintWriter outputStructs,
+                                    PrintWriter outputMethHead,
+                                    PrintWriter outputMethods
+                                    ) {
 
     /*
-       output.println("struct sese"+faen.getPrettyIdentifier()+"in {");
-       Iterator<TempDescriptor> itr = faen.getInVarSet().iterator();
-       while( itr.hasNext() ) {
-       TempDescriptor td = itr.next();
-       output.println("  "+td+";");
-       }
-       output.println("}");
+    FlatMethod       fm = fsen.getEnclosingFlatMeth();
+    MethodDescriptor md = fm.getMethod();
+    ClassDescriptor  cn = md.getClassDesc();
+    
+    
+    //Creates bogus method descriptor to index into tables
+    Modifiers bogusmod=new Modifiers();
+    MethodDescriptor bogusmd=new MethodDescriptor(bogusmod, new TypeDescriptor(TypeDescriptor.VOID), fsen.getIdentifier());
+    FlatMethod bogusfm=new FlatMethod(bogusmd, null);
+    
+    //Build paramsobj for bogus method descriptor
+    ParamsObject objectparams=new ParamsObject(bogusmd, tag++);
+    paramstable.put(bogusmd, objectparams);
+    
+    for(int i=0; i<fsen.numParameters(); i++) {
+      TempDescriptor temp=fsen.getParameter(i);
+      TypeDescriptor type=temp.getType();
+      if (type.isPtr()&&GENERATEPRECISEGC)
+       objectparams.addPtr(temp);
+      else
+       objectparams.addPrim(temp);
+    }
+    
+    //Build normal temp object for bogus method descriptor
+    
+    TempObject objecttemps=new TempObject(objectparams,bogusmd,tag++);
+    tempstable.put(bogusmd, objecttemps);
+    
+    for(Iterator nodeit=fsen.getNodeSet().iterator(); nodeit.hasNext();) {
+      FlatNode fn=(FlatNode)nodeit.next();
+      TempDescriptor[] writes=fn.writesTemps();
+      for(int i=0; i<writes.length; i++) {
+       TempDescriptor temp=writes[i];
+       TypeDescriptor type=temp.getType();
+       if (type.isPtr()&&GENERATEPRECISEGC)
+         objecttemps.addPtr(temp);
+       else
+         objecttemps.addPrim(temp);
+      }
+    }
+    
+    //Generate code for parameters structure
+
+    generateMethodParam(cn, bogusmd, null, outputStructs); 
+
+    //Generate code for locals structure
+    outputStructs.println("struct "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()+"_locals {");
+    outputStructs.println("  INTPTR size;");
+    outputStructs.println("  void * next;");
+    for(int i=0; i<objecttemps.numPointers(); i++) {
+      TempDescriptor temp=objecttemps.getPointer(i);
+      if (temp.getType().isNull())
+        outputStructs.println("  void * "+temp.getSafeSymbol()+";");
+      else
+        outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
+    }
+    outputStructs.println("};\n");
+    
+    //Ready to build code at this point
 
-       output.println("struct sese"+faen.getPrettyIdentifier()+"out {");
-       itr = faen.getOutVarSet().iterator();
-       while( itr.hasNext() ) {
-       TempDescriptor td = itr.next();
-       output.println("  "+td+";");
-       }
-       output.println("}");
-     */
+    headersout.print("void ");
 
+    // Next the method name
+    headersout.print(cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()+"(");
+
+    boolean printcomma=false;
+    if (GENERATEPRECISEGC) {
+      headersout.print("struct "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()+"_params * "+paramsprefix);
+      printcomma=true;
+    }
+
+    //  Output parameter list
+    for(int i=0; i<objectparams.numPrimitives(); i++) {
+      TempDescriptor temp=objectparams.getPrimitive(i);
+      if (printcomma)
+       headersout.print(", ");
+      printcomma=true;
+      if (temp.getType().isClass()||temp.getType().isArray())
+       headersout.print("struct " + temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
+      else
+       headersout.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
+    }
+    headersout.println(");\n");
+
+    generateFlatMethodSESE(bogusfm, cn, fsen, fsen.getFlatExit(), output?????????);
+    */
   }
 
 
@@ -1565,10 +1688,6 @@ public class BuildCode {
        FlatNode nextnode;
        if (state.MLP && current_node.kind()==FKind.FlatSESEEnterNode) {
          FlatSESEEnterNode fsen = (FlatSESEEnterNode)current_node;
-         if( nonSESEpass ) {
-           setSESEtoGen.add(fsen);
-           fsen.setEnclosingFlatMeth(fm);
-         }
          nextnode=fsen.getFlatExit().getNext(0);
        } else {
          output.print("   ");
@@ -1635,6 +1754,7 @@ public class BuildCode {
     MethodDescriptor md=fm.getMethod();
     TaskDescriptor task=fm.getTask();
     TempObject objecttemps=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task);
+
     if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) {
       //System.out.println("generateTemp returns " + td.getSafeSymbol());
       return td.getSafeSymbol();
@@ -1647,6 +1767,7 @@ public class BuildCode {
     if (objecttemps.isParamPtr(td)) {
       return paramsprefix+"->"+td.getSafeSymbol();
     }
+
     throw new Error();
   }
 
index 11da4cb8c10e4246334edaf563c64b52807840a6..4d8968d4805d14e813a48bf20393b45a51b94a6e 100644 (file)
@@ -64,6 +64,49 @@ public class FlatSESEEnterNode extends FlatNode {
     return inVars;
   }
 
+  Vector<TempDescriptor> vecinVars;
+  void buildvarVec() {
+    HashSet<TempDescriptor> paramset=new HashSet<TempDescriptor>();
+    paramset.addAll(inVars);
+    paramset.addAll(outVars);
+    vecinVars=new Vector<TempDescriptor>();
+    vecinVars.addAll(paramset);
+  }
+
+  public TempDescriptor getParameter(int i) {
+    if (vecinVars==null) {
+      buildvarVec();
+    }
+    return vecinVars.get(i);
+  }
+
+  public int numParameters() {
+    if (vecinVars==null) {
+      buildvarVec();
+    }
+    return vecinVars.size();
+  }
+
+  public Set<FlatNode> getNodeSet() {
+    HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
+    HashSet<FlatNode> visited=new HashSet<FlatNode>();
+    tovisit.add(this);
+    while(!tovisit.isEmpty()) {
+      FlatNode fn=tovisit.iterator().next();
+      tovisit.remove(fn);
+      visited.add(fn);
+      
+      if (fn!=exit) {
+       for(int i=0; i<fn.numNext(); i++) {
+         FlatNode nn=fn.getNext(i);
+         if (!visited.contains(nn))
+           tovisit.add(nn);
+       }
+      }
+    }
+    return visited;
+  }
+
   public Set<TempDescriptor> getOutVarSet() {
     return outVars;
   }
index ec1023377cc4c7058d8c5aa5e52621c269ec9c5a..45625edf109f0fe4a71ed9872e26c483aa306d58 100644 (file)
@@ -248,6 +248,7 @@ public class Main {
     bf.buildFlat();
     SafetyAnalysis sa=null;
     PrefetchAnalysis pa=null;
+    MLPAnalysis mlpa=null;
 
     if (state.OPTIMIZE) {
       CallGraph callgraph=new CallGraph(state);
@@ -303,10 +304,10 @@ public class Main {
                                                    state.OWNERSHIPWRITEDOTS,
                                                    state.OWNERSHIPWRITEALL,
                                                    state.OWNERSHIPALIASFILE);
-      MLPAnalysis mlpa = new MLPAnalysis(state,
-                                        tu,
-                                        callGraph,
-                                        oa);
+      mlpa = new MLPAnalysis(state,
+                             tu,
+                             callGraph,
+                             oa);
     }    
 
     if (state.TAGSTATE) {
@@ -394,10 +395,10 @@ public class Main {
        }
        LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
        GenerateConversions gc=new GenerateConversions(la, state);
-       BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa);
+       BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa, mlpa);
        bc.buildCode();
       } else {
-       BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa);
+       BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa, mlpa);
        bc.buildCode();
       }
     }
index ad9d6ba85db30efb3ab2e04fd5f6b65134885f04..897d72e802e23cff075522209ee3d8d577e3492c 100644 (file)
@@ -3,8 +3,7 @@ PROGRAM=test
 SOURCE_FILES=$(PROGRAM).java
 
 BUILDSCRIPT=~/research/Robust/src/buildscript
-BSFLAGS= -mlpdebug -justanalyze -mainclass Test -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions -flatirusermethods -ownaliasfile aliases.txt #-justanalyze -recover 
-#BSFLAGS= -mainclass Test -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions -flatirusermethods -ownaliasfile aliases.txt #-justanalyze -recover 
+BSFLAGS= -mlpdebug  -mainclass Test -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions -flatirusermethods -ownaliasfile aliases.txt
 
 
 all: $(PROGRAM).bin
index 2c38702c8cfac24f0e92b57a3f69d8eeb9d77874..c55d0b186b4c304538da18d3a482b12aeb971469 100644 (file)
@@ -40,5 +40,12 @@ public class Test {
     y = y + 1;
     x = x + 1;
     z = z + 1;
+
+    //Integer i;
+    //afunc( i );
+  }
+
+  public static void afunc( Integer i ) {
+    i = null;
   }
 }