first version of inliner
authorbdemsky <bdemsky>
Fri, 26 Jun 2009 00:29:08 +0000 (00:29 +0000)
committerbdemsky <bdemsky>
Fri, 26 Jun 2009 00:29:08 +0000 (00:29 +0000)
Robust/src/IR/Flat/Inliner.java
Robust/src/Main/Main.java
Robust/src/buildscript

index 88bbe41e7c7aca5a5332f5bd53e3e31e03be8039..77e37c7251b51067a54bb58967293f45278676bf 100644 (file)
@@ -1,6 +1,8 @@
 package IR.Flat;
 import java.util.Hashtable;
 import java.util.Set;
+import java.util.HashSet;
+import java.util.Stack;
 import java.util.Iterator;
 import IR.ClassDescriptor;
 import IR.Operation;
@@ -9,6 +11,59 @@ import IR.TypeUtil;
 import IR.MethodDescriptor;
 
 public class Inliner {
+  public static void inlineAtomic(State state, TypeUtil typeutil, FlatMethod fm, int depth) {
+    Stack<FlatNode> toprocess=new Stack<FlatNode>();
+    HashSet<FlatNode> visited=new HashSet<FlatNode>();
+    Hashtable<FlatNode, Integer> atomictable=new Hashtable<FlatNode, Integer>();
+    HashSet<FlatNode> atomicset=new HashSet<FlatNode>();
+
+    toprocess.push(fm);
+    visited.add(fm);
+    atomictable.put(fm, new Integer(0));
+    while(!toprocess.isEmpty()) {
+      FlatNode fn=toprocess.pop();
+      int atomicval=atomictable.get(fn).intValue();
+      if (fn.kind()==FKind.FlatAtomicEnterNode)
+       atomicval++;
+      else if(fn.kind()==FKind.FlatAtomicExitNode)
+       atomicval--;
+      for(int i=0;i<fn.numNext();i++) {
+       FlatNode fnext=fn.getNext(i);
+       if (!visited.contains(fnext)) {
+         atomictable.put(fnext, new Integer(atomicval));
+         if (atomicval>0)
+           atomicset.add(fnext);
+         visited.add(fnext);
+         toprocess.push(fnext);
+       }
+      }
+    }
+    //make depth 0 be depth infinity
+    if (depth==0)
+      depth=10000000;
+    recursive(state, typeutil, atomicset, depth, new Stack<MethodDescriptor>());
+  }
+  
+
+  public static void recursive(State state, TypeUtil typeutil, Set<FlatNode> fnset, int depth, Stack<MethodDescriptor> toexclude) {
+    for(Iterator<FlatNode> fnit=fnset.iterator();fnit.hasNext();) {
+      FlatNode fn=fnit.next();
+      if (fn.kind()==FKind.FlatCall) {
+       FlatCall fc=(FlatCall)fn;
+       MethodDescriptor md=fc.getMethod();
+
+       if (toexclude.contains(md))
+         continue;
+
+       Set<FlatNode> inlinefnset=inline(fc, typeutil, state);
+       toexclude.push(md);
+       if (depth>1)
+         recursive(state, typeutil, inlinefnset, depth-1, toexclude);
+       toexclude.pop();
+      }
+    }
+  }
+
   public static Set<FlatNode> inline(FlatCall fc, TypeUtil typeutil, State state) {
     MethodDescriptor md=fc.getMethod();
     /* Do we need to do virtual dispatch? */
index dba20e3860dce3458a2bc91088a7db646d034b3d..db6f700e3c8925e4736c839e564bca652e134167 100644 (file)
@@ -17,6 +17,7 @@ import IR.Tree.SemanticCheck;
 import IR.Flat.BuildCodeMultiCore;
 import IR.Flat.BuildFlat;
 import IR.Flat.BuildCode;
+import IR.Flat.Inliner;
 import IR.ClassDescriptor;
 import IR.State;
 import IR.TaskDescriptor;
@@ -80,7 +81,10 @@ public class Main {
        state.excprefetch.add(args[++i]);
       else if (option.equals("-classlibrary"))
        state.classpath.add(args[++i]);
-      else if(option.equals("-numcore")) {
+      else if (option.equals("-inlineatomic")) {
+       state.INLINEATOMIC=true;
+       state.inlineatomicdepth=Integer.parseInt(args[++i]);
+      } else if(option.equals("-numcore")) {
        ++i;
        state.CORENUM = Integer.parseInt(args[i]);
       } else if (option.equals("-mainclass"))
@@ -251,6 +255,20 @@ public class Main {
     SafetyAnalysis sa=null;
     PrefetchAnalysis pa=null;
     MLPAnalysis mlpa=null;
+    if (state.INLINEATOMIC) {
+      Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
+      while(classit.hasNext()) {
+        ClassDescriptor cn=(ClassDescriptor)classit.next();
+        Iterator methodit=cn.getMethods();
+        while(methodit.hasNext()) {
+         // do inlining
+          MethodDescriptor md=(MethodDescriptor)methodit.next();
+          FlatMethod fm=state.getMethodFlat(md);
+         Inliner.inlineAtomic(state, tu, fm, state.inlineatomicdepth);
+       }
+      }
+    }
+
 
     if (state.OPTIMIZE) {
       CallGraph callgraph=new CallGraph(state);
index 03d32594b81949b0ef15a8116f76a909b6134fd2..b071eca29e4a299eb42901d794e2945beee93403 100755 (executable)
@@ -46,6 +46,7 @@ echo -transstats generates transaction stats on commits and aborts
 echo -garbagestats Print garbage collection statistics
 echo -webinterface enable web interface
 echo -runtimedebug printout runtime debug messages
+echo -inlineatomic depth inline methods inside of transactions to specified depth
 echo "-thread use support for multiple threads"
 echo "-optimize call gcc with -O9 (optimize)"
 echo "-nooptimize call gcc with -O0 (do not optimize)"
@@ -184,6 +185,10 @@ elif [[ $1 = '-trueprob' ]]
 then
 JAVAOPTS="$JAVAOPTS -trueprob $2"
 shift
+elif [[ $1 = '-inlineatomic' ]]
+then
+JAVAOPTS="$JAVAOPTS -inlineatomic $2"
+shift
 elif [[ $1 = '-mac' ]]
 then
 EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"